Skip to content

Commit 24f1d2a

Browse files
author
Mariam-Almesfer
committed
Enable VARCHAR ↔ timestamp_ntz cast native execution in Velox backend
1 parent e497b43 commit 24f1d2a

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

backends-velox/src/test/scala/org/apache/gluten/functions/DateFunctionsValidateSuite.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,15 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
599599
checkGlutenPlan[BatchScanExecTransformer]
600600
}
601601

602-
// Ensures the fallback of unsupported function works.
603-
runQueryAndCompare("select hour(ts) from view") {
604-
df =>
605-
assert(collect(df.queryExecution.executedPlan) {
606-
case p if p.isInstanceOf[ProjectExec] => p
607-
}.nonEmpty)
602+
// cast(timestamp_ntz as string) runs natively.
603+
runQueryAndCompare("select cast(ts as string) from view") {
604+
checkGlutenPlan[ProjectExecTransformer]
605+
}
606+
607+
// cast(string as timestamp_ntz) runs natively.
608+
spark.createDataset(inputs).toDF("str").createOrReplaceTempView("str_view")
609+
runQueryAndCompare("select cast(str as timestamp_ntz) from str_view") {
610+
checkGlutenPlan[ProjectExecTransformer]
608611
}
609612
}
610613
}

ep/build-velox/src/get-velox.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUN_SETUP_SCRIPT=ON
2525
ENABLE_ENHANCED_FEATURES=OFF
2626

2727
# Developer use only for testing Velox PR.
28-
UPSTREAM_VELOX_PR_ID=""
28+
UPSTREAM_VELOX_PR_ID="17498"
2929

3030
OS=`uname -s`
3131

gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/validator/Validators.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,12 @@ object Validators {
262262
case p if HiveTableScanExecTransformer.isHiveTableScan(p) => true
263263
case _ => false
264264
}
265-
val hasNTZ = plan.output.exists(a => containsNTZ(a.dataType)) ||
266-
plan.children.exists(_.output.exists(a => containsNTZ(a.dataType)))
267-
if (isScan || !hasNTZ) {
265+
// Allow nodes that either consume NTZ (e.g. hour(timestamp_ntz) -> int)
266+
// or produce NTZ from non-NTZ input (e.g. cast(string as timestamp_ntz)).
267+
// Only fall back when NTZ propagates unchanged through both input and output.
268+
val inputHasNTZ = plan.children.exists(_.output.exists(a => containsNTZ(a.dataType)))
269+
val outputHasNTZ = plan.output.exists(a => containsNTZ(a.dataType))
270+
if (isScan || !(inputHasNTZ && outputHasNTZ)) {
268271
return pass()
269272
}
270273
}

0 commit comments

Comments
 (0)