Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ trait CheckAnalysis extends PredicateHelper {
def ordinalNumber(i: Int): String = i match {
case 0 => "first"
case 1 => "second"
case i => s"${i}th"
case 2 => "third"
case i => s"${i + 1}th"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehehe, nice catch ;)

}
val ref = dataTypes(operator.children.head)
operator.children.tail.zipWithIndex.foreach { case (child, ti) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,4 +831,57 @@ class AnalysisSuite extends AnalysisTest with Matchers {
}
}
}

test("SPARK-32131: Fix wrong column index when we have more than two columns" +
" during union and set operations" ) {
val firstTable = LocalRelation(
AttributeReference("a", StringType)(),
AttributeReference("b", DoubleType)(),
AttributeReference("c", IntegerType)(),
AttributeReference("d", FloatType)())

val secondTable = LocalRelation(
AttributeReference("a", StringType)(),
AttributeReference("b", TimestampType)(),
AttributeReference("c", IntegerType)(),
AttributeReference("d", FloatType)())

val thirdTable = LocalRelation(
AttributeReference("a", StringType)(),
AttributeReference("b", DoubleType)(),
AttributeReference("c", TimestampType)(),
AttributeReference("d", FloatType)())

val fourthTable = LocalRelation(
AttributeReference("a", StringType)(),
AttributeReference("b", DoubleType)(),
AttributeReference("c", IntegerType)(),
AttributeReference("d", TimestampType)())

val r1 = Union(firstTable, secondTable)
val r2 = Union(firstTable, thirdTable)
val r3 = Union(firstTable, fourthTable)
val r4 = Except(firstTable, secondTable, isAll = false)
val r5 = Intersect(firstTable, secondTable, isAll = false)

assertAnalysisError(r1,
Seq("Union can only be performed on tables with the compatible column types. " +
"timestamp <> double at the second column of the second table"))

assertAnalysisError(r2,
Seq("Union can only be performed on tables with the compatible column types. " +
"timestamp <> int at the third column of the second table"))

assertAnalysisError(r3,
Seq("Union can only be performed on tables with the compatible column types. " +
"timestamp <> float at the 4th column of the second table"))

assertAnalysisError(r4,
Seq("Except can only be performed on tables with the compatible column types. " +
"timestamp <> double at the second column of the second table"))

assertAnalysisError(r5,
Seq("Intersect can only be performed on tables with the compatible column types. " +
"timestamp <> double at the second column of the second table"))
}
}