zhengruifeng commented on code in PR #40008:
URL: https://github.com/apache/spark/pull/40008#discussion_r1106628436
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -1237,37 +1236,37 @@ class SparkConnectPlanner(val session: SparkSession) {
}
private def transformSetOperation(u: proto.SetOperation): LogicalPlan = {
- assert(u.hasLeftInput && u.hasRightInput, "Union must have 2 inputs")
+ if (!u.hasLeftInput || !u.hasRightInput) {
+ throw InvalidPlanInput("Set operation must have 2 inputs")
+ }
+ val leftPlan = transformRelation(u.getLeftInput)
+ val rightPlan = transformRelation(u.getRightInput)
+ val isAll = if (u.hasIsAll) u.getIsAll else false
u.getSetOpType match {
case proto.SetOperation.SetOpType.SET_OP_TYPE_EXCEPT =>
if (u.getByName) {
throw InvalidPlanInput("Except does not support union_by_name")
}
- Except(transformRelation(u.getLeftInput),
transformRelation(u.getRightInput), u.getIsAll)
+ Except(leftPlan, rightPlan, isAll)
case proto.SetOperation.SetOpType.SET_OP_TYPE_INTERSECT =>
if (u.getByName) {
throw InvalidPlanInput("Intersect does not support union_by_name")
}
- Intersect(
- transformRelation(u.getLeftInput),
- transformRelation(u.getRightInput),
- u.getIsAll)
+ Intersect(leftPlan, rightPlan, isAll)
case proto.SetOperation.SetOpType.SET_OP_TYPE_UNION =>
if (!u.getByName && u.getAllowMissingColumns) {
throw InvalidPlanInput(
"UnionByName `allowMissingCol` can be true only if `byName` is
true.")
}
- val combinedUnion = CombineUnions(
- Union(
- Seq(transformRelation(u.getLeftInput),
transformRelation(u.getRightInput)),
- byName = u.getByName,
- allowMissingCol = u.getAllowMissingColumns))
- if (u.getIsAll) {
- combinedUnion
+ val union = Union(Seq(leftPlan, rightPlan), u.getByName,
u.getAllowMissingColumns)
+ if (isAll) {
+ union
} else {
- logical.Deduplicate(combinedUnion.output, combinedUnion)
+ val analyzed = new QueryExecution(session, union).analyzed
+ Deduplicate(analyzed.output, analyzed)
Review Comment:
https://github.com/apache/spark/pull/40029
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]