This is an automated email from the ASF dual-hosted git repository.
zhouyuan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 8d787c2b24 [DOC][VL] Add Kafka getting started guide (#13413)
8d787c2b24 is described below
commit 8d787c2b24f32f83c1d6cff14ef274888b602ef5
Author: Reema <[email protected]>
AuthorDate: Tue Nov 24 17:05:56 2026 +0300
[DOC][VL] Add Kafka getting started guide (#13413)
---
docs/backends/velox/get-started/Velox.md | 3 +
docs/backends/velox/get-started/VeloxKafka.md | 251 ++++++++++++++++++++++++++
docs/get-started/build-guide.md | 3 +-
docs/image/velox-kafka-read.svg | 63 +++++++
4 files changed, 319 insertions(+), 1 deletion(-)
diff --git a/docs/backends/velox/get-started/Velox.md
b/docs/backends/velox/get-started/Velox.md
index 3a0e9ca43e..cb1a1daa3b 100644
--- a/docs/backends/velox/get-started/Velox.md
+++ b/docs/backends/velox/get-started/Velox.md
@@ -54,6 +54,9 @@ git clone https://github.com/apache/gluten.git
It's recommended to use buildbundle-veloxbe.sh to build gluten in one script.
[Gluten build guide](../../../get-started/build-guide.md) listed the
parameters and their default value of build command for your reference.
+For experimental Kafka micro-batch reads, see [Kafka with Gluten and
Velox](VeloxKafka.md)
+for required build profiles and a streaming example.
+
**For x86_64 build**
First time build for all supported spark versions.
diff --git a/docs/backends/velox/get-started/VeloxKafka.md
b/docs/backends/velox/get-started/VeloxKafka.md
new file mode 100644
index 0000000000..fd5df59344
--- /dev/null
+++ b/docs/backends/velox/get-started/VeloxKafka.md
@@ -0,0 +1,251 @@
+---
+layout: page
+title: Kafka with Gluten and Velox
+nav_order: 13
+parent: Getting-Started
+---
+
+# Kafka with Gluten and Velox
+
+Gluten's experimental Kafka integration offloads eligible Spark Structured
+Streaming micro-batch reads to the Velox backend. Queries use Spark's existing
+`readStream.format("kafka")` API. Gluten changes how the Kafka scan executes:
+the native reader uses librdkafka to produce columnar batches inside each
+Spark executor.
+
+Spark continues to plan micro-batches, schedule tasks, and manage checkpoints
+and streaming sinks. Kafka writes use Spark's Kafka writer.
+
+## How Gluten reads Kafka
+
+
+
+1. **Spark** resolves topic partitions and plans offset ranges for each
micro-batch.
+2. **Gluten** replaces an eligible Kafka scan with
+ `MicroBatchScanExecTransformer`. Executor tasks pass the Substrait plan and
+ partition splits through JNI to Velox.
+3. **Velox** reads each topic partition over `[startOffset, endOffset)` using
+ librdkafka and returns columnar batches. Supported downstream operators can
+ also run natively.
+
+The native reader disables automatic consumer-group offset commits and offset
+storage; Spark owns checkpoint progress. The diagram shows one executor, but
+Spark can distribute tasks across multiple executors.
+
+## Supported reads
+
+- Kafka DataSource V2 **micro-batch reads** are eligible for offloading. Batch
+ reads and continuous processing remain available through Spark's Java Kafka
+ reader. Kafka writes use Spark's Kafka writer. Gluten does not offload these
+ operations.
+- Supported columns are `key` and `value` (`binary`), `topic` (`string`),
+ `partition` and `timestampType` (`int`), `offset` (`long`), and `timestamp`
+ (`timestamp`). Decode keys and values in the query as needed.
+- The native reader does not support `headers`. Queries that request `headers`
+ with `includeHeaders=true` fall back to Spark for the Kafka scan. Filters run
+ above the scan; Kafka predicate pushdown is not supported.
+- Spark's driver uses the Java Kafka client; native readers use librdkafka.
+ Unknown native properties are skipped, and Java JAAS, callback, and
credential
+ settings are not translated. Validate both client paths before using TLS or
+ SASL. Unsupported authentication settings can cause native reads to fail;
+ these failures do not automatically fall back to Spark's Java Kafka reader.
+ The example uses a local PLAINTEXT broker.
+
+To use Spark's Java Kafka reader explicitly, set
+`spark.gluten.sql.columnar.kafkaScan=false` before starting the streaming
query,
+for example with `--conf spark.gluten.sql.columnar.kafkaScan=false` when
launching
+Spark. Supported downstream operators remain eligible for native execution.
+The setting defaults to `true`.
+
+## Build Gluten with Kafka support
+
+The commands below use **Spark 3.5.5, Scala 2.12, and JDK 17 on Linux**,
matching
+the Kafka CI build configuration. The Kafka CI workflow currently runs Spark
+3.5 only. Native Kafka compatibility with other Spark versions supported by
+Gluten is not established by this example or that workflow.
+
+The Gluten checkout must include the Velox Kafka scan offload rule and native
+Kafka plan conversion, as well as the native reader. Building the reader alone
+does not enable scan offloading.
+
+Follow the prerequisites in the
+[Velox build guide](Velox.md), then build native
+libraries before the JVM bundle:
+
+```bash
+export JAVA_HOME=/path/to/jdk-17
+export PATH="$JAVA_HOME/bin:$PATH"
+export PROMPT_ALWAYS_RESPOND=y
+
+./dev/builddeps-veloxbe.sh --enable_vcpkg=ON --enable_kafka=ON \
+ --enable_s3=OFF --enable_gcs=OFF --enable_hdfs=OFF --enable_abfs=OFF
+
+./build/mvn clean install -Pbackends-velox -Pspark-3.5 -Pscala-2.12 \
+ -Pjava-17 -Pkafka -Pfast-build -DskipTests
+```
+
+Both Kafka build options are disabled by default:
+
+- `--enable_kafka=ON` builds the native Kafka connector and installs
librdkafka.
+- `-Pkafka` builds Gluten's JVM Kafka integration and includes it in the Velox
+ bundle through the backend's `gluten-kafka` dependency.
+
+`buildbundle-veloxbe.sh` does not add the `kafka` Maven profile automatically.
+
+## Start Spark with Gluten
+
+Set `GLUTEN_JAR` to the exact bundle produced under `package/target/`, and use
a
+Spark distribution and Kafka package with matching Spark and Scala versions:
+
+```bash
+export SPARK_HOME=/path/to/spark-3.5.5
+export GLUTEN_JAR=/absolute/path/to/gluten-velox-bundle.jar
+
+"$SPARK_HOME/bin/spark-shell" --master 'local[2]' \
+ --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.5.5 \
+ --jars "$GLUTEN_JAR" \
+ --conf spark.plugins=org.apache.gluten.GlutenPlugin \
+ --conf spark.memory.offHeap.enabled=true \
+ --conf spark.memory.offHeap.size=1g \
+ --conf
spark.shuffle.manager=org.apache.spark.shuffle.sort.ColumnarShuffleManager
+```
+
+The Spark Kafka package supplies the source and sink APIs; the Gluten bundle
+supplies native execution. Both are required at runtime. The `1g` off-heap
+allocation is for this small local example. Local mode runs Spark tasks in one
+process; the diagram shows the distributed deployment model.
+
+## Example: read Kafka with Gluten
+
+Use Spark's `rate` source to populate a Kafka topic, then read the topic with
+Gluten and print the results to the console. The producer supplies sample data;
+the consumer's Kafka scan is the operation to check for native offloading.
+The producer/consumer setup follows the
+[OpenLake Kafka
walkthrough](https://github.com/minio/openlake/blob/main/spark/end-to-end-spark-structured-streaming-kafka.md).
+
+### 1. Create a topic
+
+Start a local broker at `localhost:9092`, set `KAFKA_HOME` to the Kafka
installation,
+and create a fresh topic from another terminal:
+
+```bash
+"$KAFKA_HOME/bin/kafka-topics.sh" --bootstrap-server localhost:9092 \
+ --create --topic gluten-kafka-rate-demo --partitions 2 --replication-factor 1
+```
+
+For a cluster, replace `localhost:9092` throughout with broker addresses
reachable
+from both the driver and executors, including Kafka's advertised listener
addresses.
+
+### 2. Produce and consume records
+
+Run this block in `spark-shell` using `:paste`. The consumer starts first, and
+producer and consumer use separate checkpoints:
+
+```scala
+import java.nio.file.Files
+import org.apache.spark.sql.streaming.Trigger
+
+val liveRunDir = Files.createTempDirectory("gluten-kafka-rate-").toUri.toString
+val liveTopic = "gluten-kafka-rate-demo"
+val bootstrapServers = "localhost:9092"
+
+val consumed = spark.readStream
+ .format("kafka")
+ .option("kafka.bootstrap.servers", bootstrapServers)
+ .option("subscribe", liveTopic)
+ .option("startingOffsets", "earliest")
+ .option("failOnDataLoss", "true")
+ .load()
+ .selectExpr("topic", "partition", "offset", "CAST(value AS STRING) AS value")
+
+val consumer = consumed.writeStream
+ .format("console")
+ .outputMode("append")
+ .option("truncate", "false")
+ .option("checkpointLocation", liveRunDir + "consumer-checkpoint")
+ .trigger(Trigger.ProcessingTime("2 seconds"))
+ .start()
+
+try {
+ val producer = spark.readStream
+ .format("rate")
+ .option("rowsPerSecond", 10)
+ .load()
+ .selectExpr("CAST(value AS STRING) AS value")
+ .writeStream
+ .format("kafka")
+ .option("kafka.bootstrap.servers", bootstrapServers)
+ .option("topic", liveTopic)
+ .option("checkpointLocation", liveRunDir + "producer-checkpoint")
+ .trigger(Trigger.ProcessingTime("2 seconds"))
+ .start()
+
+ try {
+ producer.awaitTermination(15000)
+ } finally {
+ producer.stop()
+ }
+
+ consumer.processAllAvailable()
+ consumer.explain(true)
+} finally {
+ consumer.stop()
+}
+```
+
+The producer targets 10 rows per second and stops after the timed wait. The
+consumer drains the topic, prints its plan, and stops. Use a dedicated topic
+without other producers so draining can finish. Console output includes each
+record's topic, partition, offset, and value; the exact row count can vary.
+
+Each run creates fresh local checkpoints and rereads existing topic records.
+For deployment, use persistent checkpoint locations accessible to the cluster
+and reuse them on restart; recovered offsets take precedence over
`startingOffsets`.
+
+## Verify Gluten offloading
+
+Check that the bundle contains the JVM Kafka integration:
+
+```bash
+jar tf "$GLUTEN_JAR" | grep -E \
+ 'OffloadKafkaScan|MicroBatchScanExecTransformer|VeloxKafkaComponent'
+```
+
+Expect the `OffloadKafkaScan`, `MicroBatchScanExecTransformer`, and
+`VeloxKafkaComponent` classes, plus the component registration resource
+`META-INF/gluten-components/org.apache.gluten.component.VeloxKafkaComponent`.
+Then verify native execution using the streaming plan.
+
+The example calls `consumer.explain(true)` after processing records. Inspect
+that output or the executed streaming plan in Spark UI for
+**`MicroBatchScanExecTransformer`** on the Kafka source. This is the Gluten
scan
+node; console output alone does not confirm native Kafka execution.
+
+If the Kafka scan remains on Spark, check the Gluten bundle, native library,
+Kafka offload integration, and requested columns. Native operators elsewhere
+in the plan do not prove that the Kafka scan was offloaded.
+
+## Troubleshooting
+
+| Symptom | Check |
+| --- | --- |
+| Kafka data source missing | Supply the matching `spark-sql-kafka-0-10`
runtime package. |
+| Kafka scan stays in Spark | Confirm `GlutenPlugin` is loaded, both Kafka
build options are enabled, the bundle contains the Kafka classes and component
resource listed above, and `spark.gluten.sql.columnar.kafkaScan` is `true`. |
+| Unsupported native schema | Use the supported Kafka columns listed above;
requesting `headers` falls back to Spark. |
+| Native read times out | Check broker reachability, authentication
compatibility, offset availability, and `kafkaConsumer.pollTimeoutMs`. |
+
+Set the source option `.option("kafkaConsumer.pollTimeoutMs", "120000")` to
allow
+up to 120 seconds for executor polling. When omitted, Spark derives this
timeout
+from `spark.network.timeout`, which defaults to 120 seconds. The native reader
+bounds record-consumption waits by the remaining poll timeout; metadata and
+recovery operations have separate timeout allowances. This is not a whole-query
+deadline.
+
+The source option `failOnDataLoss` defaults to `true`, so unavailable offsets
+cause the query to fail. Setting `.option("failOnDataLoss", "false")` allows
the
+native reader to skip unavailable offsets and read the remaining records.
Missing
+data is not recovered.
+
+See Spark's [Kafka integration
guide](https://spark.apache.org/docs/3.5.6/structured-streaming-kafka-integration.html)
+for full source options. Native consumers default to `read_uncommitted` unless
+`kafka.isolation.level` is supplied.
diff --git a/docs/get-started/build-guide.md b/docs/get-started/build-guide.md
index 5f1809628c..57459c1a9a 100644
--- a/docs/get-started/build-guide.md
+++ b/docs/get-started/build-guide.md
@@ -19,7 +19,7 @@ Please set them via `--`, e.g. `--build_type=Release`.
| enable_gcs | Build with GCS support.
| OFF |
| enable_hdfs | Build with HDFS support.
| OFF |
| enable_abfs | Build with ABFS support.
| OFF |
-| enable_kafka | Build with Kafka streaming read support.
Automatically installs librdkafka. | OFF |
+| enable_kafka | Build with native Kafka support and install
librdkafka. See [Kafka support](../backends/velox/get-started/VeloxKafka.md)
for JVM setup. | OFF |
| enable_vcpkg | Enable vcpkg for static build.
| OFF |
| run_setup_script | Run setup script to install Velox dependencies.
| ON |
| velox_repo | Specify your own Velox repo to build.
| "" |
@@ -66,6 +66,7 @@ The below parameters can be set via `-P` for mvn.
| delta | Build Gluten with Delta Lake support. | disabled |
| iceberg | Build Gluten with Iceberg support. | disabled |
| hudi | Build Gluten with Hudi support. | disabled |
+| kafka | Build JVM Kafka integration. See [Kafka
support](../backends/velox/get-started/VeloxKafka.md) for Velox prerequisites.
| disabled |
| spark-3.4 | Build Gluten for Spark 3.4. | disabled |
| spark-3.5 | Build Gluten for Spark 3.5. | enabled |
| spark-4.0 | Build Gluten for Spark 4.0. Requires JDK 17+ and Scala
2.13. | disabled |
diff --git a/docs/image/velox-kafka-read.svg b/docs/image/velox-kafka-read.svg
new file mode 100644
index 0000000000..4b888b81c7
--- /dev/null
+++ b/docs/image/velox-kafka-read.svg
@@ -0,0 +1,63 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="840" height="575" viewBox="0 0
840 575" role="img" aria-labelledby="title description">
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+ <title id="title">Kafka reads with Gluten and Velox</title>
+ <desc id="description">The Spark driver plans micro-batches and tracks
offsets and checkpoints. Gluten converts eligible Kafka scans into native
plans. One Spark executor is shown. Its Gluten task calls the Velox Kafka
reader through JNI within the same process. The native reader uses librdkafka
to read records directly from Kafka and returns columnar batches to the task.
Spark can distribute tasks across multiple executors.</desc>
+ <defs>
+ <marker id="control-arrow" markerWidth="10" markerHeight="10" refX="9"
refY="5" orient="auto">
+ <path d="M 0 1 L 9 5 L 0 9 Z" fill="#52657a"/>
+ </marker>
+ <marker id="data-arrow" markerWidth="10" markerHeight="10" refX="9"
refY="5" orient="auto">
+ <path d="M 0 1 L 9 5 L 0 9 Z" fill="#197567"/>
+ </marker>
+ </defs>
+ <rect width="840" height="575" rx="14" fill="#ffffff"/>
+ <g font-family="Arial, Helvetica, sans-serif" fill="#172b4d">
+ <text x="30" y="39" font-size="26" font-weight="700">Kafka reads with
Gluten and Velox</text>
+
+ <rect x="30" y="80" width="270" height="130" rx="12" fill="#eef4ff"
stroke="#5377a3" stroke-width="2"/>
+ <text x="165" y="115" text-anchor="middle" font-size="22"
font-weight="700">Spark driver + Gluten</text>
+ <text x="165" y="151" text-anchor="middle" font-size="17">Plans
micro-batches</text>
+ <text x="165" y="181" text-anchor="middle" font-size="17">Tracks offsets
and checkpoints</text>
+
+ <rect x="435" y="80" width="375" height="430" rx="12" fill="#f6f8fc"
stroke="#5377a3" stroke-width="2"/>
+ <text x="622" y="115" text-anchor="middle" font-size="22"
font-weight="700">Spark executor ยท JVM process</text>
+ <rect x="460" y="155" width="325" height="80" rx="8" fill="#eef4ff"
stroke="#8ba5c5"/>
+ <text x="622" y="188" text-anchor="middle" font-size="21"
font-weight="700">Gluten columnar task</text>
+ <text x="622" y="215" text-anchor="middle" font-size="17">Downstream
processing</text>
+ <path d="M 300 170 H 458" fill="none" stroke="#52657a" stroke-width="2"
stroke-dasharray="6 5" marker-end="url(#control-arrow)"/>
+ <text x="367" y="152" text-anchor="middle" font-size="16">Plan +
offsets</text>
+
+ <path d="M 550 235 V 373" fill="none" stroke="#52657a" stroke-width="2"
stroke-dasharray="6 5" marker-end="url(#control-arrow)"/>
+ <text x="535" y="310" text-anchor="end" font-size="16">JNI call</text>
+ <path d="M 700 375 V 237" fill="none" stroke="#197567" stroke-width="2.5"
marker-end="url(#data-arrow)"/>
+ <text x="715" y="298" font-size="16">Columnar</text>
+ <text x="715" y="320" font-size="16">batches</text>
+ <rect x="460" y="375" width="325" height="100" rx="9" fill="#edf8f3"
stroke="#37806a" stroke-width="2"/>
+ <text x="622" y="409" text-anchor="middle" font-size="21"
font-weight="700">Velox Kafka reader</text>
+ <text x="622" y="436" text-anchor="middle" font-size="17">librdkafka</text>
+ <text x="622" y="459" text-anchor="middle" font-size="15">Native C++ in
this executor</text>
+
+ <rect x="30" y="385" width="270" height="100" rx="12" fill="#fff5e8"
stroke="#a87936" stroke-width="2"/>
+ <text x="165" y="424" text-anchor="middle" font-size="22"
font-weight="700">Kafka brokers</text>
+ <text x="165" y="455" text-anchor="middle" font-size="17">Topic
partitions</text>
+ <path d="M 300 435 H 458" fill="none" stroke="#197567" stroke-width="2.5"
marker-end="url(#data-arrow)"/>
+ <text x="367" y="418" text-anchor="middle" font-size="16"
fill="#176356">Records</text>
+
+ <text x="420" y="550" text-anchor="middle" font-size="15">One executor
shown; Spark can distribute tasks across multiple executors.</text>
+ </g>
+</svg>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]