2017-02-10 55 views
3

我有一個數據幀加薪,我想增加對其他一些COLUMN1分組每一行new_col=max(some_column0)火花加入「檢測到笛卡爾乘積爲INNER JOIN」

maxs = df0.groupBy("catalog").agg(max("row_num").alias("max_num")).withColumnRenamed("catalog", "catalogid") 
df0.join(maxs, df0.catalog == maxs.catalogid).take(4) 

而在第二個字符串我得到一個錯誤:

AnalysisException: u'Detected cartesian product for INNER join between logical plans\nProject ... Use the CROSS JOIN syntax to allow cartesian products between these relations.;'

我不明白:爲什麼火花在這裏找到笛卡爾產品?

可能出現此錯誤的方法:我將DF保存到Hive表中,然後再次從表中選擇init DF。或者將這兩個字符串替換爲配置單元查詢 - 無論如何。但我不想保存DF。

回答

0

通過下面的建議,嘗試

df0.join(maxs, df0.catalog == maxs.catalogid, 'cross') 

基本上,第三個參數指定連接的類型。這解決了錯誤,但結果可能不是你想要的。

它解決了我的問題是應用別名。問題,如在這裏指定的,Why does spark think this is a cross/cartesian join,是你的轉換涉及的結構共享相同的血統。