You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ericm-db (via GitHub)" <gi...@apache.org> on 2025/12/03 19:11:39 UTC
[PR] [SPARK-54583] Add SQLConf to enable use of OffsetMap [spark]
ericm-db opened a new pull request, #53311:
URL: https://github.com/apache/spark/pull/53311
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Add the SQLConf that allows us to use the OffsetMap format instead of OffsetSeq.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
We need to allow users to set the offset log format version which will enable features like source naming in the future.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
#### What changes?
This PR adds a new public configuration `spark.sql.streaming.offsetLog.formatVersion` that allows users to control the offset log format version
used in streaming query checkpoints.
#### Previous behavior:
Streaming queries could only use VERSION_1 offset log format (OffsetSeq), which stores offsets as an ordered sequence. Although VERSION_2 format
(OffsetMap) was implemented internally, there was no way for users to enable it.
#### New behavior:
Users can now set `spark.sql.streaming.offsetLog.formatVersion` to choose between two offset log formats:
- **Version 1 (default)**: Uses sequence-based OffsetSeq format (existing behavior)
- **Version 2**: Uses map-based OffsetMap format with string-based source IDs ("0", "1", "2", etc.)
#### Example:
```scala
// Create a new streaming query with VERSION_2 format
spark.conf.set("spark.sql.streaming.offsetLog.formatVersion", "2")
val query = spark.readStream
.format("rate")
.load()
.writeStream
.format("parquet")
.option("checkpointLocation", "/path/to/checkpoint")
.start()
The checkpoint will use OffsetMap format with source IDs as map keys instead of relying on source ordering.
Important notes:
- Default behavior unchanged: The configuration defaults to 1, so existing queries are unaffected
- New queries only: This config only affects new streaming queries; existing queries continue using the format from their checkpoint
- No migration path: Checkpoints cannot be migrated between versions; changing the config requires starting a fresh query
Comparison:
This is a user-facing change compared to released Spark versions as it introduces a new public configuration that was not previously available.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
Unit tests
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54583][SS] Add SQLConf to enable use of OffsetMap [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #53311:
URL: https://github.com/apache/spark/pull/53311#discussion_r2590126010
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/OffsetSeq.scala:
##########
@@ -169,7 +169,7 @@ object OffsetSeqMetadata extends Logging {
STREAMING_JOIN_STATE_FORMAT_VERSION, STATE_STORE_COMPRESSION_CODEC,
STATE_STORE_ROCKSDB_FORMAT_VERSION, STATEFUL_OPERATOR_USE_STRICT_DISTRIBUTION,
PRUNE_FILTERS_CAN_PRUNE_STREAMING_SUBPLAN, STREAMING_STATE_STORE_ENCODING_FORMAT,
- STATE_STORE_ROW_CHECKSUM_ENABLED
+ STATE_STORE_ROW_CHECKSUM_ENABLED, STREAMING_OFFSET_LOG_FORMAT_VERSION
Review Comment:
removed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54583][SS] Add SQLConf to enable use of OffsetMap [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #53311:
URL: https://github.com/apache/spark/pull/53311#discussion_r2590469285
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/OffsetSeq.scala:
##########
@@ -244,7 +244,8 @@ object OffsetSeqMetadata extends Logging {
case (confInSession, confInOffsetLog) =>
confInOffsetLog.key -> sessionConf.get(confInSession.key)
}.toMap
- OffsetSeqMetadata(batchWatermarkMs, batchTimestampMs, confs++ confsFromRebind)
+ val version = sessionConf.get(STREAMING_OFFSET_LOG_FORMAT_VERSION.key).toInt
Review Comment:
OffsetSeqBase - we don't have multiple metadata versions here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54583][SS] Add SQLConf to enable use of OffsetMap [spark]
Posted by "dylanwong250 (via GitHub)" <gi...@apache.org>.
dylanwong250 commented on code in PR #53311:
URL: https://github.com/apache/spark/pull/53311#discussion_r2590418087
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/OffsetSeqLogSuite.scala:
##########
@@ -237,4 +237,147 @@ class OffsetSeqLogSuite extends SharedSparkSession {
assert(metadata.batchWatermarkMs === 0)
assert(metadata.batchTimestampMs === 1758651405232L)
}
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - new query with VERSION_2") {
+ import testImplicits._
+ withTempDir { checkpointDir =>
+ withSQLConf(SQLConf.STREAMING_OFFSET_LOG_FORMAT_VERSION.key -> "2") {
+ val inputData = MemoryStream[Int]
+ val query = inputData.toDF()
+ .writeStream
+ .format("memory")
+ .queryName("offsetlog_v2_test")
+ .option("checkpointLocation", checkpointDir.getAbsolutePath)
+ .start()
+
+ try {
+ // Add data and process batches
+ inputData.addData(1, 2, 3)
+ query.processAllAvailable()
+ inputData.addData(4, 5)
+ query.processAllAvailable()
+
+ // Read the offset log from checkpoint
+ val offsetLog = new OffsetSeqLog(spark, s"${checkpointDir.getAbsolutePath}/offsets")
+ val latestBatch = offsetLog.getLatest()
+ assert(latestBatch.isDefined, "Offset log should have at least one entry")
+
+ val (batchId, offsetSeq) = latestBatch.get
+
+ // Verify it's OffsetMap (VERSION_2)
+ assert(offsetSeq.isInstanceOf[OffsetMap],
+ s"Expected OffsetMap but got ${offsetSeq.getClass.getSimpleName}")
+
+ // Verify metadata version is 2
+ assert(offsetSeq.metadataOpt.isDefined)
+ val metadata = offsetSeq.metadataOpt.get
+ assert(metadata.version === 2, s"Expected version 2 but got ${metadata.version}")
+
+ // Verify OffsetMap uses string keys ("0", "1", etc.)
+ val offsetMap = offsetSeq.asInstanceOf[OffsetMap]
+ assert(offsetMap.offsetsMap.keys.forall(_.forall(_.isDigit)),
+ "OffsetMap keys should be string representations of ordinals (e.g., '0', '1')")
+ } finally {
+ query.stop()
+ }
+ }
+ }
+ }
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - default VERSION_1") {
+ import testImplicits._
+ withTempDir { checkpointDir =>
+ // Don't set the config, should default to VERSION_1
+ val inputData = MemoryStream[Int]
+ val query = inputData.toDF()
+ .writeStream
+ .format("memory")
+ .queryName("offsetlog_v1_test")
+ .option("checkpointLocation", checkpointDir.getAbsolutePath)
+ .start()
+
+ try {
+ // Add data and process batches
+ inputData.addData(1, 2, 3)
+ query.processAllAvailable()
+
+ // Read the offset log from checkpoint
+ val offsetLog = new OffsetSeqLog(spark, s"${checkpointDir.getAbsolutePath}/offsets")
+ val latestBatch = offsetLog.getLatest()
+ assert(latestBatch.isDefined, "Offset log should have at least one entry")
+
+ val (batchId, offsetSeq) = latestBatch.get
+
+ // Verify it's OffsetSeq (VERSION_1)
+ assert(offsetSeq.isInstanceOf[OffsetSeq],
+ s"Expected OffsetSeq but got ${offsetSeq.getClass.getSimpleName}")
+
+ // Verify metadata version is 1
+ assert(offsetSeq.metadataOpt.isDefined)
+ val metadata = offsetSeq.metadataOpt.get
+ assert(metadata.version === 1, s"Expected version 1 but got ${metadata.version}")
+ } finally {
+ query.stop()
+ }
+ }
+ }
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - checkpoint wins on restart") {
Review Comment:
should we also test the inverse? Start with v2 and ensure it remains v2 ?
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/OffsetSeqLogSuite.scala:
##########
@@ -237,4 +237,147 @@ class OffsetSeqLogSuite extends SharedSparkSession {
assert(metadata.batchWatermarkMs === 0)
assert(metadata.batchTimestampMs === 1758651405232L)
}
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - new query with VERSION_2") {
+ import testImplicits._
+ withTempDir { checkpointDir =>
+ withSQLConf(SQLConf.STREAMING_OFFSET_LOG_FORMAT_VERSION.key -> "2") {
+ val inputData = MemoryStream[Int]
+ val query = inputData.toDF()
+ .writeStream
+ .format("memory")
+ .queryName("offsetlog_v2_test")
+ .option("checkpointLocation", checkpointDir.getAbsolutePath)
+ .start()
+
+ try {
+ // Add data and process batches
+ inputData.addData(1, 2, 3)
+ query.processAllAvailable()
+ inputData.addData(4, 5)
+ query.processAllAvailable()
+
+ // Read the offset log from checkpoint
+ val offsetLog = new OffsetSeqLog(spark, s"${checkpointDir.getAbsolutePath}/offsets")
+ val latestBatch = offsetLog.getLatest()
+ assert(latestBatch.isDefined, "Offset log should have at least one entry")
+
+ val (batchId, offsetSeq) = latestBatch.get
+
+ // Verify it's OffsetMap (VERSION_2)
+ assert(offsetSeq.isInstanceOf[OffsetMap],
+ s"Expected OffsetMap but got ${offsetSeq.getClass.getSimpleName}")
+
+ // Verify metadata version is 2
+ assert(offsetSeq.metadataOpt.isDefined)
+ val metadata = offsetSeq.metadataOpt.get
+ assert(metadata.version === 2, s"Expected version 2 but got ${metadata.version}")
+
+ // Verify OffsetMap uses string keys ("0", "1", etc.)
+ val offsetMap = offsetSeq.asInstanceOf[OffsetMap]
+ assert(offsetMap.offsetsMap.keys.forall(_.forall(_.isDigit)),
Review Comment:
Is it worth checking the specific defaults are correct?
I guess in this case it would be just "0"
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/OffsetSeq.scala:
##########
@@ -244,7 +244,8 @@ object OffsetSeqMetadata extends Logging {
case (confInSession, confInOffsetLog) =>
confInOffsetLog.key -> sessionConf.get(confInSession.key)
}.toMap
- OffsetSeqMetadata(batchWatermarkMs, batchTimestampMs, confs++ confsFromRebind)
+ val version = sessionConf.get(STREAMING_OFFSET_LOG_FORMAT_VERSION.key).toInt
Review Comment:
Does the version here refer to the OffsetSeqMetadata version or the OffsetSeqBase version?
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/OffsetSeqLogSuite.scala:
##########
@@ -237,4 +237,147 @@ class OffsetSeqLogSuite extends SharedSparkSession {
assert(metadata.batchWatermarkMs === 0)
assert(metadata.batchTimestampMs === 1758651405232L)
}
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - new query with VERSION_2") {
Review Comment:
I think it would be good to add a test with multiple sources and verify the OffsetMap
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/OffsetSeqLogSuite.scala:
##########
@@ -237,4 +237,147 @@ class OffsetSeqLogSuite extends SharedSparkSession {
assert(metadata.batchWatermarkMs === 0)
assert(metadata.batchTimestampMs === 1758651405232L)
}
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - new query with VERSION_2") {
+ import testImplicits._
+ withTempDir { checkpointDir =>
+ withSQLConf(SQLConf.STREAMING_OFFSET_LOG_FORMAT_VERSION.key -> "2") {
+ val inputData = MemoryStream[Int]
+ val query = inputData.toDF()
+ .writeStream
+ .format("memory")
+ .queryName("offsetlog_v2_test")
+ .option("checkpointLocation", checkpointDir.getAbsolutePath)
+ .start()
+
+ try {
+ // Add data and process batches
+ inputData.addData(1, 2, 3)
+ query.processAllAvailable()
+ inputData.addData(4, 5)
+ query.processAllAvailable()
+
+ // Read the offset log from checkpoint
+ val offsetLog = new OffsetSeqLog(spark, s"${checkpointDir.getAbsolutePath}/offsets")
+ val latestBatch = offsetLog.getLatest()
+ assert(latestBatch.isDefined, "Offset log should have at least one entry")
+
+ val (batchId, offsetSeq) = latestBatch.get
+
+ // Verify it's OffsetMap (VERSION_2)
+ assert(offsetSeq.isInstanceOf[OffsetMap],
+ s"Expected OffsetMap but got ${offsetSeq.getClass.getSimpleName}")
+
+ // Verify metadata version is 2
+ assert(offsetSeq.metadataOpt.isDefined)
+ val metadata = offsetSeq.metadataOpt.get
+ assert(metadata.version === 2, s"Expected version 2 but got ${metadata.version}")
+
+ // Verify OffsetMap uses string keys ("0", "1", etc.)
+ val offsetMap = offsetSeq.asInstanceOf[OffsetMap]
+ assert(offsetMap.offsetsMap.keys.forall(_.forall(_.isDigit)),
+ "OffsetMap keys should be string representations of ordinals (e.g., '0', '1')")
+ } finally {
+ query.stop()
+ }
+ }
+ }
+ }
+
+ test("STREAMING_OFFSET_LOG_FORMAT_VERSION config - default VERSION_1") {
+ import testImplicits._
Review Comment:
could the `import testImplicits._` be at the test class level so it does not need to be duplicated for the tests?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54583][SS] Add SQLConf to enable use of OffsetMap [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db closed pull request #53311: [SPARK-54583][SS] Add SQLConf to enable use of OffsetMap
URL: https://github.com/apache/spark/pull/53311
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54583][SS] Add SQLConf to enable use of OffsetMap [spark]
Posted by "dylanwong250 (via GitHub)" <gi...@apache.org>.
dylanwong250 commented on code in PR #53311:
URL: https://github.com/apache/spark/pull/53311#discussion_r2586523573
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/OffsetSeq.scala:
##########
@@ -169,7 +169,7 @@ object OffsetSeqMetadata extends Logging {
STREAMING_JOIN_STATE_FORMAT_VERSION, STATE_STORE_COMPRESSION_CODEC,
STATE_STORE_ROCKSDB_FORMAT_VERSION, STATEFUL_OPERATOR_USE_STRICT_DISTRIBUTION,
PRUNE_FILTERS_CAN_PRUNE_STREAMING_SUBPLAN, STREAMING_STATE_STORE_ENCODING_FORMAT,
- STATE_STORE_ROW_CHECKSUM_ENABLED
+ STATE_STORE_ROW_CHECKSUM_ENABLED, STREAMING_OFFSET_LOG_FORMAT_VERSION
Review Comment:
This should not be needed since we use the version directly in the offset log.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org