Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions spark/src/main/scala/org/apache/comet/serde/unixtime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ import org.apache.comet.serde.QueryPlanSerde.{exprToProtoInternal, optExprWithFa
object CometFromUnixTime extends CometExpressionSerde[FromUnixTime] with CodegenDispatchFallback {

override def getIncompatibleReasons(): Seq[String] = Seq(
"Only supports the default datetime format pattern `yyyy-MM-dd HH:mm:ss`." +
" DataFusion's valid timestamp range differs from Spark" +
"DataFusion's valid timestamp range differs from Spark" +
" (https://github.com/apache/datafusion/issues/16594)")

override def getSupportLevel(expr: FromUnixTime): SupportLevel = Incompatible(None)
override def getUnsupportedReasons(): Seq[String] = Seq(
"Only the default datetime format pattern `yyyy-MM-dd HH:mm:ss` is supported.")

override def getSupportLevel(expr: FromUnixTime): SupportLevel = {
if (expr.format != Literal(TimestampFormatter.defaultPattern())) {
Unsupported(Some("Only the default datetime pattern `yyyy-MM-dd HH:mm:ss` is supported"))
} else {
Incompatible(None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might wnat to add some SQL tests to verify the fallback and make sure the plan is annotated

}
}

override def convert(
expr: FromUnixTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ INSERT INTO test_from_unix_time VALUES (0), (1718451045), (-1), (NULL), (2147483
query
SELECT from_unixtime(t) FROM test_from_unix_time

query
query expect_fallback(Datetime pattern format is unsupported)
SELECT from_unixtime(t, 'yyyy-MM-dd') FROM test_from_unix_time

-- literal arguments
query
SELECT from_unixtime(0)

query
query expect_fallback(Datetime pattern format is unsupported)
SELECT from_unixtime(1718451045, 'yyyy-MM-dd')
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ CREATE TABLE test_from_unix_time_enabled(t long) USING parquet
statement
INSERT INTO test_from_unix_time_enabled VALUES (0), (1718451045), (-1), (NULL), (2147483647)

-- Even with allowIncompatible=true, the default datetime pattern is unsupported natively
query spark_answer_only
-- With allowIncompatible=true, the default datetime pattern runs natively
query
SELECT from_unixtime(t) FROM test_from_unix_time_enabled

query spark_answer_only
-- Non-default format patterns are Unsupported and always fall back to Spark
query expect_fallback(Datetime pattern format is unsupported)
SELECT from_unixtime(t, 'yyyy-MM-dd') FROM test_from_unix_time_enabled

-- literal arguments
query spark_answer_only
query
SELECT from_unixtime(0)

query spark_answer_only
query expect_fallback(Datetime pattern format is unsupported)
SELECT from_unixtime(1718451045, 'yyyy-MM-dd')