如何分配从sql得到的特定结果可以在spark/python中设置为变量

xjreopfe  于 2021-05-29  发布在  Spark
关注(0)|答案(1)|浏览(395)

假设我从 SQL 我传的剧本 Spark.SQL ```
results = spark.sql("SELECT EndDate FROM countDirectorySize WHERE Path IN (SELECT Path FROM countDirectorySize WHERE EndDate = (SELECT MAX(EndDate) FROM countDirectorySize)) ORDER BY EndDate DESC LIMIT 1")
print(results.show())

o/p-

+----------+
| EndDate|
+----------+
|2020-06-08|
+----------+

我想把 `2020-06-08` 并将其传递给python脚本。
jjjwad0x

jjjwad0x1#

其他方法也可以

OPTION 1: end_date = results.take(1)[0][0]

 OPTION 2: end_date = results.first()[0]

相关问题