Skip to content

Commit 330a5c8

Browse files
Update Code based on comments
1 parent b834ed4 commit 330a5c8

File tree

2 files changed

+18
-13
lines changed
  • sql
    • catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions
    • hive/src/main/scala/org/apache/spark/sql/hive

2 files changed

+18
-13
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,22 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression {
244244
b => x.numeric.asInstanceOf[Numeric[Any]].toFloat(b)
245245
}
246246

247-
private[this] lazy val cast: Any => Any = dataType match {
248-
case StringType => castToString
249-
case BinaryType => castToBinary
250-
case DecimalType => castToDecimal
251-
case TimestampType => castToTimestamp
252-
case BooleanType => castToBoolean
253-
case ByteType => castToByte
254-
case ShortType => castToShort
255-
case IntegerType => castToInt
256-
case FloatType => castToFloat
257-
case LongType => castToLong
258-
case DoubleType => castToDouble
247+
private[this] lazy val cast: Any => Any = if (child.dataType == dataType) {
248+
sys.error(s"$dataType Cast To $dataType should have been eliminated in ConstantFolding")
249+
} else {
250+
dataType match {
251+
case StringType => castToString
252+
case BinaryType => castToBinary
253+
case DecimalType => castToDecimal
254+
case TimestampType => castToTimestamp
255+
case BooleanType => castToBoolean
256+
case ByteType => castToByte
257+
case ShortType => castToShort
258+
case IntegerType => castToInt
259+
case FloatType => castToFloat
260+
case LongType => castToLong
261+
case DoubleType => castToDouble
262+
}
259263
}
260264

261265
override def eval(input: Row): Any = {

sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ private[hive] abstract class HiveFunctionRegistry
5757
functionClassName,
5858
children.zip(expectedDataTypes).map {
5959
case (e, NullType) => e
60-
case (e, t) => if (e.dataType == t) e else Cast(e, t)
60+
case (e, t) if (e.dataType == t) => e
61+
case (e, t) => Cast(e, t)
6162
}
6263
)
6364
} else if (classOf[GenericUDF].isAssignableFrom(functionInfo.getFunctionClass)) {

0 commit comments

Comments
 (0)