[英]Issue with dropDuplicates() and except() method in Spark using Scala
我有一個表colum xcept(filteredDuplicates)
當我在Spark shell中運行它時,它正如預期的那樣完美地工作。 但是在spark提交中,重復刪除不是按排序順序(即)seq_no 3在有效幀中,1,5在拒絕幀中。 另外,除了()在spark提交中也有問題。 我被困了一整天,請有人幫助提前感謝大家
以下方法使用spark-sql提供的row_number函數生成有效和無效的數據幀。 我沒有訪問cassandra所以我在這里使用一個簡單的Dataframe。
import sqlContext.implicits._
val df = sc.parallelize(Seq(("a" -> 1), ("b" -> 2), ("c" -> 3), ("d" -> 4), ("a" -> 5), ("a" -> 6), ("c" -> 7), ("c" -> 8))).toDF("c1", "c2")
df.registerTempTable("temp_table")
val masterdf = sqlContext.sql("SELECT c1, c2, ROW_NUMBER() OVER(PARTITION BY c1 ORDER BY c2) as row_num FROM temp_table")
masterdf.filter("row_num = 1").show()
+---+---+-------+
| c1| c2|row_num|
+---+---+-------+
| a| 1| 1|
| b| 2| 1|
| c| 3| 1|
| d| 4| 1|
+---+---+-------+
masterdf.filter("row_num > 1").show()
+---+---+-------+
| c1| c2|row_num|
+---+---+-------+
| a| 5| 2|
| a| 6| 3|
| c| 7| 2|
| c| 8| 3|
+---+---+-------+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.