-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29837][SQL] PostgreSQL dialect: cast to boolean #26463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
75d51ba
53c9a9b
2ab1847
6c2c0c7
6ad100c
101a026
be08daf
95caf40
8ebd5aa
0b9a78d
fda48c0
36f60ee
b7c6baf
b9711ae
68c7a13
999ec61
a178b79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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() | ||
|
||
| case dt => throw new UnsupportedOperationException(s"cannot cast type $dt to boolean") | ||
|
||
| } | ||
|
|
||
| override def castToBoolean(from: DataType): Any => Any = from match { | ||
| case StringType => | ||
| buildCast[UTF8String](_, str => { | ||
|
|
@@ -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) | ||
| } | ||
|
|
@@ -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) | ||
|
|
||
There was a problem hiding this comment.
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.