-
Notifications
You must be signed in to change notification settings - Fork 29k
[WIP][SPARK-41812][SPARK-41823][CONNECT][PYTHON] Fix ambiguous columns issue in Join #39734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1235,27 +1235,63 @@ class SparkConnectPlanner(val session: SparkSession) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private def splitConjunctivePredicates(condition: Expression): Seq[Expression] = { | ||||||
| condition match { | ||||||
| case UnresolvedFunction(Seq("and"), Seq(cond1, cond2), _, _, _) => | ||||||
| splitConjunctivePredicates(cond1) ++ splitConjunctivePredicates(cond2) | ||||||
| case other => other :: Nil | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private def transformJoin(rel: proto.Join): LogicalPlan = { | ||||||
| assert(rel.hasLeft && rel.hasRight, "Both join sides must be present") | ||||||
| if (rel.hasJoinCondition && rel.getUsingColumnsCount > 0) { | ||||||
| throw InvalidPlanInput( | ||||||
| s"Using columns or join conditions cannot be set at the same time in Join") | ||||||
| } | ||||||
| val joinCondition = | ||||||
| if (rel.hasJoinCondition) Some(transformExpression(rel.getJoinCondition)) else None | ||||||
|
|
||||||
| val catalystJointype = transformJoinType( | ||||||
| if (rel.getJoinType != null) rel.getJoinType else proto.Join.JoinType.JOIN_TYPE_INNER) | ||||||
| val joinType = if (rel.getUsingColumnsCount > 0) { | ||||||
| UsingJoin(catalystJointype, rel.getUsingColumnsList.asScala.toSeq) | ||||||
| } else { | ||||||
| catalystJointype | ||||||
| } | ||||||
| logical.Join( | ||||||
| left = transformRelation(rel.getLeft), | ||||||
| right = transformRelation(rel.getRight), | ||||||
| joinType = joinType, | ||||||
| condition = joinCondition, | ||||||
| hint = logical.JoinHint.NONE) | ||||||
|
|
||||||
| if (rel.hasJoinCondition) { | ||||||
| val leftDF = Dataset.ofRows(session, transformRelation(rel.getLeft)) | ||||||
| val rightDF = Dataset.ofRows(session, transformRelation(rel.getRight)) | ||||||
| val joinExprs = splitConjunctivePredicates(transformExpression(rel.getJoinCondition)) | ||||||
| .map { | ||||||
| case func @ UnresolvedFunction(Seq(f), Seq(l, r), _, _, _) | ||||||
| if Seq("==", "<=>").contains(f) => | ||||||
| val l2 = l match { | ||||||
| case UnresolvedAttribute(Seq(c)) => leftDF.apply(c).expr | ||||||
| case other => other | ||||||
| } | ||||||
| val r2 = r match { | ||||||
| case UnresolvedAttribute(Seq(c)) => rightDF.apply(c).expr | ||||||
| case other => other | ||||||
| } | ||||||
| func.copy(arguments = Seq(l2, r2)) | ||||||
|
|
||||||
| case other => other | ||||||
| } | ||||||
| .reduce(And) | ||||||
|
|
||||||
| leftDF | ||||||
|
||||||
| // A globally unique id of this Dataset. | |
| private val id = Dataset.curId.getAndIncrement() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,21 +260,21 @@ class SparkConnectPlannerSuite extends SparkFunSuite with SparkConnectPlanTest { | |
| .addArguments(unresolvedAttribute) | ||
| .build()) | ||
|
|
||
| val simpleJoin = proto.Relation.newBuilder | ||
| .setJoin( | ||
| proto.Join.newBuilder | ||
| .setLeft(readRel) | ||
| .setRight(readRel) | ||
| .setJoinType(proto.Join.JoinType.JOIN_TYPE_INNER) | ||
| .setJoinCondition(joinCondition) | ||
| .build()) | ||
| .build() | ||
|
|
||
| val res = transform(simpleJoin) | ||
| assert(res.nodeName == "Join") | ||
| assert(res != null) | ||
| val e0 = intercept[AnalysisException] { | ||
|
||
| val simpleJoin = proto.Relation.newBuilder | ||
| .setJoin( | ||
| proto.Join.newBuilder | ||
| .setLeft(readRel) | ||
| .setRight(readRel) | ||
| .setJoinType(proto.Join.JoinType.JOIN_TYPE_INNER) | ||
| .setJoinCondition(joinCondition) | ||
| .build()) | ||
| .build() | ||
| transform(simpleJoin) | ||
| } | ||
| assert(e0.getMessage.contains("TABLE_OR_VIEW_NOT_FOUND")) | ||
|
|
||
| val e = intercept[InvalidPlanInput] { | ||
| val e1 = intercept[InvalidPlanInput] { | ||
| val simpleJoin = proto.Relation.newBuilder | ||
| .setJoin( | ||
| proto.Join.newBuilder | ||
|
|
@@ -286,7 +286,7 @@ class SparkConnectPlannerSuite extends SparkFunSuite with SparkConnectPlanTest { | |
| transform(simpleJoin) | ||
| } | ||
| assert( | ||
| e.getMessage.contains( | ||
| e1.getMessage.contains( | ||
| "Using columns or join conditions cannot be set at the same time in Join")) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently, both
a == aanda <=> aare taken into account