【发布时间】:2023-01-14 18:05:47
【问题描述】:
我有一个数据框,从中创建一个临时视图以运行 sql 查询。经过几次 sql 查询后,我想将 sql 查询的输出转换为新的 Dataframe。我想要数据返回 Dataframe 的原因是我可以将它保存到 blob 存储中。
所以,问题是:将 sql 查询输出转换为 Dataframe 的正确方法是什么?
这是我到目前为止的代码:
%scala
//read data from Azure blob
...
var df = spark.read.parquet(some_path)
// create temp view
df.createOrReplaceTempView("data_sample")
%sql
//have some sqlqueries, the one below is just an example
SELECT
date,
count(*) as cnt
FROM
data_sample
GROUP BY
date
//Now I want to have a dataframe that has the above sql output. How to do that?
Preferably the code would be in python or scala.
【问题讨论】:
标签: pyspark databricks azure-databricks