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/04/22 21:54:10 UTC
[PR] [WIP] Creating user error classification for TransformWithState [spark]
ericm-db opened a new pull request, #50667:
URL: https://github.com/apache/spark/pull/50667
<!--
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.
-->
### 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.
-->
### 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'.
-->
### 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.
-->
### 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.
-->
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055293705
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -5233,6 +5233,12 @@
],
"sqlState" : "XXKST"
},
+ "TRANSFORM_WITH_STATE_USER_FUNCTION_ERROR" : {
+ "message" : [
+ "An error occurred in the handleInputRows function of the StatefulProcessor. Function: <function>. Reason: <reason>"
Review Comment:
nit: `An error occurred in the stateful processor user-defined function`
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055296936
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +260,62 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
Review Comment:
Do we need to cover `init` too ? also - will this cover all the paths on the driver 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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055304307
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +260,62 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
Review Comment:
Yeah I think I need to do this for all invocations of init
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055092572
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -5221,6 +5221,12 @@
],
"sqlState" : "XXKST"
},
+ "TRANSFORM_WITH_STATE_USER_FUNCTION_ERROR" : {
+ "message" : [
+ "An error occurred in the handleInputRows function of the StatefulProcessor. Reason: <reason>"
Review Comment:
lets pass the function name as an arg 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-51869][SS] Create classification for user errors within UDFs for Scala TransformWithState [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2062734749
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +262,52 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
- }
- ImplicitGroupingKeyTracker.removeImplicitKey()
+ withStatefulProcessorErrorHandling("handleInputRows") {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
+ keyObj,
+ valueObjIter,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
+ getOutputRow(obj)
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
- iteratorWithImplicitKeySet(keyObj, mappedIterator)
+ iteratorWithImplicitKeySet(keyObj, mappedIterator)
+ }
}
private def processInitialStateRows(
keyRow: UnsafeRow,
initStateIter: Iterator[InternalRow]): Unit = {
- val getInitStateValueObj =
- ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
-
- initStateObjIter.foreach { initState =>
- // allow multiple initial state rows on the same grouping key for integration
- // with state data source reader with initial state
- statefulProcessor
- .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
- .handleInitialState(keyObj, initState,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ withStatefulProcessorErrorHandling("handleInitialState") {
+ val getInitStateValueObj =
Review Comment:
Same here
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -315,19 +322,21 @@ case class TransformWithStateExec(
keyObj: Any,
expiryTimestampMs: Long,
processorHandle: StatefulProcessorHandleImpl): Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleExpiredTimer(
- keyObj,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction),
- new ExpiredTimerInfoImpl(Some(expiryTimestampMs))).map { obj =>
- getOutputRow(obj)
- }
- ImplicitGroupingKeyTracker.removeImplicitKey()
+ withStatefulProcessorErrorHandling("handleExpiredTimer") {
Review Comment:
Same here
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +262,52 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
- }
- ImplicitGroupingKeyTracker.removeImplicitKey()
+ withStatefulProcessorErrorHandling("handleInputRows") {
Review Comment:
Do we have specific reason to wrap broader scope of code instead of strictly the scope of user function call?
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055306871
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateSuite.scala:
##########
@@ -2400,6 +2554,170 @@ class TransformWithStateValidationSuite extends StateStoreMetricsTest {
)
}
+ test("transformWithState - check that error within handleInputRows is classified") {
+ withSQLConf(
+ SQLConf.STATE_STORE_PROVIDER_CLASS.key -> classOf[RocksDBStateStoreProvider].getName,
+ SQLConf.SHUFFLE_PARTITIONS.key ->
+ TransformWithStateSuiteUtils.NUM_SHUFFLE_PARTITIONS.toString) {
+
+ val inputData = MemoryStream[String]
+ val result = inputData.toDS()
+ .groupByKey(x => x)
+ .transformWithState(new UnclassifiedErrorProcessor(),
+ TimeMode.None(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, "a"),
+ ExpectFailure[TransformWithStateUserFunctionException] { error =>
+ checkError(
+ error.asInstanceOf[SparkException],
+ condition = "TRANSFORM_WITH_STATE_USER_FUNCTION_ERROR",
+ parameters = Map("reason" ->
+ ("Cannot invoke \"org.apache.spark.sql.streaming.ValueState." +
+ "get()\" because \"null\" is null"))
Review Comment:
intentional ?
--
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-51869][SS] Create classification for user errors within UDFs for Scala TransformWithState [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #50667:
URL: https://github.com/apache/spark/pull/50667#issuecomment-2834021460
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055309375
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateSuite.scala:
##########
@@ -73,6 +73,119 @@ case class EvolvedState(
score: Double // Should default to 0.0
)
+class ClassifiedTimerErrorProcessor
+ extends StatefulProcessor[String, String, (String, BasicState)] {
+
+ @transient var state: ValueState[BasicState] = _
+
+ override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = {
+ state = getHandle.getValueState[BasicState](
+ "testState",
+ Encoders.product[BasicState],
+ TTLConfig.NONE)
+ }
+
+ override def handleInputRows(
+ key: String,
+ rows: Iterator[String],
+ timerValues: TimerValues): Iterator[(String, BasicState)] = {
+ getHandle.registerTimer(timerValues.getCurrentProcessingTimeInMs() + 1000)
+ Seq.empty.iterator
+ }
+
+ override def handleExpiredTimer(
+ key: String,
+ timerValues: TimerValues,
+ expiredTimerInfo: ExpiredTimerInfo): Iterator[(String, BasicState)] = {
+ throw StateStoreErrors.multipleColumnFamiliesNotSupported("dummy val")
+ }
+}
+
+class UnclassifiedTimerErrorProcessor
+ extends StatefulProcessor[String, String, (String, BasicState)] {
+
+ @transient var state: ValueState[BasicState] = _
+
+ override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = {
+ state = getHandle.getValueState[BasicState](
+ "testState",
+ Encoders.product[BasicState],
+ TTLConfig.NONE)
+ }
+
+ override def handleInputRows(
+ key: String,
+ rows: Iterator[String],
+ timerValues: TimerValues): Iterator[(String, BasicState)] = {
+ getHandle.registerTimer(timerValues.getCurrentProcessingTimeInMs() + 1000)
+ Seq.empty.iterator
+ }
+
+ override def handleExpiredTimer(
+ key: String,
+ timerValues: TimerValues,
+ expiredTimerInfo: ExpiredTimerInfo): Iterator[(String, BasicState)] = {
+ null.asInstanceOf[ValueState[BasicState]].get()
+ Seq.empty.iterator
+ }
+}
+
+
Review Comment:
nit: extra newline ?
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055003563
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,26 +260,33 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
Review Comment:
We need to do this for all functions on stateful processor right ?
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055297035
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +260,62 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
+ keyObj,
+ valueObjIter,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
+ getOutputRow(obj)
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+
+ iteratorWithImplicitKeySet(keyObj, mappedIterator)
+ } catch {
+ case sparkThrowable: SparkThrowable =>
+ throw sparkThrowable
+ case e: Exception =>
+ throw TransformWithStateUserFunctionException(e, "handleInputRows")
}
- ImplicitGroupingKeyTracker.removeImplicitKey()
-
- iteratorWithImplicitKeySet(keyObj, mappedIterator)
}
private def processInitialStateRows(
keyRow: UnsafeRow,
initStateIter: Iterator[InternalRow]): Unit = {
- val getInitStateValueObj =
- ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
-
- initStateObjIter.foreach { initState =>
- // allow multiple initial state rows on the same grouping key for integration
- // with state data source reader with initial state
- statefulProcessor
- .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
- .handleInitialState(keyObj, initState,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ try {
+ val getInitStateValueObj =
+ ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
+
+ initStateObjIter.foreach { initState =>
+ // allow multiple initial state rows on the same grouping key for integration
+ // with state data source reader with initial state
+ statefulProcessor
+ .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
+ .handleInitialState(keyObj, initState,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+ } catch {
+ case sparkThrowable: SparkThrowable =>
Review Comment:
Is the existing code not sufficient? This is how ForeachBatch does it:
```
try {
batchWriter(ds, batchId)
} catch {
// The user code can throw any type of exception.
case NonFatal(e) if !e.isInstanceOf[SparkThrowable] =>
throw ForeachBatchUserFuncException(e)
}
```
--
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-51869][SS] Create classification for user errors within UDFs for Scala TransformWithState [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #50667:
URL: https://github.com/apache/spark/pull/50667#issuecomment-2834021314
This only failed with docker integration CI.
https://github.com/ericm-db/spark/runs/41243071103
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055323329
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateSuite.scala:
##########
@@ -2400,6 +2554,170 @@ class TransformWithStateValidationSuite extends StateStoreMetricsTest {
)
}
+ test("transformWithState - check that error within handleInputRows is classified") {
Review Comment:
Yes they are
--
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-51869][SS] Create classification for user errors within UDFs for Scala TransformWithState [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2062779981
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +262,52 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
- }
- ImplicitGroupingKeyTracker.removeImplicitKey()
+ withStatefulProcessorErrorHandling("handleInputRows") {
Review Comment:
Ah good point
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055309557
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateSuite.scala:
##########
@@ -73,6 +73,119 @@ case class EvolvedState(
score: Double // Should default to 0.0
)
+class ClassifiedTimerErrorProcessor
+ extends StatefulProcessor[String, String, (String, BasicState)] {
+
+ @transient var state: ValueState[BasicState] = _
+
+ override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = {
+ state = getHandle.getValueState[BasicState](
+ "testState",
+ Encoders.product[BasicState],
+ TTLConfig.NONE)
+ }
+
+ override def handleInputRows(
+ key: String,
+ rows: Iterator[String],
+ timerValues: TimerValues): Iterator[(String, BasicState)] = {
+ getHandle.registerTimer(timerValues.getCurrentProcessingTimeInMs() + 1000)
+ Seq.empty.iterator
+ }
+
+ override def handleExpiredTimer(
+ key: String,
+ timerValues: TimerValues,
+ expiredTimerInfo: ExpiredTimerInfo): Iterator[(String, BasicState)] = {
+ throw StateStoreErrors.multipleColumnFamiliesNotSupported("dummy val")
+ }
+}
+
+class UnclassifiedTimerErrorProcessor
+ extends StatefulProcessor[String, String, (String, BasicState)] {
+
+ @transient var state: ValueState[BasicState] = _
+
+ override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = {
+ state = getHandle.getValueState[BasicState](
+ "testState",
+ Encoders.product[BasicState],
+ TTLConfig.NONE)
+ }
+
+ override def handleInputRows(
+ key: String,
+ rows: Iterator[String],
+ timerValues: TimerValues): Iterator[(String, BasicState)] = {
+ getHandle.registerTimer(timerValues.getCurrentProcessingTimeInMs() + 1000)
+ Seq.empty.iterator
+ }
+
+ override def handleExpiredTimer(
+ key: String,
+ timerValues: TimerValues,
+ expiredTimerInfo: ExpiredTimerInfo): Iterator[(String, BasicState)] = {
+ null.asInstanceOf[ValueState[BasicState]].get()
+ Seq.empty.iterator
+ }
+}
+
+
+class ClassifiedErrorInitialStateProcessor
+ extends StatefulProcessorWithInitialState[String, String, (String, BasicState), String] {
+
+ @transient var state: ValueState[BasicState] = _
+
+ override def init(outputMode: OutputMode, timeMode: TimeMode): Unit = {
+ state = getHandle.getValueState[BasicState](
+ "testState",
+ Encoders.product[BasicState],
+ TTLConfig.NONE)
+ }
+
+ override def handleInitialState(
+ key: String,
+ initialState: String,
+ timerValues: TimerValues): Unit = {
+ throw StateStoreErrors.multipleColumnFamiliesNotSupported("dummy val")
+ }
+
+ override def handleInputRows(
+ key: String,
+ rows: Iterator[String],
+ timerValues: TimerValues): Iterator[(String, BasicState)] = {
+ Seq.empty.iterator
+ }
+}
+
+
Review Comment:
nit: same 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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055295233
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +260,62 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
+ keyObj,
+ valueObjIter,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
+ getOutputRow(obj)
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+
+ iteratorWithImplicitKeySet(keyObj, mappedIterator)
+ } catch {
+ case sparkThrowable: SparkThrowable =>
+ throw sparkThrowable
+ case e: Exception =>
+ throw TransformWithStateUserFunctionException(e, "handleInputRows")
}
- ImplicitGroupingKeyTracker.removeImplicitKey()
-
- iteratorWithImplicitKeySet(keyObj, mappedIterator)
}
private def processInitialStateRows(
keyRow: UnsafeRow,
initStateIter: Iterator[InternalRow]): Unit = {
- val getInitStateValueObj =
- ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
-
- initStateObjIter.foreach { initState =>
- // allow multiple initial state rows on the same grouping key for integration
- // with state data source reader with initial state
- statefulProcessor
- .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
- .handleInitialState(keyObj, initState,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ try {
+ val getInitStateValueObj =
+ ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
+
+ initStateObjIter.foreach { initState =>
+ // allow multiple initial state rows on the same grouping key for integration
+ // with state data source reader with initial state
+ statefulProcessor
+ .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
+ .handleInitialState(keyObj, initState,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+ } catch {
+ case sparkThrowable: SparkThrowable =>
Review Comment:
We need to check if the underlying exception has the error class already defined ?
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055303990
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +260,62 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
+ keyObj,
+ valueObjIter,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
+ getOutputRow(obj)
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+
+ iteratorWithImplicitKeySet(keyObj, mappedIterator)
+ } catch {
+ case sparkThrowable: SparkThrowable =>
+ throw sparkThrowable
+ case e: Exception =>
+ throw TransformWithStateUserFunctionException(e, "handleInputRows")
}
- ImplicitGroupingKeyTracker.removeImplicitKey()
-
- iteratorWithImplicitKeySet(keyObj, mappedIterator)
}
private def processInitialStateRows(
keyRow: UnsafeRow,
initStateIter: Iterator[InternalRow]): Unit = {
- val getInitStateValueObj =
- ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
-
- initStateObjIter.foreach { initState =>
- // allow multiple initial state rows on the same grouping key for integration
- // with state data source reader with initial state
- statefulProcessor
- .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
- .handleInitialState(keyObj, initState,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ try {
+ val getInitStateValueObj =
+ ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
+
+ initStateObjIter.foreach { initState =>
+ // allow multiple initial state rows on the same grouping key for integration
+ // with state data source reader with initial state
+ statefulProcessor
+ .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
+ .handleInitialState(keyObj, initState,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+ } catch {
+ case sparkThrowable: SparkThrowable =>
Review Comment:
Can we also check for error class explicitly also - just to be safe ?
--
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-51869][SS] Create classification for user errors within UDFs for Scala TransformWithState [spark]
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR closed pull request #50667: [SPARK-51869][SS] Create classification for user errors within UDFs for Scala TransformWithState
URL: https://github.com/apache/spark/pull/50667
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on PR #50667:
URL: https://github.com/apache/spark/pull/50667#issuecomment-2823187086
@HeartSaVioR can you PTAL when you get a chance?
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "ericm-db (via GitHub)" <gi...@apache.org>.
ericm-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055304909
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -259,48 +260,62 @@ case class TransformWithStateExec(
private def handleInputRows(keyRow: UnsafeRow, valueRowIter: Iterator[InternalRow]):
Iterator[InternalRow] = {
- val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- val valueObjIter = valueRowIter.map(getValueObj.apply)
-
- // The statefulProcessor's handleInputRows method may create an eager iterator,
- // and in that case, the implicit key needs to be set now. However, it could return
- // a lazy iterator, in which case the implicit key should be set when the actual
- // methods on the iterator are invoked. This is done with the wrapper class
- // at the end of this method.
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val mappedIterator = statefulProcessor.handleInputRows(
- keyObj,
- valueObjIter,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
- getOutputRow(obj)
+ try {
+ val getOutputRow = ObjectOperator.wrapObjectToRow(outputObjectType)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ val valueObjIter = valueRowIter.map(getValueObj.apply)
+
+ // The statefulProcessor's handleInputRows method may create an eager iterator,
+ // and in that case, the implicit key needs to be set now. However, it could return
+ // a lazy iterator, in which case the implicit key should be set when the actual
+ // methods on the iterator are invoked. This is done with the wrapper class
+ // at the end of this method.
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val mappedIterator = statefulProcessor.handleInputRows(
+ keyObj,
+ valueObjIter,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction)).map { obj =>
+ getOutputRow(obj)
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+
+ iteratorWithImplicitKeySet(keyObj, mappedIterator)
+ } catch {
+ case sparkThrowable: SparkThrowable =>
+ throw sparkThrowable
+ case e: Exception =>
+ throw TransformWithStateUserFunctionException(e, "handleInputRows")
}
- ImplicitGroupingKeyTracker.removeImplicitKey()
-
- iteratorWithImplicitKeySet(keyObj, mappedIterator)
}
private def processInitialStateRows(
keyRow: UnsafeRow,
initStateIter: Iterator[InternalRow]): Unit = {
- val getInitStateValueObj =
- ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
-
- val keyObj = getKeyObj(keyRow) // convert key to objects
- ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
- val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
-
- initStateObjIter.foreach { initState =>
- // allow multiple initial state rows on the same grouping key for integration
- // with state data source reader with initial state
- statefulProcessor
- .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
- .handleInitialState(keyObj, initState,
- new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ try {
+ val getInitStateValueObj =
+ ObjectOperator.deserializeRowToObject(initialStateDeserializer, initialStateDataAttrs)
+
+ val keyObj = getKeyObj(keyRow) // convert key to objects
+ ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+ val initStateObjIter = initStateIter.map(getInitStateValueObj.apply)
+
+ initStateObjIter.foreach { initState =>
+ // allow multiple initial state rows on the same grouping key for integration
+ // with state data source reader with initial state
+ statefulProcessor
+ .asInstanceOf[StatefulProcessorWithInitialState[Any, Any, Any, Any]]
+ .handleInitialState(keyObj, initState,
+ new TimerValuesImpl(batchTimestampMs, eventTimeWatermarkForEviction))
+ }
+ ImplicitGroupingKeyTracker.removeImplicitKey()
+ } catch {
+ case sparkThrowable: SparkThrowable =>
Review Comment:
Ohh sure yeah sorry - didn't realize that's what you meant. Yeah will add.
--
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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055309857
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateSuite.scala:
##########
@@ -2400,6 +2554,170 @@ class TransformWithStateValidationSuite extends StateStoreMetricsTest {
)
}
+ test("transformWithState - check that error within handleInputRows is classified") {
+ withSQLConf(
+ SQLConf.STATE_STORE_PROVIDER_CLASS.key -> classOf[RocksDBStateStoreProvider].getName,
+ SQLConf.SHUFFLE_PARTITIONS.key ->
+ TransformWithStateSuiteUtils.NUM_SHUFFLE_PARTITIONS.toString) {
+
+ val inputData = MemoryStream[String]
+ val result = inputData.toDS()
+ .groupByKey(x => x)
+ .transformWithState(new UnclassifiedErrorProcessor(),
+ TimeMode.None(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, "a"),
+ ExpectFailure[TransformWithStateUserFunctionException] { error =>
+ checkError(
+ error.asInstanceOf[SparkException],
+ condition = "TRANSFORM_WITH_STATE_USER_FUNCTION_ERROR",
+ parameters = Map("reason" ->
+ ("Cannot invoke \"org.apache.spark.sql.streaming.ValueState." +
+ "get()\" because \"null\" is null"))
+ )
+ }
+ )
+ }
+ }
+
+ test("transformWithState - check that classified error is thrown from handleInputRows") {
+ withSQLConf(
+ SQLConf.STATE_STORE_PROVIDER_CLASS.key -> classOf[RocksDBStateStoreProvider].getName,
+ SQLConf.SHUFFLE_PARTITIONS.key ->
+ TransformWithStateSuiteUtils.NUM_SHUFFLE_PARTITIONS.toString) {
+
+ val inputData = MemoryStream[String]
+ val result = inputData.toDS()
+ .groupByKey(x => x)
+ .transformWithState(new ClassifiedErrorProcessor(),
+ TimeMode.None(),
+ OutputMode.Update())
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, "a"),
+ ExpectFailure[StateStoreMultipleColumnFamiliesNotSupportedException] { error =>
+ assert(error.getMessage.contains("not supported"))
+ }
+ )
+ }
+ }
+
+ test("transformWithState - check that error within handleInitialState is classified") {
+ withSQLConf(
+ SQLConf.STATE_STORE_PROVIDER_CLASS.key -> classOf[RocksDBStateStoreProvider].getName,
+ SQLConf.SHUFFLE_PARTITIONS.key ->
+ TransformWithStateSuiteUtils.NUM_SHUFFLE_PARTITIONS.toString) {
+
+ val inputData = MemoryStream[String]
+ val initDf = Seq("init_1").toDS().groupByKey(x => x)
+ val result = inputData.toDS()
+ .groupByKey(x => x)
+ .transformWithState(new UnclassifiedErrorInitialStateProcessor(),
+ TimeMode.None(),
+ OutputMode.Update(),
+ initDf)
+
+ testStream(result, OutputMode.Update())(
+ AddData(inputData, "a"),
+ ExpectFailure[TransformWithStateUserFunctionException] { error =>
+ checkError(
+ error.asInstanceOf[SparkException],
+ condition = "TRANSFORM_WITH_STATE_USER_FUNCTION_ERROR",
+ parameters = Map("reason" ->
+ ("Cannot invoke \"org.apache.spark.sql.streaming.ValueState." +
+ "get()\" because \"null\" is null"))
Review Comment:
same 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-51869][SS] Create classification for user errors within handleInputRows for Scala TransformWithState [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on code in PR #50667:
URL: https://github.com/apache/spark/pull/50667#discussion_r2055307574
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateSuite.scala:
##########
@@ -2400,6 +2554,170 @@ class TransformWithStateValidationSuite extends StateStoreMetricsTest {
)
}
+ test("transformWithState - check that error within handleInputRows is classified") {
Review Comment:
These are all in the validation suite right ?
--
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