Repository navigation
[GLUTEN-13673][VL] Enable native streaming appends on Spark 3.5 - #13674
ReemaAlzaid wants to merge 6 commits into
Conversation
|
Run Gluten Clickhouse CI on x86 |
malinjawi
left a comment
There was a problem hiding this comment.
Thanks for raising this @ReemaAlzaid, native streaming writes are a nice gap to close.
Wrapping the sink makes sense on 3.5. V1 sinks have no physical write node, and you keep Delta's dedup and commit. A few things before this can go in, mostly inline. Two more here:
- Nothing in CI runs this. delta-spark-test is 4.x only, and the sink is mocked in the backends-velox suite. Can you run DeltaSinkSuite and DeltaSinkImplicitCastSuite on 3.5 with native write on (stats on) and paste the results? Watch the cast-overflow tests: errors from a Spark-side cast under R2C come back as GlutenException, the same thing we hit on #13158.
- Could you share some numbers vs vanilla Delta, batch duration and CPU at roughly 10k / 100k / 1M rows per trigger? Small micro-batches pay R2C + writer setup every batch, so I'm not sure this is a win there.
Also, new Delta work is going to src-delta4 now. I'd rather see this on 4.x, where the Delta UT gate covers it. If you need 3.5 first, please open an issue for 4.x.
|
Run Gluten Clickhouse CI on x86 |
ReemaAlzaid
left a comment
There was a problem hiding this comment.
Thanks @malinjawi. I’ve updated the patch and replied inline
I also added a Spark 3.5 CI job for DeltaSinkSuite and DeltaSinkImplicitCastSuite, with native writes, native streaming writes, and statistics enabled.
I’ll share the suite results and benchmarks once validation is complete. The benchmarks cover 10k, 100k, and 1M rows per trigger. I’ll also open the Spark 4.x follow up PR
|
Run Gluten Clickhouse CI on x86 |
|
I ran the benchmark with Spark 3.5.5 / Delta 3.3.2, local[2], two input partitions, and stats enabled. Averages from five batches after two warmups:
CPU measures local JVM time from enqueue through processAllAvailable. Native writes were slower in this setup. Would you recommend different parallelism, a wider schema, or partitioned tables for a more representative comparison? |
13cfd2e to
8bb0ba0
Compare
|
Run Gluten Clickhouse CI on x86 |
malinjawi
left a comment
There was a problem hiding this comment.
Thanks @ReemaAlzaid, looks good now.
The GlutenDeltaFileFormatWriter change duplicates #13390. I'll get that merged first, then please rebase and drop the hunk.
On the benchmark, the baseline turns Gluten off, so it's measuring Gluten on vs off rather than the writer. With Gluten on in both runs and a wider schema (24 cols, 1M rows), native is ~1.6x faster per batch for me with a third less CPU. Narrow batches are mostly commit overhead, so they won't show a difference. Not blocking.
Anything else (Complete mode, 4.x), please open follow-ups for those.
@felipepessoto @zhztheplayer PTAL too.
|
Run Gluten Clickhouse CI on x86 |
|
Thanks @malinjawi! I’ve removed the duplicate writer change locally and will rebase once #13390 lands. I’ll update the benchmark to keep Gluten enabled in both runs. I’ll also open follow ups for Complete mode and Spark 4.x support |
felipepessoto
left a comment
There was a problem hiding this comment.
Please keep encrypted writes and unpartitioned appends with a positive maxRecordsPerFile on Delta's writer until the native writer can honor those settings. Those are the two merge blockers. I also left comments on checkpoint replay and the benchmark's first batch.
| // Keep Delta's schema checks, epoch deduplication and commit protocol in the original sink | ||
| class GlutenDeltaSink(private[delta] val delegate: DeltaSink) extends Sink { | ||
| override def addBatch(batchId: Long, data: DataFrame): Unit = | ||
| DeltaV2WriteOperators.withColumnarTransaction { |
There was a problem hiding this comment.
This switches even an encrypted Delta table to the 3.5 Velox writer. That writer doesn't use the Parquet crypto factory from the job's Hadoop configuration, so a streaming append that parquet-mr would encrypt can commit plaintext files. Please check the effective write configuration (including table properties) and fall back to Delta's writer when parquet.crypto.factory.class is set, as the 4.x GlutenDeltaNativeWriteGate does.
There was a problem hiding this comment.
Added the check at transaction write time using the effective Hadoop configuration, including table properties. When parquet.crypto.factory.class is set, it falls back to Delta’s writer. Tests verified encrypted output, including when the table property changes after stream startup.
There was a problem hiding this comment.
Thanks, this addresses my concern. The test that sets the table property after startup checks the encrypted PARE header on disk and reads the rows back with Spark. That covers the case I was worried about.
Auto-replied by the GitHub Copilot app
| plan.resolveOperatorsDown { | ||
| case write: WriteToStream if write.outputMode == OutputMode.Append() => | ||
| write.sink match { | ||
| case sink: DeltaSink => write.copy(sink = new GlutenDeltaSink(sink)) |
There was a problem hiding this comment.
An unpartitioned stream with maxRecordsPerFile=1 also gets wrapped. For a two-row Velox batch, Spark rotates the file after the placeholder row, but Velox only writes data on the terminal row: one file gets no footer and the other gets both rows. With stats off, Delta commits both. The empty-task fix in #13390 doesn't cover this because the task has input. Please fall back for a positive effective file limit on unpartitioned writes, or split the batch at the file boundary.
There was a problem hiding this comment.
Added fallback to Delta’s writer for unpartitioned writes with a positive effective limit, respecting writer options over the session setting. Tested with stats on and off, verifying valid files and the expected rows per file
There was a problem hiding this comment.
The new tests verify actual rows per file with stats both on and off, including when the writer option overrides the session limit. That covers the rotation bug I reported here.
Auto-replied by the GitHub Copilot app
| val samples = scala.collection.mutable.ArrayBuffer.empty[(Long, Double)] | ||
| try { | ||
| query.processAllAvailable() | ||
| var previousBatchId = Option(query.lastProgress).map(_.batchId).getOrElse(-1L) |
There was a problem hiding this comment.
The first processAllAvailable() runs on an empty MemoryStream. Spark 3.5 can publish idle progress with batchId == 0 without advancing the batch ID. If lastProgress sees that event, the first real batch is also 0 and the p.batchId > previousBatchId filter rejects it, aborting the benchmark with “Expected one data trigger, found 0”. This is a fresh checkpoint, so initialize previousBatchId to -1L and advance it only for data-bearing progress.
There was a problem hiding this comment.
Changed previousBatchId to start at -1L and advance only for data-bearing progress. The updated benchmark ran successfully.
There was a problem hiding this comment.
Starting at -1L and advancing only on data-bearing progress fixes the batch 0 case. Thanks for also keeping Gluten enabled in both benchmark runs.
Auto-replied by the GitHub Copilot app
| assert(query.recentProgress.nonEmpty) | ||
| assert(query.recentProgress.forall(_.sink.description == s"DeltaSink[$path]")) | ||
| } finally { | ||
| query.stop() |
There was a problem hiding this comment.
All three batches advance normally in one run. Please add a replay case for the failure window after Delta commits an epoch but before Spark records it in the checkpoint. Restart from that checkpoint with a replayable source and verify the same epoch adds no rows or AddFiles, then verify the next epoch can commit. The observer test starts a transaction but never commits one, so it doesn't cover this exactly-once guarantee.
There was a problem hiding this comment.
Added a restart test with a replayable file source. It simulates the failure window by removing Spark’s commit marker while keeping the source offset and Delta commit. Replaying the same epoch adds no rows or AddFiles
There was a problem hiding this comment.
Removing only Spark’s commits/0 marker recreates the failure window I meant. The test checks that the Delta version and file set stay unchanged on replay, then verifies that epoch 1 commits. This addresses my coverage request.
Auto-replied by the GitHub Copilot app
ReemaAlzaid
left a comment
There was a problem hiding this comment.
Thanks @felipepessoto! Addressed all four comments and replied inline. Tests passed except the two empty batch cases waiting on #13390. I’ll rebase once it lands
| // Keep Delta's schema checks, epoch deduplication and commit protocol in the original sink | ||
| class GlutenDeltaSink(private[delta] val delegate: DeltaSink) extends Sink { | ||
| override def addBatch(batchId: Long, data: DataFrame): Unit = | ||
| DeltaV2WriteOperators.withColumnarTransaction { |
There was a problem hiding this comment.
Added the check at transaction write time using the effective Hadoop configuration, including table properties. When parquet.crypto.factory.class is set, it falls back to Delta’s writer. Tests verified encrypted output, including when the table property changes after stream startup.
| val samples = scala.collection.mutable.ArrayBuffer.empty[(Long, Double)] | ||
| try { | ||
| query.processAllAvailable() | ||
| var previousBatchId = Option(query.lastProgress).map(_.batchId).getOrElse(-1L) |
There was a problem hiding this comment.
Changed previousBatchId to start at -1L and advance only for data-bearing progress. The updated benchmark ran successfully.
| assert(query.recentProgress.nonEmpty) | ||
| assert(query.recentProgress.forall(_.sink.description == s"DeltaSink[$path]")) | ||
| } finally { | ||
| query.stop() |
There was a problem hiding this comment.
Added a restart test with a replayable file source. It simulates the failure window by removing Spark’s commit marker while keeping the source offset and Delta commit. Replaying the same epoch adds no rows or AddFiles
|
Run Gluten Clickhouse CI on x86 |
6c3d87c to
a3e80b3
Compare
|
Run Gluten Clickhouse CI on x86 |
a3e80b3 to
d713183
Compare
|
Run Gluten Clickhouse CI on x86 |
felipepessoto
left a comment
There was a problem hiding this comment.
Thanks for addressing the four earlier comments. The remaining correctness blocker I found is the historical-date write: with Spark 3.5’s default rebase policy, Delta rejects the batch, but the native sink commits it and advances the checkpoint. Please preserve Delta’s behavior before merging. The replay-test and documentation comments below are nonblocking.
| .map(_.toLong) | ||
| .getOrElse(spark.sessionState.conf.maxRecordsPerFile) | ||
| // Only the partitioned native writer can split a columnar batch across output files. | ||
| if (encrypted || (metadata.partitionColumns.isEmpty && maxRecordsPerFile > 0)) { |
There was a problem hiding this comment.
I reproduced this on Spark 3.5.5 / Delta 3.3.2 with the streaming code from d713183. For an unpartitioned append of DATE '1500-01-01' under the default spark.sql.parquet.datetimeRebaseModeInWrite=EXCEPTION, Delta's writer raised WRITE_ANCIENT_DATETIME and left no commit. Turning on native streaming writes committed Delta version 0 and Spark checkpoint commits/0. I got the same result with statistics on and off. In LEGACY mode, parquet-mr wrote physical day -171655 with the legacy calendar marker; Velox wrote -171664 without it.
Please fall back for DATE data columns when the mode isn't CORRECTED, as the 4.x write gate does, and add a streaming regression test that checks the exception occurs before the commit.
| assert(source.mkdir()) | ||
| def addInput(name: String, ids: Seq[Long]): Unit = { | ||
| val json = ids.map(id => s"""{"id":$id}""").mkString("\n") | ||
| Files.write( |
There was a problem hiding this comment.
Files.write creates second.json in the watched directory before it writes the bytes. I forced that scheduling window in the restarted stream: Spark committed epoch 1 while the file was empty. After the write finished, the table still had only rows 1 and 2; publishing the same JSON by atomic rename delivered rows 3 and 4. This is a test reliability issue, not the cause of the current CI failures. Please write the file outside source, close it, then move it into source atomically.
| | | `insertInto(t)`, `saveAsTable(t)` in append mode on an existing table, `writeTo(t).append()`, `overwrite(condition)`, `overwritePartitions()` | PartialOffload | From code. | | ||
| | `MERGE INTO` | | PartialOffload | Scans, the DML target scan and joins can run in Velox. On Spark 3.5 and 4.0, Gluten's tests check that a deletion-vector MERGE runs a scan of the target table in Velox. The other cases are from code. Native MERGE write is in progress in [#13324](https://github.com/apache/gluten/pull/13324). | | ||
| | | `writeStream.format("delta")` | PartialOffload | Inside `foreachBatch`, batch writes follow the rows above. From code. | | ||
| | | `writeStream.format("delta")` | Experimental Offload on Spark 3.5 in append mode; otherwise PartialOffload | Requires both native write and native streaming write on. Column-mapped tables use Delta's writer. Row tracking is unvalidated and retains native scan limitations. Inside `foreachBatch`, batch writes follow the rows above. From code. | |
There was a problem hiding this comment.
Please update the write-problems and configuration tables to match the new transaction guard, too. They still say Spark 3.5 may produce invalid files with a positive unpartitioned maxRecordsPerFile and describe parquet.crypto.factory.class fallback only for 4.x. This change makes both cases use Delta's writer on 3.5 for batch as well as streaming. The empty-task problem is separate.
|
Run Gluten Clickhouse CI on x86 |
e7602a4 to
916742e
Compare
|
Run Gluten Clickhouse CI on x86 |
ReemaAlzaid
left a comment
There was a problem hiding this comment.
Thanks @felipepessoto! Addressed all three comments: DATE rebase fallback, atomic replay inputs, and updated docs
What changes are proposed in this pull request?
Enable native Delta streaming appends on Spark 3.5 / Delta 3.3.2 using the existing native writer. Preserve Delta’s schema checks, batch-ID handling, commits, and Gluten fallback settings.
Add streaming and kafka to delta tests, CI coverage, and documentation.
related: #13673
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?