Skip to content
Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
check unsupported types in checkInputDataTypes()
  • Loading branch information
Ngone51 committed Nov 12, 2019
commit 6ad100c921ed6f1e52c2e191cced400b3a335206
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.spark.sql.catalyst.expressions.postgreSQL

import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.expressions.{CastBase, Expression, TimeZoneAwareExpression}
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.expressions.codegen.JavaCode
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: remove this unused import.

Expand All @@ -32,6 +33,11 @@ case class PostgreCastToBoolean(child: Expression, timeZoneId: Option[String])
override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
copy(timeZoneId = Option(timeZoneId))

override def checkInputDataTypes(): TypeCheckResult = child.dataType match {
case StringType | IntegerType => super.checkInputDataTypes()
Copy link
Contributor

Choose a reason for hiding this comment

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

why call super.checkInputDataTypes() here? shall we just return success?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just want the StringType and IntegerType to do Cast.canCast() check in super.checkInputDataTypes(), though I know it's not necessary.

I'll return success directly.

case dt => throw new UnsupportedOperationException(s"cannot cast type $dt to boolean")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should follow other expressions and return TypeCheckResult.TypeCheckFailure here.

}

override def castToBoolean(from: DataType): Any => Any = from match {
case StringType =>
buildCast[UTF8String](_, str => {
Expand All @@ -44,10 +50,6 @@ case class PostgreCastToBoolean(child: Expression, timeZoneId: Option[String])
throw new IllegalArgumentException(s"invalid input syntax for type boolean: $s")
}
})
case TimestampType | DateType | LongType | ShortType |
ByteType | DecimalType() | DoubleType | FloatType =>
_ => throw new UnsupportedOperationException(s"cannot cast type $from to boolean")

case IntegerType =>
super.castToBoolean(from)
}
Expand All @@ -65,11 +67,6 @@ case class PostgreCastToBoolean(child: Expression, timeZoneId: Option[String])
throw new IllegalArgumentException("invalid input syntax for type boolean: $c");
}
"""
case TimestampType | DateType | LongType | ShortType |
ByteType | DecimalType() | DoubleType | FloatType =>
(c, evPrim, evNull) =>
val fromType = JavaCode.javaType(from)
code"""throw new UnsupportedOperationException("cannot cast type $fromType to boolean");"""

case IntegerType =>
super.castToBooleanCode(from)
Expand Down