This is an automated email from the ASF dual-hosted git repository.
rui-mo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 3b5fc5a0f3 [GLUTEN-12538][VL] Support cast between DATE and
TIMESTAMP_NTZ (#12966)
3b5fc5a0f3 is described below
commit 3b5fc5a0f36ae9f8e7bf6592e9b7f3ac39638a66
Author: Felipe Pessoto <[email protected]>
AuthorDate: Mon Sep 7 07:29:55 2026 -0700
[GLUTEN-12538][VL] Support cast between DATE and TIMESTAMP_NTZ (#12966)
---
.../functions/DateFunctionsValidateSuite.scala | 25 ++++++++++++++++++++++
.../substrait/SubstraitToVeloxPlanValidator.cc | 4 ++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git
a/backends-velox/src/test/scala/org/apache/gluten/functions/DateFunctionsValidateSuite.scala
b/backends-velox/src/test/scala/org/apache/gluten/functions/DateFunctionsValidateSuite.scala
index b51b3563d2..98a8b4a4b4 100644
---
a/backends-velox/src/test/scala/org/apache/gluten/functions/DateFunctionsValidateSuite.scala
+++
b/backends-velox/src/test/scala/org/apache/gluten/functions/DateFunctionsValidateSuite.scala
@@ -621,6 +621,11 @@ class DateFunctionsValidateSuite extends
FunctionsValidateSuite {
checkGlutenPlan[ProjectExecTransformer]
}
+ // cast(timestamp_ntz as date)
+ runQueryAndCompare("select cast(ts as date) from view") {
+ checkGlutenPlan[ProjectExecTransformer]
+ }
+
// cast(timestamp_ntz as string)
runQueryAndCompare("select cast(ts as string) from view") {
checkGlutenPlan[ProjectExecTransformer]
@@ -681,6 +686,26 @@ class DateFunctionsValidateSuite extends
FunctionsValidateSuite {
runQueryAndCompare("select cast(str as timestamp_ntz) from str_view") {
checkGlutenPlan[ProjectExecTransformer]
}
+
+ val datePath = dir.getAbsolutePath + "/date_view"
+ Seq(
+ java.sql.Date.valueOf("1969-12-31"),
+ java.sql.Date.valueOf("1970-01-01"),
+ java.sql.Date.valueOf("2000-01-01")
+ ).toDF("d").coalesce(1).write.mode("overwrite").parquet(datePath)
+ spark.read.parquet(datePath).createOrReplaceTempView("date_view")
+
+ // cast(date as timestamp_ntz)
+ runQueryAndCompare("select cast(d as timestamp_ntz) from date_view") {
+ checkGlutenPlan[ProjectExecTransformer]
+ }
+
+ // Ensure native execution works under a non-UTC session timezone.
+ withSQLConf("spark.sql.session.timeZone" -> "America/Los_Angeles") {
+ runQueryAndCompare("select cast(d as timestamp_ntz) from date_view")
{
+ checkGlutenPlan[ProjectExecTransformer]
+ }
+ }
}
}
}
diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
index 2b36c1ff41..618ffa1c0c 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
+++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
@@ -305,13 +305,13 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const
TypePtr& fromType, const
// Limited support for TimestampNTZ from/to X
// Casts between Timestamp and TimestampNTZ are handled in from/to timestamp.
if (fromType->equivalent(*TIMESTAMP_UTC())) {
- if (toType->isVarchar() || toType->isVarbinary()) {
+ if (toType->isDate() || toType->isVarchar() || toType->isVarbinary()) {
return true;
}
return false;
}
if (toType->equivalent(*TIMESTAMP_UTC())) {
- if (fromType->isVarchar()) {
+ if (fromType->isDate() || fromType->isVarchar()) {
return true;
}
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]