火花查询卡桑德拉中的集合联合
Union of sets in spark querying cassandra
cassandra中的table结构:
identifier, date, set(integer)
我想使用 Spark 实现的是按标识符和日期对行进行分组,然后聚合所有集合值。我会通过一个例子更清楚:
原始数据:(考虑代表整数的字母)
id1, 05-05-2017, {a,b,c}
id1, 05-05-2017, {c,d}
id1, 26-05-2017, {a,b,c}
id1, 26-05-2017, {b,c}
id2, 26-05-2017, {a,b,c}
id2, 26-05-2017, {b,c,d}
输出:
id1, 05-05-2017, {a,b,c,d}
id1, 26-05-2017, {a,b,c}
id2, 26-05-2017, {a,b,c,d}
由于这是一个集合,我希望聚合结果中的值是唯一的。我正在使用 java 和数据集。
如果你的数据框有你提到的列,你可以这样做:
df.withColumn("set", explode(col("set"))).groupBy("identifier", "date").agg(collect_set("set"))
cassandra中的table结构:
identifier, date, set(integer)
我想使用 Spark 实现的是按标识符和日期对行进行分组,然后聚合所有集合值。我会通过一个例子更清楚:
原始数据:(考虑代表整数的字母)
id1, 05-05-2017, {a,b,c}
id1, 05-05-2017, {c,d}
id1, 26-05-2017, {a,b,c}
id1, 26-05-2017, {b,c}
id2, 26-05-2017, {a,b,c}
id2, 26-05-2017, {b,c,d}
输出:
id1, 05-05-2017, {a,b,c,d}
id1, 26-05-2017, {a,b,c}
id2, 26-05-2017, {a,b,c,d}
由于这是一个集合,我希望聚合结果中的值是唯一的。我正在使用 java 和数据集。
如果你的数据框有你提到的列,你可以这样做:
df.withColumn("set", explode(col("set"))).groupBy("identifier", "date").agg(collect_set("set"))