0
有可能使用updateStateByKey()
函数与元组作为值吗?我使用PySpark,我的输入是(word, (count, tweet_id))
,这意味着word
是一个关键字,而一个元组(count, tweet_id)
是一个值。 updateStateByKey
的任务是为每个单词总结他们的计数并创建包含该单词的所有tweet_id的列表。Spark Streaming updateStateByKey与元组作为值
我实现了以下更新功能,但我得到了错误列表索引超出范围new_values
索引1:
def updateFunc(new_values, last_sum):
count = 0
tweets_id = []
if last_sum:
count = last_sum[0]
tweets_id = last_sum[1]
return sum(new_values[0]) + count, tweets_id.extend(new_values[1])
并调用方法:
running_counts.updateStateByKey(updateFunc)
可以分享pyspark代码,我可以自己试试这样一个例子。想知道为什么-1被给出 – thebluephantom
我在这个项目中遇到了这个问题https://github.com/dmacjam/twitter-word-cloud/blob/master/processing/trending_words.py –
thx,会尝试并摆脱,如果减1 – thebluephantom