【发布时间】:2021-10-06 18:28:46
【问题描述】:
我有以下代码:
val df_in = sqlcontext.read.json(jsonFile) // the file resides in hdfs
//some operations in here to create df as df_in with two more columns "terms1" and "terms2"
val intersectUDF = udf( (seq1:Seq[String], seq2:Seq[String] ) => { seq1 intersect seq2 } ) //intersects two sequences
val symmDiffUDF = udf( (seq1:Seq[String], seq2:Seq[String] ) => { (seq1 diff seq2) ++ (seq2 diff seq1) } ) //compute the difference of two sequences
val df1 = (df.withColumn("termsInt", intersectUDF(df("terms1"), df1("terms2") ) )
.withColumn("termsDiff", symmDiffUDF(df("terms1"), df1("terms2") ) )
.where( size(col("termsInt")) >0 && size(col("termsDiff")) > 0 && size(col("termsDiff")) <= 2 )
.cache()
) // add the intersection and difference columns and filter the resulting DF
df1.show()
df1.count()
在show() 之前,该应用程序运行正常且快速,但在count() 步骤中,它会创建40000 个任务。
我的理解是df1.show() 应该触发完整的df1 创建,df1.count() 应该非常快。我在这里想念什么?为什么count() 这么慢?
非常感谢您, 罗克珊娜
【问题讨论】:
标签: apache-spark