Mam następujący kod:Czy funkcja imageframe.show() jest w iskrze?
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()
Aplikacja działa poprawnie i szybko do show()
ale w kroku count()
tworzy 40000 zadań.
Rozumiem, że df1.show()
powinien uruchamiać pełne tworzenie df1
, a df1.count()
powinno być bardzo szybkie. Czego tu mi brakuje? dlaczego powolne jest count()
?
Dziękuję bardzo z góry, Roxana
Tak, rzeczywiście ... order zajmuje dużo czasu. – Roxana
'coalesce' jest prawdopodobnie lepszy niż' partycja', ponieważ unika shuffle. – LiMuBei
Uwaga na przyszłość :) –