Tôi có đoạn mã sau:Là dataframe.show() một hành động trong tia lửa?
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()
Ứng dụng này được hoạt động bình thường và nhanh chóng cho đến khi show()
nhưng trong bước count()
, nó tạo ra 40000 nhiệm vụ.
Hiểu biết của tôi là df1.show()
phải kích hoạt việc tạo đầy đủ df1
và df1.count()
sẽ rất nhanh. Tôi đang thiếu gì ở đây? tại sao là count()
chậm?
Cảm ơn bạn rất nhiều trước, Roxana
Có, thực sự ... orderBy mất nhiều thời gian. – Roxana
'coalesce' có lẽ tốt hơn' repartition' vì nó tránh được sự lộn xộn. – LiMuBei
Lưu ý cho tương lai :) –