You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "HeartSaVioR (via GitHub)" <gi...@apache.org> on 2026/04/08 21:23:16 UTC
[PR] [SPARK-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
HeartSaVioR opened a new pull request, #55265:
URL: https://github.com/apache/spark/pull/55265
### What changes were proposed in this pull request?
This PR proposes to apply rangeScan API in transformWithState Timer/TTL, which will give an improvement of scanning on expired timers and entries with configured TTL.
The main idea is to perform scanning of expired timers and TTL entries from [the end timestamp of previous scan + 1, new end timestamp], which was [None, new end timestamp]. Previously it had to go through tombstones prior batches made in prior evictions (till compaction happens), and with this change we will be able to skip those tombstones.
### Why are the changes needed?
This change will give a hit to RocksDB about the exact range to scan, reducing the chance of reading tombstone a lot.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
New UTs, and existing UTs.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude 4.6 Opus
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4275481062
It's unfortunate that null field is flipped as a binary order in UnsafeRow so we are doing a heavy lifting work. Also technically we should just ask the caller to fill out the range part of the data on calling rangeScan, not to fill out all keys. Arguably if we are very clear about the intention of the scan e.g. timestamp in API, we really don't need to do the heavy work like this.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3106357496
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/TransformWithStateExec.scala:
##########
@@ -260,7 +261,13 @@ case class TransformWithStateExec(
case EventTime =>
assert(eventTimeWatermarkForEviction.isDefined)
val watermark = eventTimeWatermarkForEviction.get
- processorHandle.getExpiredTimers(watermark)
+ // Only use the late-events watermark as the scan lower bound when a previous batch
+ // actually existed (prevBatchTimestampMs is set). In the very first batch the
+ // watermark propagation yields Some(0) for late events even though no timers have
+ // been processed yet, which would incorrectly skip timers registered at timestamp 0.
+ val prevWatermark =
+ if (prevBatchTimestampMs.isDefined) eventTimeWatermarkForLateEvents else None
Review Comment:
You spotted on.
This has some subtle bug - this does not work with legacy config (`spark.sql.streaming.statefulOperator.allowMultiple=true`). I think there is few users leveraging this config and we would probably want to kick the config out (we no longer need such a kill switch - this was introduced long time ago), so probably we can skip optimization for the legacy path, and remove the config sooner.
I indicated https://github.com/apache/spark/pull/55267 has the same issue, so I'm going to fix that PR as well.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3105564676
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/timers/TimerStateImpl.scala:
##########
@@ -112,6 +112,27 @@ class TimerStateImpl(
schemaForValueRow, RangeKeyScanStateEncoderSpec(keySchemaForSecIndex, Seq(0)),
useMultipleValuesPerKey = false, isInternal = true)
+ private val secIndexProjection = UnsafeProjection.create(keySchemaForSecIndex)
+
+ /**
+ * Encodes a timestamp into an UnsafeRow key for the secondary index.
+ * The timestamp is incremented by 1 so that the encoded key serves as an exclusive
+ * lower / upper bound in range scans. Returns None if tsMs is Long.MaxValue
+ * (overflow guard).
+ *
+ * The returned UnsafeRow is always a fresh copy, safe to hold alongside other
+ * rows produced by the same projection.
+ */
+ private def encodeTimestampAsKey(tsMs: Long): Option[UnsafeRow] = {
+ if (tsMs < Long.MaxValue) {
+ val row = new GenericInternalRow(keySchemaForSecIndex.length)
+ row.setLong(0, tsMs + 1)
Review Comment:
Is it always valid to only fill the first field of keySchemaForSecIndex?
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4275384223
https://github.com/apache/spark/pull/55265/commits/0c5e948b7f2da0950e616bf6a5cb23e85ace1355
The code change is a big large - @viirya would you mind having another look and re-approve if the code change looks OK to you for your review comments? Thanks in advance!
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3106427579
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RangeScanBoundaryUtils.scala:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.execution.streaming.state
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Literal, UnsafeProjection, UnsafeRow}
+import org.apache.spark.sql.types.StructType
+
+/**
+ * Utilities for building boundary rows used as start / end keys in state store
+ * range scans.
+ *
+ * Callers of [[StateStore.rangeScan]] / [[StateStore.rangeScanWithMultiValues]]
+ * must provide fully-typed `UnsafeRow` boundaries matching the column family's key
+ * schema, even when they only care about the ordering column (e.g. timestamp).
+ * The non-ordering columns must encode byte-wise no larger than any real entry at
+ * the same ordering prefix, or `seek()` will silently skip matching entries.
+ *
+ * The helpers here fill non-ordering columns with `Literal.default` (recursive
+ * zero / empty / false). In UnsafeRow, that encodes as the byte-wise smallest
+ * representation for all standard Dataset/SQL-encoded types -- numerics (including
+ * negatives, whose non-zero two's-complement bytes still sort greater than
+ * all-zero), and variable-length types (size=0 beats any non-zero size).
+ *
+ * Caveats where the "smallest" property does NOT hold and which therefore should
+ * not appear in caller key schemas:
+ * - `CharType(n)`: default is space-padded (0x20), but real values may legally
+ * contain control bytes (0x00..0x1F).
+ * - `VariantType`: the Variant binary layout is not guaranteed minimized by
+ * `castToVariant(0, IntegerType)`.
Review Comment:
If key schema includes these types, should we have some runtime detection?
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3106354340
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/timers/TimerStateImpl.scala:
##########
@@ -112,6 +112,27 @@ class TimerStateImpl(
schemaForValueRow, RangeKeyScanStateEncoderSpec(keySchemaForSecIndex, Seq(0)),
useMultipleValuesPerKey = false, isInternal = true)
+ private val secIndexProjection = UnsafeProjection.create(keySchemaForSecIndex)
+
+ /**
+ * Encodes a timestamp into an UnsafeRow key for the secondary index.
+ * The timestamp is incremented by 1 so that the encoded key serves as an exclusive
+ * lower / upper bound in range scans. Returns None if tsMs is Long.MaxValue
+ * (overflow guard).
+ *
+ * The returned UnsafeRow is always a fresh copy, safe to hold alongside other
+ * rows produced by the same projection.
+ */
+ private def encodeTimestampAsKey(tsMs: Long): Option[UnsafeRow] = {
+ if (tsMs < Long.MaxValue) {
+ val row = new GenericInternalRow(keySchemaForSecIndex.length)
+ row.setLong(0, tsMs + 1)
Review Comment:
Unfortunately no - null is "greater" than non-null in UnsafeRow format. I'm going to apply the same approach with https://github.com/apache/spark/pull/55267 via using defaults on Literal.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3105575684
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/TransformWithStateExec.scala:
##########
@@ -260,7 +261,13 @@ case class TransformWithStateExec(
case EventTime =>
assert(eventTimeWatermarkForEviction.isDefined)
val watermark = eventTimeWatermarkForEviction.get
- processorHandle.getExpiredTimers(watermark)
+ // Only use the late-events watermark as the scan lower bound when a previous batch
+ // actually existed (prevBatchTimestampMs is set). In the very first batch the
+ // watermark propagation yields Some(0) for late events even though no timers have
+ // been processed yet, which would incorrectly skip timers registered at timestamp 0.
+ val prevWatermark =
+ if (prevBatchTimestampMs.isDefined) eventTimeWatermarkForLateEvents else None
Review Comment:
So if `prevBatchTimestampMs` is defined, the value of `eventTimeWatermarkForLateEvents` is always valid to use?
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR closed pull request #55265: [SPARK-56400][SS] Apply rangeScan API in transformWithState Timer/TTL
URL: https://github.com/apache/spark/pull/55265
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4273742824
@anishshri-db @viirya PTAL, thanks!
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "bogao007 (via GitHub)" <gi...@apache.org>.
bogao007 commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3061313436
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/ttl/TTLState.scala:
##########
@@ -161,10 +168,25 @@ trait TTLState {
//
// The schema of the UnsafeRow returned by this iterator is (expirationMs, elementKey).
private[sql] def ttlEvictionIterator(): Iterator[UnsafeRow] = {
- val ttlIterator = store.iterator(TTL_INDEX)
+ val dummyElementKey = ELEMENT_KEY_PROJECTION
+ .apply(new GenericInternalRow(elementKeySchema.length))
+ val startKey = prevBatchTimestampMs.flatMap { prevTs =>
+ if (prevTs < Long.MaxValue) {
+ Some(TTL_ENCODER.encodeTTLRow(prevTs + 1, dummyElementKey).copy())
+ } else {
+ None
+ }
+ }
+ val endKey = if (batchTimestampMs < Long.MaxValue) {
+ Some(TTL_ENCODER.encodeTTLRow(batchTimestampMs + 1, dummyElementKey).copy())
+ } else {
+ None
+ }
+ val ttlIterator = store.rangeScan(startKey, endKey, TTL_INDEX)
Review Comment:
Should we update the method comment indicating that we are using range scan now?
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/ttl/TTLState.scala:
##########
@@ -161,10 +168,25 @@ trait TTLState {
//
// The schema of the UnsafeRow returned by this iterator is (expirationMs, elementKey).
private[sql] def ttlEvictionIterator(): Iterator[UnsafeRow] = {
- val ttlIterator = store.iterator(TTL_INDEX)
+ val dummyElementKey = ELEMENT_KEY_PROJECTION
Review Comment:
Is the `dummyElementKey` here just for using `TTL_ENCODER.encodeTTLRow` requires an elementKey?
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4276832451
Thanks! Merging to master.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4209760432
Only the last commit is related to this PR. Once https://github.com/apache/spark/pull/55226 is merged, I'll rebase.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3061805408
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/transformwithstate/ttl/TTLState.scala:
##########
@@ -161,10 +168,25 @@ trait TTLState {
//
// The schema of the UnsafeRow returned by this iterator is (expirationMs, elementKey).
private[sql] def ttlEvictionIterator(): Iterator[UnsafeRow] = {
- val ttlIterator = store.iterator(TTL_INDEX)
+ val dummyElementKey = ELEMENT_KEY_PROJECTION
Review Comment:
Yes, correct.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4276827982
https://github.com/HeartSaVioR/spark/actions/runs/24624331383/job/72002194205
CI only fails on k8s integratino test and sparkr which are irrelevant.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3106442464
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RangeScanBoundaryUtils.scala:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.execution.streaming.state
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Literal, UnsafeProjection, UnsafeRow}
+import org.apache.spark.sql.types.StructType
+
+/**
+ * Utilities for building boundary rows used as start / end keys in state store
+ * range scans.
+ *
+ * Callers of [[StateStore.rangeScan]] / [[StateStore.rangeScanWithMultiValues]]
+ * must provide fully-typed `UnsafeRow` boundaries matching the column family's key
+ * schema, even when they only care about the ordering column (e.g. timestamp).
+ * The non-ordering columns must encode byte-wise no larger than any real entry at
+ * the same ordering prefix, or `seek()` will silently skip matching entries.
+ *
+ * The helpers here fill non-ordering columns with `Literal.default` (recursive
+ * zero / empty / false). In UnsafeRow, that encodes as the byte-wise smallest
+ * representation for all standard Dataset/SQL-encoded types -- numerics (including
+ * negatives, whose non-zero two's-complement bytes still sort greater than
+ * all-zero), and variable-length types (size=0 beats any non-zero size).
+ *
+ * Caveats where the "smallest" property does NOT hold and which therefore should
+ * not appear in caller key schemas:
+ * - `CharType(n)`: default is space-padded (0x20), but real values may legally
+ * contain control bytes (0x00..0x1F).
+ * - `VariantType`: the Variant binary layout is not guaranteed minimized by
+ * `castToVariant(0, IntegerType)`.
Review Comment:
Let's do that - I guess it's unlikely to hit but better to be safer.
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #55265:
URL: https://github.com/apache/spark/pull/55265#discussion_r3106476110
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RangeScanBoundaryUtils.scala:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.execution.streaming.state
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Literal, UnsafeProjection, UnsafeRow}
+import org.apache.spark.sql.types.StructType
+
+/**
+ * Utilities for building boundary rows used as start / end keys in state store
+ * range scans.
+ *
+ * Callers of [[StateStore.rangeScan]] / [[StateStore.rangeScanWithMultiValues]]
+ * must provide fully-typed `UnsafeRow` boundaries matching the column family's key
+ * schema, even when they only care about the ordering column (e.g. timestamp).
+ * The non-ordering columns must encode byte-wise no larger than any real entry at
+ * the same ordering prefix, or `seek()` will silently skip matching entries.
+ *
+ * The helpers here fill non-ordering columns with `Literal.default` (recursive
+ * zero / empty / false). In UnsafeRow, that encodes as the byte-wise smallest
+ * representation for all standard Dataset/SQL-encoded types -- numerics (including
+ * negatives, whose non-zero two's-complement bytes still sort greater than
+ * all-zero), and variable-length types (size=0 beats any non-zero size).
+ *
+ * Caveats where the "smallest" property does NOT hold and which therefore should
+ * not appear in caller key schemas:
+ * - `CharType(n)`: default is space-padded (0x20), but real values may legally
+ * contain control bytes (0x00..0x1F).
+ * - `VariantType`: the Variant binary layout is not guaranteed minimized by
+ * `castToVariant(0, IntegerType)`.
Review Comment:
https://github.com/apache/spark/pull/55265/commits/291553bb2aa304c78cce627fa8b013d3b70020dc
I've taken a bit more work - we have a consistent binary lowest value for CharType, so we can actually address it without rejection. We can still reject VariantType since it's not practical for VariantType to be used in grouping key anyway.
The same change is applied to the PR here - https://github.com/apache/spark/pull/55267
--
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-56400][SS] Apply rangeScan API in transformWithState Timer/TTL [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #55265:
URL: https://github.com/apache/spark/pull/55265#issuecomment-4256690240
cc. @viirya
--
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