You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by ph...@apache.org on 2025/03/17 13:19:44 UTC

(incubator-gluten) branch main updated: [GLUTEN-9019][VL] Add a check to fall back "cast decimal to timestamp" (#9022)

This is an automated email from the ASF dual-hosted git repository.

philo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new dc6e712845 [GLUTEN-9019][VL] Add a check to fall back "cast decimal to timestamp" (#9022)
dc6e712845 is described below

commit dc6e712845d538aa0db775beab2ad609a16ee182
Author: Zhen Wang <64...@qq.com>
AuthorDate: Mon Mar 17 21:19:40 2025 +0800

    [GLUTEN-9019][VL] Add a check to fall back "cast decimal to timestamp" (#9022)
---
 cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc           |  5 +++++
 .../spark/sql/catalyst/expressions/GlutenCastSuite.scala       | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
index 6328c786e4..899a16d0d9 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
+++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
@@ -263,6 +263,11 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const TypePtr& fromType, const
 
   // Limited support for X to Timestamp.
   if (toType->isTimestamp()) {
+    if (fromType->isDecimal()) {
+      // Decimal to Timestamp is not supported.
+      LOG_VALIDATION_MSG("Casting from " + fromType->toString() + " to TIMESTAMP is not supported.");
+      return false;
+    }
     if (fromType->isDate()) {
       return true;
     }
diff --git a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
index fa809d5176..465590b4c8 100644
--- a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
+++ b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
@@ -266,4 +266,14 @@ class GlutenCastSuite extends CastSuiteBase with GlutenTestsTrait {
         }
     }
   }
+
+  testGluten("cast decimal to timestamp") {
+    val tz = TimeZone.getTimeZone(TimeZone.getDefault.getID)
+    val c = Calendar.getInstance(tz)
+    c.set(2015, 0, 1, 0, 0, 0)
+    c.set(Calendar.MILLISECOND, 123)
+    val d = Decimal(c.getTimeInMillis.toDouble / 1000)
+    checkEvaluation(cast(d, TimestampType), new Timestamp(c.getTimeInMillis))
+  }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org