You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2025/06/28 16:50:20 UTC
Re: [PR] feat: Add from_unixtime support [datafusion-comet]
andygrove commented on code in PR #1943:
URL: https://github.com/apache/datafusion-comet/pull/1943#discussion_r2173423255
##########
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala:
##########
@@ -1179,6 +1179,29 @@ object QueryPlanSerde extends Logging with CometExprShim {
})
optExprWithInfo(optExpr, expr, child)
+ case FromUnixTime(sec, format, timeZoneId) =>
+ val secExpr = exprToProtoInternal(sec, inputs, binding)
+ val formatExpr = exprToProtoInternal(format, inputs, binding)
+ val timeZone = exprToProtoInternal(Literal(timeZoneId.orNull), inputs, binding)
+
+ // TODO: DataFusion toChar does not support Spark format
+ // https://github.com/apache/datafusion/issues/16577
+ // https://github.com/apache/datafusion/issues/14536
+ // TODO: DataFusion supports only -8334601211038 <= sec <= 8210266876799
+ // https://github.com/apache/datafusion/issues/16594
+ // if (secExpr.isDefined && formatExpr.isDefined) {
+ // val timestampExpr = scalarFunctionExprToProto("from_unixtime", Seq(secExpr, timeZone): _*)
+ // val optExpr = scalarFunctionExprToProto("to_char", Seq(timestampExpr, formatExpr): _*)
+ // optExprWithInfo(optExpr, expr, sec, format)
+ if (secExpr.isDefined && formatExpr.isDefined && format == Literal(
+ TimestampFormatter.defaultPattern)) {
+ val optExpr = scalarFunctionExprToProto("from_unixtime", Seq(secExpr, timeZone): _*)
+ castToProto(expr, timeZoneId, StringType, optExpr.get, CometEvalMode.LEGACY)
+ } else {
+ withInfo(expr, sec, format)
+ None
+ }
Review Comment:
nit: rather than adding this code directly in this file, could you delegate to an object that implements `CometExpressionSerde`. See https://github.com/apache/datafusion-comet/pull/1932 for an example of this approach.
--
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.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org