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 971cd678c0 [GLUTEN-8744][VL] Add casting support for timestamp to long
(#8745)
971cd678c0 is described below
commit 971cd678c0ec242c10e60ebb2327c38401295a83
Author: Arnav Balyan <[email protected]>
AuthorDate: Tue Apr 29 14:44:05 2025 +0530
[GLUTEN-8744][VL] Add casting support for timestamp to long (#8745)
---
.../substrait/SubstraitToVeloxPlanValidator.cc | 14 +++++++++++-
.../utils/clickhouse/ClickHouseTestSettings.scala | 1 +
.../sql/catalyst/expressions/GlutenCastSuite.scala | 26 ++++++++++++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
index a91c96f039..ecb69fff6c 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
+++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
@@ -269,7 +269,19 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const
TypePtr& fromType, const
}
// Limited support for Timestamp to X.
- if (fromType->isTimestamp() && !(toType->isDate() || toType->isVarchar())) {
+ if (fromType->isTimestamp()) {
+ if (toType->isDecimal()) {
+ return false;
+ }
+
+ if (toType->isBigint()) {
+ return true;
+ }
+
+ if (toType->isDate() || toType->isVarchar()) {
+ return true;
+ }
+
return false;
}
diff --git
a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index e095d7760a..e0d1251580 100644
---
a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -626,6 +626,7 @@ class ClickHouseTestSettings extends BackendTestSettings {
.exclude("SPARK-36924: Cast YearMonthIntervalType to IntegralType")
.exclude("SPARK-36924: Cast IntegralType to YearMonthIntervalType")
.exclude("Cast should output null for invalid strings when ANSI is not
enabled.")
+ .exclude("cast timestamp to Int64 with floor division")
.exclude("cast array element from integer to string")
.exclude("cast array element from double to string")
.exclude("cast array element from bool to string")
diff --git
a/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
b/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
index 13eb8fa14c..b10a9cec20 100644
---
a/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
+++
b/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
@@ -219,6 +219,32 @@ class GlutenCastSuite extends CastSuite with
GlutenTestsTrait {
checkEvaluation(cast(Literal.create(null, IntegerType), ShortType), null)
}
+ test("cast timestamp to Int64 with floor division") {
+ val originalDefaultTz = TimeZone.getDefault
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
+ val testCases = Seq(
+ ("1970-01-01 00:00:00.000", 0L),
+ ("1970-01-01 00:00:00.999", 0L),
+ ("1970-01-01 00:00:01.000", 1L),
+ ("1970-01-01 00:00:59.999", 59L),
+ ("1970-01-01 00:01:00.000", 60L),
+ ("2000-01-01 00:00:00.000", 946684800L),
+ ("2024-02-16 12:34:56.789", 1708086896L),
+ ("9999-12-31 23:59:59.999", 253402300799L),
+ ("1969-12-31 23:59:59.999", -1L),
+ ("1969-12-31 23:59:58.500", -2L),
+ ("1900-01-01 12:00:00.000", -2208945600L)
+ )
+
+ for ((inputStr, expectedOutput) <- testCases) {
+ checkEvaluation(cast(Timestamp.valueOf(inputStr), LongType),
expectedOutput)
+ }
+ } finally {
+ TimeZone.setDefault(originalDefaultTz)
+ }
+ }
+
testGluten("cast string to timestamp") {
ThreadUtils.parmap(
ALL_TIMEZONES
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]