kunishou's picture
Upload 284 files
2eae90c verified
raw
history blame contribute delete
No virus
1.26 kB
from spark_queries import utils
Q_NUM = 9
def q():
query_str = f"""
select
nation,
o_year,
round(sum(amount), 2) as sum_profit
from
(
select
n_name as nation,
year(o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from
part,
supplier,
lineitem,
partsupp,
orders,
nation
where
s_suppkey = l_suppkey
and ps_suppkey = l_suppkey
and ps_partkey = l_partkey
and p_partkey = l_partkey
and o_orderkey = l_orderkey
and s_nationkey = n_nationkey
and p_name like '%green%'
) as profit
group by
nation,
o_year
order by
nation,
o_year desc
"""
utils.get_part_ds()
utils.get_supplier_ds()
utils.get_line_item_ds()
utils.get_part_supp_ds()
utils.get_orders_ds()
utils.get_nation_ds()
q_final = utils.get_or_create_spark().sql(query_str)
utils.run_query(Q_NUM, q_final)
if __name__ == "__main__":
q()