Skip to content
Snippets Groups Projects
Commit 652c4703 authored by Davies Liu's avatar Davies Liu Committed by Davies Liu
Browse files

[SPARK-14528] [SQL] Fix same result of Union

## What changes were proposed in this pull request?

This PR fix resultResult() for Union.

## How was this patch tested?

Added regression test.

Author: Davies Liu <davies@databricks.com>

Closes #12295 from davies/fix_sameResult.
parent efaf7d18
No related branches found
No related tags found
No related merge requests found
...@@ -312,18 +312,17 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanT ...@@ -312,18 +312,17 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanT
/** Args that have cleaned such that differences in expression id should not affect equality */ /** Args that have cleaned such that differences in expression id should not affect equality */
protected lazy val cleanArgs: Seq[Any] = { protected lazy val cleanArgs: Seq[Any] = {
def cleanArg(arg: Any): Any = arg match { def cleanArg(arg: Any): Any = arg match {
// Children are checked using sameResult above.
case tn: TreeNode[_] if containsChild(tn) => null
case e: Expression => cleanExpression(e).canonicalized case e: Expression => cleanExpression(e).canonicalized
case other => other case other => other
} }
productIterator.map { productIterator.map {
// Children are checked using sameResult above.
case tn: TreeNode[_] if containsChild(tn) => null
case e: Expression => cleanArg(e)
case s: Option[_] => s.map(cleanArg) case s: Option[_] => s.map(cleanArg)
case s: Seq[_] => s.map(cleanArg) case s: Seq[_] => s.map(cleanArg)
case m: Map[_, _] => m.mapValues(cleanArg) case m: Map[_, _] => m.mapValues(cleanArg)
case other => other case other => cleanArg(other)
}.toSeq }.toSeq
} }
} }
...@@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.plans ...@@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.plans
import org.apache.spark.SparkFunSuite import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.dsl.expressions._ import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._ import org.apache.spark.sql.catalyst.dsl.plans._
import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan} import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan, Union}
import org.apache.spark.sql.catalyst.util._ import org.apache.spark.sql.catalyst.util._
/** /**
...@@ -61,4 +61,9 @@ class SameResultSuite extends SparkFunSuite { ...@@ -61,4 +61,9 @@ class SameResultSuite extends SparkFunSuite {
test("sorts") { test("sorts") {
assertSameResult(testRelation.orderBy('a.asc), testRelation2.orderBy('a.asc)) assertSameResult(testRelation.orderBy('a.asc), testRelation2.orderBy('a.asc))
} }
test("union") {
assertSameResult(Union(Seq(testRelation, testRelation2)),
Union(Seq(testRelation2, testRelation)))
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment