Repository navigation
[GLUTEN-11622][VL] Tag TimestampNTZ Arrow fields so Velox imports them as TIMESTAMP_UTC - #13756
WangGuangxin wants to merge 2 commits into
Conversation
Range partitioning prepends a JVM-computed partition id column via VeloxColumnarBatch::compose, which rebuilt the row type from the child vectors' own types. For Spark TimestampNTZType, the row-to-columnar converter produces TIMESTAMP vectors while the Velox plan declares TIMESTAMP_UTC, and VeloxBatchResizer creates merged batches from the declared type. Batches of one stream could therefore compose to different row types, failing the hash shuffle writer check rowType_->equivalent(*rv.rowType()). Take child types from the source RowVector's declared row type in compose() and select(), and include both row types in the shuffle writer check message.
1072b43 to
4ff558d
Compare
rui-mo
left a comment
There was a problem hiding this comment.
@WangGuangxin Thanks for the fix. This looks a gap needs to be fixed for supporting TimestampNTZ type.
facebookincubator/velox#17116 tags schemas that Velox itself exports, and Velox imports an Arrow timestamp as TIMESTAMP_UTC when the field carries velox.logical_timestamp=utc.
The JVM builds row-to-columnar schema in SparkArrowUtil.toArrowField, which writes TimestampNTZType as a timestamp with no timezone and no tag, so Velox imports it as TIMESTAMP. The Substrait plan maps NTZ to TIMESTAMP_UTC, so mixed batches fail rowType_->equivalent in the shuffle writer; other JVM-built schemas such as shuffle read and broadcast have the same gap.
The suggested fix would be two JVM-only changes. First, SparkArrowUtil.toArrowField adds the utc tag to NTZ fields, including nested ones. Second, ArrowUtil.toArrowSchema, which ColumnarBatches.load uses, keeps the metadata Velox exported.
Do you think this make sense?
…_UTC The Substrait plan maps Spark TimestampNTZType to Velox TIMESTAMP_UTC, and Velox imports an Arrow timestamp as TIMESTAMP_UTC only when the field carries velox.logical_timestamp=utc. Arrow schemas built on the JVM had no such tag, so row-to-columnar, shuffle read and broadcast produced TIMESTAMP vectors for NTZ columns. With range partitioning, batches passed through from row-to-columnar and batches rebuilt by the shuffle-input resizer from the declared type then reached the hash shuffle writer with different row types and failed rowType_->equivalent(*rv.rowType()). - SparkArrowUtil.toArrowField tags NTZ fields, including nested ones. - ArrowUtil.toArrowSchema, used by ColumnarBatches.load, keeps the field metadata Velox exported instead of rebuilding it from the Spark type. Velox exports TIMESTAMP without a timezone, which fromArrowField maps to TimestampNTZType, so rebuilding would tag TIMESTAMP columns as TIMESTAMP_UTC. Revert the VeloxColumnarBatch compose()/select() change from the previous commit, which only covered the symptom. Keep the more detailed shuffle writer check message.
yes it's more reasonable, I'll try to refact it |
|
I noticed #13512 adds the same |
felipepessoto
left a comment
There was a problem hiding this comment.
The scalar NTZ tag survives, but the shuffle reader still loses it on map keys and values. I also noted how to keep the range-shuffle test on the batch-resize path.
| ) | ||
| case dataType => | ||
| val fieldType = new FieldType(nullable, toArrowType(dataType, timeZoneId), null) | ||
| val metadata = if (isTimestampNTZ(dataType)) timestampUtcMetadata else null |
There was a problem hiding this comment.
This tag reaches row-to-columnar, but shuffle read still loses it when NTZ is the direct key or value of a map. ShuffleReaderJniWrapper.make calls arrow::ImportSchema before VeloxShuffleReader derives its row type. I reproduced that round-trip with the pinned Arrow 18.0.0: scalar and array-element tags survived, but both tags on map<timestamp_ntz,timestamp_ntz> disappeared. The reader therefore produces MAP<TIMESTAMP,TIMESTAMP> where the plan expects two TIMESTAMP_UTC children. Can we reuse the original-C-schema reader change from #13512 and cover both a map key and a map value after a shuffle? This affects shuffle consumers independently of Delta writes.
| assert(find(plan)(_.isInstanceOf[RowToVeloxColumnarExec]).isDefined) | ||
| assert(find(plan) { | ||
| case e: ColumnarShuffleExchangeExec => | ||
| e.outputPartitioning.isInstanceOf[RangePartitioning] |
There was a problem hiding this comment.
This assertion also passes for a sort shuffle, which doesn't install VeloxResizeBatchesExec. And with a max batch size of 1024, for example, the 808-row tail is above the default 256-row resize minimum, so no batch is rebuilt. Please pin the batch size and resize minimum in this test and assert that the range exchange's input contains the resizer and native project. That way a plan or default change can't make the original mismatch disappear from the test.
What changes are proposed in this pull request?
The Substrait plan maps Spark
TimestampNTZTypeto VeloxTIMESTAMP_UTC. Velox imports an Arrow timestamp asTIMESTAMP_UTConly when the field carriesvelox.logical_timestamp=utc(facebookincubator/velox#17116). Otherwise it imports the field asTIMESTAMP.Arrow schemas built on the JVM by
SparkArrowUtil.toArrowFieldwrite NTZ as a timestamp with no timezone and no tag. Row-to-columnar, shuffle read and broadcast therefore produceTIMESTAMPvectors for NTZ columns, while the plan declaresTIMESTAMP_UTC.With range partitioning this fails the hash shuffle writer:
TIMESTAMPchild vectors.VeloxBatchResizerrebuilds short batches from the declared type, so their children areTIMESTAMP_UTC.VeloxColumnarBatch::compose, which takes the row type from the child vectors. Batches of the same stream then reach the writer with different row types:Changes:
SparkArrowUtil.toArrowFieldtags NTZ fields withvelox.logical_timestamp=utc, including fields nested in arrays, structs and maps.ArrowUtil.toArrowSchema, whichColumnarBatches.loaduses, keeps the field metadata Velox exported instead of rebuilding it from the Spark type. Velox exportsTIMESTAMPwithout a timezone, andfromArrowFieldmaps that toTimestampNTZType. Rebuilding with the new tag would therefore turn aTimestampTypecolumn intoTIMESTAMP_UTC.Minimal reproduction (spark-shell)
Launch
spark-shellwith the Gluten Velox bundle and:Each partition is converted into R2C batches of 4096, 4096 and 808 rows. The shuffle-input resizer passes the two full batches through and rebuilds the 808-row tail from the declared type.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)
Related issue: #11622