如何将列的值与Spark上单独dataFrame上列的所有行进行比较

问题描述 投票:-2回答:1

我有这两个数据框。

enter image description hereenter image description here

我的目标是将第一个数据帧上的“ FilteredDescription”列的每个值与第二个数据帧上的“ Name”列的所有值进行比较。

apache-spark bigdata text-processing
1个回答
0
投票

由于您没有提到逻辑的完整流程,我只是在下面添加逻辑以匹配两个表中的一列。

//load data for first dataframe.
val dfa = dfaData.withColumn("id",monotonically_increasing_id).withColumn("id",row_number().over(Window.partitionBy($"id").orderBy($"id".asc)))
//load data for second dataframe.
val dfb = dfbData.withColumn("id",monotonically_increasing_id).withColumn("id",row_number().over(Window.partitionBy($"id").orderBy($"id".asc)))

//Used cross join to match dfa columns to dfb columns.
dfa.crossJoin(dfb).withColumn("matched",when($"saltedgecategory" === $"name", lit("matched")).otherwise("not matched")).show(false)

© www.soinside.com 2019 - 2024. All rights reserved.