Home > Mobile >  Create Tempview from sql query
Create Tempview from sql query

Time:10-22

df_sales = spark.sql(
"SELECT \
s.TRANS_DT, \
s.STORE_KEY, \
s.PROD_KEY, \
s.SALES_QTY
FROM sales s \
JOIN inventory i ON s.cal_dt=i.cal_dt and s.store_key=i.store_key and s.prod_key=i.prod_key;"
)

I created sql query from 2 tempview (inventory and sales). How to convert df_sales sql query to tempview again and I can create a new SQL query.

CodePudding user response:

Read this and you can write your own code as follows:

spark.sql(
"""
SELECT
    s.TRANS_DT,
    s.STORE_KEY,
    s.PROD_KEY,
    s.SALES_QTY
FROM sales s
JOIN inventory i ON s.cal_dt=i.cal_dt and s.store_key=i.store_key and s.prod_key=i.prod_key;
"""
).createOrReplaceTempView("tmpViewName")
  • Related