This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def positive_negative(input_list): | |
| # Write your code here | |
| zeros = input_list.count(0) | |
| total = len(input_list) | |
| if zeros == 0: | |
| input_list.append(0) | |
| input_list.sort() | |
| neg_list = input_list[:input_list.index(0)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| table_list = ['customers','orders','adress','payments','shipment','sellers','products','tax','fraud','revenue'] | |
| def create_table_loop(table_name): | |
| spark.sql(f"create table loop_db.{table_name}(id int, name string)") | |
| loop_start_time = time.time() | |
| for table in table_list: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from multiprocessing.pool import ThreadPool | |
| table_list = ['customers','orders','adress','payments','shipment','sellers','products','tax','fraud','revenue'] | |
| print(table_list) | |
| def create_table_fanout(table_name): | |
| spark.sql(f"create table fanout_db.{table_name}(id int, name string)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from multiprocessing.pool import ThreadPool | |
| table_list = ['customers','orders','adress','payments','shipment','sellers','products','tax','fraud','revenue'] | |
| print(table_list) | |
| def create_table_loop(table_name): | |
| spark.sql(f"create table loop_db.{table_name}(id int, name string)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing.pool import ThreadPool | |
| import time | |
| ## Change the database name of your choice | |
| databse_name = 'your_database_name' | |
| #create a list of all tables to generate metrics | |
| table_list = spark.sql(f"show tables in {databse_name}").select('database','tablename').collect() | |
| print(table_list) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if you would like to know how tage works, un commete these | |
| # list(range(5)) #0, 1, 2, 3, 4 | |
| # list(range(2, 8)) #2, 3, 4, 5, 6, 7 | |
| # list(range(2, 8, 2)) #2, 4, 6 | |
| firstdf = spark.range(100) | |
| firstdf.count() | |
| firstdf.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def string_int(text): | |
| """_summary_ | |
| Args: | |
| text (string): a number enclosed in " or ' quotes as string | |
| Returns: | |
| integer: cast the string to number and return | |
| """ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_power(x, n): | |
| """calculate the power | |
| Args: | |
| x (integer): integr value | |
| n (integer): integer value | |
| Returns: | |
| _type_: power of x to the n | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_points(wins, draws, losses): | |
| """calculate points for a football match based on wins, losses, and draws | |
| Args: | |
| wins (integer): number of wins | |
| draws (integer): number of draws | |
| losses (integer): number of losses | |
| Returns: | |
| _type_: _description_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def is_same_num(num1, num2): | |
| """Check if given two numbers are equal | |
| Args: | |
| num1 (numeric): input numebr one | |
| num2 (numeric): input number two | |
| Returns: | |
| Boolean: Rteurn True when both numbers are same, else False | |
| """ |