Repository navigation
[VL][Iceberg] Fix timestamptz columns written with isAdjustedToUTC=false in Parquet footer - #13684
Anirban-Chand wants to merge 12 commits into
Conversation
|
Cc: @infvg |
| col.`type`().asInstanceOf[Types.TimestampType].shouldAdjustToUTC() | ||
| } | ||
| if (hasTimestampTz) { | ||
| icebergProperties.put("parquet.writer.timestamp.timezone", "UTC") |
There was a problem hiding this comment.
This never reaches velox, gluten passes empty serde parameters, and Velox sets the timezone to "" here.
There was a problem hiding this comment.
Good catch, thanks @infvg! You're right—Velox's WriterOptionsAdapter.cpp explicitly overrides kWriterSerdeTimestampTimezone = "" in applyPreConfigs, which causes ArrowSchema.cpp:240 to write isAdjustedToUTC=false.
A proper fix will require updating Velox's WriterOptionsAdapter.cpp to set "UTC" for timestamptz. I'll open a PR in Velox for this.
There was a problem hiding this comment.
This still never reaches velox, gluten passes empty serdeParameters to the insert handle.
There was a problem hiding this comment.
Fixed in cpp/velox/compute/iceberg/IcebergWriter.cc — createSerdeParameters now extracts parquet::ParquetConfig::kWriterSerdeTimestampTimezone from sparkConfs and forwards it into IcebergInsertTableHandle::serdeParameters. Upstream facebookincubator/velox#20487 (9c6c9667b2c) is also merged to preserve caller-provided timezone in ParquetWriterOptionsAdapter.
| // path (validation in IcebergWriteExec blocks them). If per-column support is needed in | ||
| // future, consider Option 2/3 discussed in https://github.com/apache/gluten/issues/13429. | ||
| val hasTimestampTz = writeSchema | ||
| .columns() |
There was a problem hiding this comment.
This only checks top-level columns, can we see if we can either add support for nested columns, and only if it's not possible without a velox change, raise the velox PR + verify fallback for nested case.
There was a problem hiding this comment.
Agreed. I'll update the check using TypeUtil.visit(...) to cover nested fields recursively. I will also verify fallback behavior if Velox can't support mixed/nested types without deeper changes.
| } | ||
| } | ||
|
|
||
| test("GLUTEN-13429: timestamptz columns written with isAdjustedToUTC=true") { |
There was a problem hiding this comment.
These tests might not be necessary, please check if this functionality is tested via our upstream iceberg tests, and if it is, we can remove this.
There was a problem hiding this comment.
Makes sense. I'll check iceberg_spark_ut.yml coverage, and if this is already tested upstream, I'll remove this test.
There was a problem hiding this comment.
@infvg, I verified the upstream Iceberg test suite: the upstream tests perform query-level round-trip validations (SELECT ... and comparing row values). Because Java/Spark-based Iceberg readers silently coerce the timestamp regardless of isAdjustedToUTC, those upstream tests pass even when isAdjustedToUTC=false (which is why #13429 was only caught by strict readers like iceberg-go).
The test in VeloxIcebergSuite.scala explicitly inspects ParquetFileReader.getFooter.getFileMetaData to assert isAdjustedToUTC=true directly on the physical Parquet metadata (matching the pattern used elsewhere in VeloxIcebergSuite for page version and codec footer verification).
I propose keeping this test so we have regression coverage verifying the physical Parquet metadata flag itself. What do you think?
There was a problem hiding this comment.
Could you move this out of the enhanced test class (i think this isn't being run)? I think this test will actually fail CI due to the above issue
There was a problem hiding this comment.
Moved to active backends-velox/src-iceberg/test/scala/org/apache/gluten/execution/VeloxIcebergSuite.scala and extended to verify isAdjustedToUTC=true for both top-level (ts TIMESTAMP) and nested (nested STRUCT<ts: TIMESTAMP>) columns.
|
Hi @infvg, quick update on the review comments:
|
|
Hi @infvg, gentle ping on this when you have a moment. All CI checks across x86, ARM, Kafka, and Iceberg suites have finished and are now fully green. In parallel, we also added the end-to-end Iceberg write test verifying Parquet footer annotations on the upstream Velox PR (facebookincubator/velox#20487). Could you take another look when you get a chance? Thanks! |
1 similar comment
|
Hi @infvg, gentle ping on this when you have a moment. All CI checks across x86, ARM, Kafka, and Iceberg suites have finished and are now fully green. In parallel, we also added the end-to-end Iceberg write test verifying Parquet footer annotations on the upstream Velox PR (facebookincubator/velox#20487). Could you take another look when you get a chance? Thanks! |
## What changes are proposed in this pull request? [`withNativeStatistics`](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/GlutenDeltaStatsLifecycleSuite.scala#L105) waits up to 15 seconds for the statistics worker threads to exit, while two other checks in [`GlutenDeltaStatsLifecycleSuite`](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/GlutenDeltaStatsLifecycleSuite.scala#L156) did not wait. This change makes those checks wait the same way. The change also writes the aborted-write test's rows from a single partition, so that test always creates its native statistics. | Test | Before | After | |---|---|---| | "aborted Delta writes close native statistics before task runtimes" | statistics sometimes never created | statistics always created | | "newRow releases the batch when statistics fail during submission" | checks worker threads without waiting | waits up to 15 seconds | | "newRow propagates a statistics worker failure while consuming input" | checks worker threads without waiting | waits up to 15 seconds | [`GlutenDeltaJobStatsTracker`](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/stats/GlutenDeltaJobStatsTracker.scala#L128) runs each statistics worker on a single-thread pool that the task's completion listener [shuts down and awaits](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/stats/GlutenDeltaJobStatsTracker.scala#L237). The pool's thread can still be exiting when a test lists the live threads right after the task ends, which fails with `Set(331) was not empty Statistics workers survived task completion`. [`executeTask`](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala#L473) reads a row before it creates the writer in every partition except partition 0. The writer's statistics tracker reports its plan to the test's observer [when the tracker is created](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/stats/GlutenDeltaJobStatsTracker.scala#L192). The aborted-write test wrote its valid row from partition 0 and its null row from partition 1, so partition 1 failed the NOT NULL check before creating a tracker. The job abort could then kill partition 0's task before that task created its tracker, which fails with `[] was empty The write did not exercise native Delta statistics`. The two tests failed 10 times across 7 pull requests between 2026-11-19 and 2026-11-24, for example on apache#13684 and apache#13728. A re-run of the same commit passed for 7 of the 10 failures. The suite was added under apache#12743. Removing both races keeps unrelated Delta pull requests from going red on them. ## How was this patch tested? ### Automated tests The `spark-test-spark40 (3)`, `spark-test-spark41 (3)` and `spark-test-spark42 (3)` jobs of the [Velox Backend (x86) workflow](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/.github/workflows/velox_backend_x86.yml) run [`GlutenDeltaStatsLifecycleSuite`](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/GlutenDeltaStatsLifecycleSuite.scala#L111). ## Was this patch authored or co-authored using generative AI tooling? Generated-by: Co-authored with Claude Code (claude-opus-5-5)
… VeloxIcebergSuite
…erg-timestamptz-isAdjustedToUTC
|
Hi @infvg, addressed both review threads inline:
Note: |
What changes are proposed in this pull request?
Fixes #13429.
When writing Iceberg tables via the Velox backend, columns with Spark
TimestampType(which map to Iceberg'stimestamptz) were written into Parquet files withisAdjustedToUTC=false.According to the Iceberg Table Specification,
timestamptzmust be written as ParquetTimestamp(isAdjustedToUTC=true, unit=micros). Because the flag was missing/false, strict Iceberg readers such asapache/iceberg-gofail during operations like table compaction with:cannot promote timestamp to timestamptz.Root Cause
velox/dwio/parquet/writer/arrow/ArrowSchema.cpp:240),isAdjustedToUTCis derived purely from whether the Arrow timestamp type carries a non-empty timezone string:parquet.writer.timestamp.timezone(ParquetConfig.h:261) to attach the timezone string during Arrow schema construction (Bridge.cpp:371).AbstractIcebergWriteExec.scala, this serde property was not passed intoicebergProperties. As a result, Velox constructed the Arrow schema with an empty timezone string (""), causing the Parquet footer to default toisAdjustedToUTC=false.Proposed Fix
In
AbstractIcebergWriteExec.scala, inspect the Iceberg write schema (writeSchema). If any column is atimestamptz(col.type().typeId() == TypeID.TIMESTAMP && col.type().asInstanceOf[Types.TimestampType].shouldAdjustToUTC()), inject"parquet.writer.timestamp.timezone" -> "UTC"intoicebergPropertiesso Velox setsisAdjustedToUTC=truein the Parquet footer.How was this patch tested?
GLUTEN-13429: timestamptz columns written with isAdjustedToUTC=trueinVeloxIcebergSuite.scala.VeloxIcebergAppendDataExec)..parquetfile footer metadata containsisAdjustedToUTC=trueviaParquetFileReaderinspection.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Antigravity