Skip to content

Commit 7633fa9

Browse files
committed
revert
1 parent fe169b0 commit 7633fa9

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ object HiveTypeCoercion {
672672
// If the expression accepts the tightest common type, cast to that.
673673
val newLeft = if (left.dataType == commonType) left else Cast(left, commonType)
674674
val newRight = if (right.dataType == commonType) right else Cast(right, commonType)
675-
b.makeCopy(Array(newLeft, newRight))
675+
b.withNewChildren(Seq(newLeft, newRight))
676676
} else {
677677
// Otherwise, don't do anything with the expression.
678678
b
@@ -691,7 +691,7 @@ object HiveTypeCoercion {
691691
// general implicit casting.
692692
val children: Seq[Expression] = e.children.zip(e.inputTypes).map { case (in, expected) =>
693693
if (in.dataType == NullType && !expected.acceptsType(NullType)) {
694-
Cast(in, expected.defaultConcreteType)
694+
Literal.create(null, expected.defaultConcreteType)
695695
} else {
696696
in
697697
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ abstract class BinaryExpression extends Expression with trees.BinaryNode[Express
353353
* 2. Two inputs are expected to the be same type. If the two inputs have different types,
354354
* the analyzer will find the tightest common type and do the proper type casting.
355355
*/
356-
abstract class BinaryOperator extends BinaryExpression {
356+
abstract class BinaryOperator extends BinaryExpression with ExpectsInputTypes {
357357
self: Product =>
358358

359359
/**
@@ -366,6 +366,8 @@ abstract class BinaryOperator extends BinaryExpression {
366366

367367
override def toString: String = s"($left $symbol $right)"
368368

369+
override def inputTypes: Seq[AbstractDataType] = Seq(inputType, inputType)
370+
369371
override def checkInputDataTypes(): TypeCheckResult = {
370372
// First check whether left and right have the same type, then check if the type is acceptable.
371373
if (left.dataType != right.dataType) {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ class ExpressionTypeCheckingSuite extends SparkFunSuite {
5252
s"differing types in '${expr.prettyString}'")
5353
}
5454

55-
def assertErrorWithImplicitCast(expr: Expression, errorMessage: String): Unit = {
56-
val e = intercept[AnalysisException] {
57-
assertSuccess(expr)
58-
}
59-
assert(e.getMessage.contains(errorMessage))
60-
}
61-
6255
test("check types for unary arithmetic") {
6356
assertError(UnaryMinus('stringField), "expected to be of type numeric")
6457
assertError(Abs('stringField), "expected to be of type numeric")

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class HiveTypeCoercionSuite extends PlanTest {
203203

204204
ruleTest(HiveTypeCoercion.ImplicitTypeCasts,
205205
NumericTypeUnaryExpression(Literal.create(null, NullType)),
206-
NumericTypeUnaryExpression(Cast(Literal.create(null, NullType), DoubleType)))
206+
NumericTypeUnaryExpression(Literal.create(null, DoubleType)))
207207
}
208208

209209
test("cast NullType for binary operators") {
@@ -215,9 +215,7 @@ class HiveTypeCoercionSuite extends PlanTest {
215215

216216
ruleTest(HiveTypeCoercion.ImplicitTypeCasts,
217217
NumericTypeBinaryOperator(Literal.create(null, NullType), Literal.create(null, NullType)),
218-
NumericTypeBinaryOperator(
219-
Cast(Literal.create(null, NullType), DoubleType),
220-
Cast(Literal.create(null, NullType), DoubleType)))
218+
NumericTypeBinaryOperator(Literal.create(null, DoubleType), Literal.create(null, DoubleType)))
221219
}
222220

223221
test("coalesce casts") {

0 commit comments

Comments
 (0)