Spark SQL选择在至少5个不同日期发推文的人

问题描述 投票:-1回答:1

第一次使用Spark SQL。我有一个带有以下列的DF:“ tweet_date”,“ user_screen_name”,“ user_id_str”。我的目标是选择在5个不同日期(tweet_date)发布的所有user_id_str和user_screen_names。

我的代码当前看起来像这样,但我认为这是错误的。

task12=spark.sql("SELECT DISTINCT user_id_str, user_screen_name FROM  tweet2 WHERE (user_id_str)>=5")

更换时

WHERE (user_id_str)>=5
#to
WHERE (tweet_date)>=5

我的输出df为空白

非常感谢您的帮助

apache-spark apache-spark-sql pyspark-sql
1个回答
0
投票

您可以在user_screen_names..etc列上group bycount(distinct(tweet_date))上获取tweet_dates的计数。

  • 使用having子句过滤结果。

Sample Query:

#this query results names where tweet_date count is atleast 5
spark.sql("select user_screen_name,count(distinct(tweet_date)) cnt from dd group by user_screen_name having cnt >= 5").show()
© www.soinside.com 2019 - 2024. All rights reserved.