Repository navigation
[GLUTEN-11622][VL] Allow operators passing TimestampNTZ values through to run natively - #13757
WangGuangxin wants to merge 3 commits into
Conversation
|
Run Gluten Clickhouse CI on x86 |
…h to run natively With TimestampNTZ validation disabled (the default), FallbackByTimestampNTZ still only allowed scans, aggregates, shuffle exchanges and some projects. Any other operator with TimestampNTZ in its input or output schema fell back, e.g. Sort, Filter, joins, Window, WindowGroupLimit and TakeOrderedAndProject. Allow these operators when every expression touching TimestampNTZ only references, compares or conditionally passes NTZ values, or is an NTZ function already supported natively (cast, hour/minute/second, timestampadd, convert_timezone, make_timestamp, min/max/first/last/count, lag/lead/nth_value). Native validation still checks the functions and signatures used, so e.g. comparisons Velox can't evaluate yet still fall back. RANGE frames with value offsets over an NTZ order key are not offloaded.
A filter such as `ts_ntz IN (TIMESTAMP_NTZ '2023-10-01 12:34:57', ...)` fell back with "Filter has TimestampNTZType in input/output schema". IN and INSET were missing from the TimestampNTZ expressions that pass-through operators may contain. Allow In and InSet there. Native validation still checks Velox's `in` signature, so the filter falls back until Velox registers `in` for TIMESTAMP UTC.
14602c5 to
aced7a8
Compare
|
Run Gluten Clickhouse CI on x86 |
rui-mo
left a comment
There was a problem hiding this comment.
@WangGuangxin Thanks for the fix! Would you be interested in explicitly supporting the TimestampUTC type in the relevant Velox operators first, rather than relying on implicit support? If no code changes are needed, we could update the documentation and add relevant tests in Velox.
…tampNTZ to run natively A window such as `rank() OVER (PARTITION BY k ORDER BY ts_ntz)` fell back with "Window has TimestampNTZType in input/output schema", and so did the WindowGroupLimit Spark plans for `rank() <= n`. Rank, DenseRank and PercentRank take the window order keys as children, so the NTZ check rejected them, while RowNumber, which has no children, passed. `greatest`/`least` over NTZ values fell back the same way. Allow Rank, DenseRank, PercentRank, Greatest and Least in the NTZ expressions that pass-through operators may contain. They only compare NTZ values. Native validation still checks Velox's `greatest`/`least` signatures, so those fall back until Velox registers them for TIMESTAMP UTC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Run Gluten Clickhouse CI on x86 |
@rui-mo ok |
|
@rui-mo A feature gap is facebookincubator/velox#20647. please help review . |
|
My Delta writer PR (#13512) also touches One case I’ll keep covered on my side: for a struct containing both timestamp types, |
felipepessoto
left a comment
There was a problem hiding this comment.
Please fix the tied-rank case before merging. On Spark 4.1, the merge-base validator preserved all three input rows, but this revision returned only two with the same data and backend. The inline comments also cover the Delta fallback expectation and the missing Unix timestamp functions.
| case _: BroadcastExchangeExec | _: ExpandExec | _: UnionExec | _: CoalesceExec => true | ||
| case _: GlobalLimitExec | _: LocalLimitExec | _: CollectLimitExec => true | ||
| case _: WindowExec => true | ||
| case p => SparkShimLoader.getSparkShims.isWindowGroupLimitExec(p) |
There was a problem hiding this comment.
This admits a WindowGroupLimit that drops tied rows. On Spark 4.1, with two rows sharing the same ts_ntz, RANK() OVER (PARTITION BY ts_ntz ORDER BY ts_ntz) filtered to r = 1 kept both in Spark but only one in Velox. DENSE_RANK() does the same. SubstraitToVeloxPlan.cc removes sort keys already used for partitioning and then builds a limited RowNumberNode when none remain. Please keep this case on Spark or fix that lowering so only ROW_NUMBER truncates ties, and cover it with an executed query.
| val rowFrame = SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow) | ||
| val rangeFrame = SpecifiedWindowFrame(RangeFrame, UnboundedPreceding, CurrentRow) | ||
| val plans = Seq[SparkPlan]( | ||
| SortExec(Seq(SortOrder(ts, Descending)), global = true, left), |
There was a problem hiding this comment.
The new sort behavior breaks an existing integration test. On Spark 4.1, VeloxDeltaSuite fails delta: TIMESTAMP_NTZ as partition column should fallback and return correct results: DeltaSuite.scala:890 sets noFallBack = false, which requires a fallback, but ORDER BY c1 now runs as a native sort over a native Delta scan. Please update the Velox expectation and keep the row comparison. The suite is shared with Bolt, so its expectation shouldn't change.
| case _: SortOrder | _: IsNull | _: IsNotNull | _: BinaryComparison => true | ||
| case _: In | _: InSet | _: Greatest | _: Least => true | ||
| case _: If | _: CaseWhen | _: Coalesce => true | ||
| case _: Cast | _: Hour | _: Minute | _: Second | _: TimestampAdd | _: ConvertTimezone => true |
There was a problem hiding this comment.
UnixTimestamp and ToUnixTimestamp are missing from this list. On Spark 4.1, SELECT unix_timestamp(ts_ntz), to_unix_timestamp(ts_ntz) uses a native projection, but WHERE unix_timestamp(ts_ntz) > 0 still runs as a Spark filter because this match rejects it. Please include both here, as the ProjectExec branch already does, and cover the predicate case.
What changes are proposed in this pull request?
TimestampNTZ validation is disabled by default (
spark.gluten.sql.columnar.backend.velox.enableTimestampNtzValidation=false). Even so,FallbackByTimestampNTZonly allowed scans, aggregates, shuffle exchanges and some projects. Any other operator with TimestampNTZ in its input or output schema fell back with<Node> has TimestampNTZType in input/output schema. This included Sort, Filter, the joins, Window, WindowGroupLimit and TakeOrderedAndProject.This PR allows those operators: Sort, Filter, TakeOrderedAndProject, the joins (SortMergeJoin, ShuffledHashJoin, BroadcastHashJoin, BroadcastNestedLoopJoin, CartesianProduct), BroadcastExchange, Expand, Union, Coalesce, the limits, Window and WindowGroupLimit. The condition is that every expression touching TimestampNTZ is one of:
IsNull/IsNotNull, orIf/CaseWhen/Coalesce;min/max/first/last/count, orlag/lead/nth_value/In/InSet.Native validation still checks the functions and signatures used. For example, comparisons for which Velox has no
(TIMESTAMP UTC, TIMESTAMP UTC)signature still fall back. Unsupported NTZ expressions (e.g.date_formaton NTZ) and RANGE frames with value offsets over an NTZ order key are not offloaded.Related issue: #11622