gpt4 book ai didi

java - Spark数据集连接错误: Join condition is missing or trivial

转载 作者:行者123 更新时间:2023-12-02 10:44:52 33 4
gpt4 key购买 nike

我想在 Spark 中加入两个数据集。这就是我所做的:

Dataset<Row> data = spark.read().format("parquet").load("hdfs://path");
Dataset<Person> p1= data.filter("id < 200").as(Encoders.bean(Person.class)).alias("ds1");
Dataset<Person> p2= data.filter("id < 100").as(Encoders.bean(Person.class)).alias("ds2");
p1.joinWith(p2, p1.col("ds1.id").equalTo(p2.col("ds2.id")) ,"inner").show();

当我运行该程序时,我收到此错误:

Detected implicit cartesian product for INNER join between logical plans
Project [named_struct(id, id#3L, fname, fname#1, lname, lname#4, email, email#0, gender, gender#2) AS _1#41]
+- Filter (named_struct(id, id#3L, fname, fname#1, lname, lname#4, email, email#0, gender, gender#2).id = named_struct(id, id#3L, fname, fname#1, lname, lname#4, email, email#0, gender, gender#2).id)
+- Relation[email#0,fname#1,gender#2,id#3L,lname#4] parquet
and
Project [named_struct(id, id#39L, fname, fname#37, lname, lname#40, email, email#36, gender, gender#38) AS _2#42]
+- Relation[email#36,fname#37,gender#38,id#39L,lname#40] parquet
Join condition is missing or trivial.
Either: use the CROSS JOIN syntax to allow cartesian products between these
relations, or: enable implicit cartesian products by setting the configuration
variable spark.sql.crossJoin.enabled=true;

我从错误中了解到并查看源代码是:它认为 this is a cross join (第 1311-1328 行)但事实并非如此。

我看到了this solution另外,这是因为结构共享相同的谱系,我们应该使用别名,我使用了它,但它不起作用。我该如何解决这个问题?

还有一个与此问题相关的错误报告:spark-25150

最佳答案

如果“col”附近没有数据集前缀(“p1.”、“p2.”),则必须工作:

import static org.apache.spark.sql.functions.col;
p1.joinWith(p2, col("ds1.id").equalTo(col("ds2.id")) ,"inner").show();

关于java - Spark数据集连接错误: Join condition is missing or trivial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52659316/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com