maropu commented on a change in pull request #26472: [SPARK-29838][SQL]
PostgreSQL dialect: cast to timestamp
URL: https://github.com/apache/spark/pull/26472#discussion_r346842564
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/postgreSQL/PostgreCastBase.scala
##########
@@ -16,19 +16,31 @@
*/
package org.apache.spark.sql.catalyst.expressions.postgreSQL
+import java.time.ZoneId
+
+import org.apache.spark.sql.AnalysisException
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.{CodegenContext,
JavaCode}
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.catalyst.util.postgreSQL.StringUtils
import org.apache.spark.sql.types._
import org.apache.spark.unsafe.types.UTF8String
-case class PostgreCastToBoolean(child: Expression, timeZoneId: Option[String])
- extends CastBase {
+abstract class PostgreCastBase extends CastBase {
Review comment:
How about the base class impl. like this?
```
abstract class PostgreCastBase(toType: DataType) extends CastBase {
def fromTypes: TypeCollection
override def dataType: DataType = toType
override protected def ansiEnabled: Boolean =
throw new UnsupportedOperationException("PostgreSQL dialect doesn't
support ansi mode")
override def checkInputDataTypes(): TypeCheckResult = {
if (!fromTypes.acceptsType(child.dataType)) {
TypeCheckResult.TypeCheckFailure(
s"cannot cast type ${child.dataType.simpleString} to boolean")
} else {
TypeCheckResult.TypeCheckSuccess
}
}
override def nullable: Boolean = child.nullable
override def sql: String = s"CAST(${child.sql} AS ${toType.sql})"
override def toString: String =
s"PostgreCastTo${toType.simpleString}($child as ${toType.simpleString})"
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]