Skip to content

Commit 52d19d3

Browse files
committed
Address comments.
1 parent 67a037c commit 52d19d3

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.spark.sql.catalyst.analysis
1919

20-
import java.util.Locale
2120
import javax.annotation.Nullable
2221

2322
import scala.annotation.tailrec
@@ -105,11 +104,10 @@ object TypeCoercion {
105104
Some(StructType(fields1.zip(fields2).map { case (f1, f2) =>
106105
// Since `t1.sameType(t2)` is true, two StructTypes have the same DataType
107106
// except `name` (in case of `spark.sql.caseSensitive=false`) and `nullable`.
108-
// - Different names: use a lower case name because findTightestCommonType is commutative.
107+
// - Different names: use f1.name
109108
// - Different nullabilities: `nullable` is true iff one of them is nullable.
110-
val name = if (f1.name == f2.name) f1.name else f1.name.toLowerCase(Locale.ROOT)
111109
val dataType = findTightestCommonType(f1.dataType, f2.dataType).get
112-
StructField(name, dataType, nullable = f1.nullable || f2.nullable)
110+
StructField(f1.name, dataType, nullable = f1.nullable || f2.nullable)
113111
}))
114112

115113
case _ => None

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,17 @@ class TypeCoercionSuite extends AnalysisTest {
131131
widenFunc: (DataType, DataType) => Option[DataType],
132132
t1: DataType,
133133
t2: DataType,
134-
expected: Option[DataType]): Unit = {
134+
expected: Option[DataType],
135+
isSymmetric: Boolean = true): Unit = {
135136
var found = widenFunc(t1, t2)
136137
assert(found == expected,
137138
s"Expected $expected as wider common type for $t1 and $t2, found $found")
138139
// Test both directions to make sure the widening is symmetric.
139-
found = widenFunc(t2, t1)
140-
assert(found == expected,
141-
s"Expected $expected as wider common type for $t2 and $t1, found $found")
140+
if (isSymmetric) {
141+
found = widenFunc(t2, t1)
142+
assert(found == expected,
143+
s"Expected $expected as wider common type for $t2 and $t1, found $found")
144+
}
142145
}
143146

144147
test("implicit type cast - ByteType") {
@@ -419,10 +422,12 @@ class TypeCoercionSuite extends AnalysisTest {
419422
None)
420423
}
421424
withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
422-
widenTest(
425+
checkWidenType(
426+
TypeCoercion.findTightestCommonType,
423427
StructType(Seq(StructField("a", IntegerType), StructField("B", IntegerType))),
424428
StructType(Seq(StructField("A", IntegerType), StructField("b", IntegerType))),
425-
Some(StructType(Seq(StructField("a", IntegerType), StructField("b", IntegerType)))))
429+
Some(StructType(Seq(StructField("a", IntegerType), StructField("B", IntegerType)))),
430+
isSymmetric = false)
426431
}
427432
}
428433

0 commit comments

Comments
 (0)