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
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,9 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
checkGlutenPlan[BatchScanExecTransformer]
}

// Ensures the fallback of unsupported function works.
// hour(timestamp_ntz) runs natively; output is int (no NTZ propagation).
runQueryAndCompare("select hour(ts) from view") {
df =>
assert(collect(df.queryExecution.executedPlan) {
case p if p.isInstanceOf[ProjectExec] => p
}.nonEmpty)
checkGlutenPlan[ProjectExecTransformer]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,33 @@ object Validators {
case p if HiveTableScanExecTransformer.isHiveTableScan(p) => true
case _ => false
}
val hasNTZ = plan.output.exists(a => containsNTZ(a.dataType)) ||
// True only if all NTZ-producing nodes in p's subtree are file scans.
// File scans run natively in Velox; their NTZ data never crosses
// RowToVeloxColumnar and therefore keeps correct semantics.
// In-memory sources (LocalTableScan) go through RowToVeloxColumnar
// which treats NTZ as UTC-adjusted, causing wrong results downstream.
def ntzOnlyFromFileScans(p: SparkPlan): Boolean = {
if (!p.output.exists(a => containsNTZ(a.dataType))) true
else
p match {
case _: BatchScanExec => true
case _: FileSourceScanExec => true
case q if HiveTableScanExecTransformer.isHiveTableScan(q) => true
case _ if p.children.isEmpty => false
case _ => p.children.forall(ntzOnlyFromFileScans)
}
}
// Allow plan nodes that consume NTZ from file scans but produce non-NTZ
// output (e.g. hour(timestamp_ntz) -> int). Nodes that propagate NTZ in
// their output still fall back until full NTZ support is complete.
// Exception: WriteFilesExec - its own output is metadata (no NTZ), but
// the native parquet writer incorrectly writes NTZ columns from its child
// as UTC-adjusted timestamps, so we must fall back when the child has NTZ.
val outputHasNTZ = plan.output.exists(a => containsNTZ(a.dataType))
val writeChildHasNTZ = plan.isInstanceOf[WriteFilesExec] &&
plan.children.exists(_.output.exists(a => containsNTZ(a.dataType)))
if (isScan || !hasNTZ) {
val childNTZFromFileScans = plan.children.forall(ntzOnlyFromFileScans)
if (isScan || (!outputHasNTZ && !writeChildHasNTZ && childNTZFromFileScans)) {
return pass()
}
}
Expand Down
Loading