Skip to content

Instantly share code, notes, and snippets.

View RaMSFT's full-sized avatar

RaMS Nelluri RaMSFT

View GitHub Profile
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
"""
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
"""
#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()
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)
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)")
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)")
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:
@RaMSFT
RaMSFT / w01-c01-positive-negative.py
Created January 22, 2022 17:29
From a given list of Integers, calculate the percentage (up to 4 decimals) of elements that are positive, negative and zeros
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)]
import http
import json
def call_publicapi(table_name):
"""
purpose:
This function does bla bla bla.
params: reads 3 global parameters
status, execution_log: for sttaus and loogging
database name: for creating database
response:
#Creating an empty DF (This is kind of an Hack...)
tbl_df = spark.sql("show tables in user_data like 'xxx'")
#Loop through all databases
for db in spark.sql("show databases like '*data'").collect():
#create a dataframe with list of tables from the database
df = spark.sql(f"show tables in {db.databaseName}")
#union the tables list dataframe with main dataframe
tbl_df = tbl_df.union(df)
#After the loop, show the results