You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "jiateoh (via GitHub)" <gi...@apache.org> on 2025/10/07 17:37:03 UTC
[PR] [WIP][SPARK-XXXXX][PS][SS][TESTS]Add Python TransformWithState test case for composite output schemas [spark]
jiateoh opened a new pull request, #52536:
URL: https://github.com/apache/spark/pull/52536
<!--
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 a new test case for python transform_with_state APIs to ensure that output schemas containing nested structs are properly handled.
### 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.
-->
Missing test coverage: the existing test case for composite types does check the state value schemas, but actual output is only handled as StringTypes.
### 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'.
-->
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.
-->
```
build/sbt -Phive -Phive-thriftserver -DskipTests package
python/run-tests --testnames 'pyspark.sql.tests.pandas.test_pandas_transform_with_state TransformWithStateInPandasTests'
python/run-tests --testnames 'pyspark.sql.tests.pandas.test_pandas_transform_with_state TransformWithStateInPySparkTests'
```
### 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.
-->
Generated-by: Claude Code (claude-sonnet-4-5-20250929)
--
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-53822][PS][SS][TESTS]Add Python TransformWithState test case for composite/nested output schemas [spark]
Posted by "bogao007 (via GitHub)" <gi...@apache.org>.
bogao007 commented on code in PR #52536:
URL: https://github.com/apache/spark/pull/52536#discussion_r2411935951
##########
python/pyspark/sql/tests/pandas/test_pandas_transform_with_state.py:
##########
@@ -1595,6 +1599,98 @@ def check_results(batch_df, batch_id):
StatefulProcessorCompositeTypeFactory(), check_results, output_schema=output_schema
)
+ # run a test with composite types where the output of TWS (not just the states) are complex.
+ def test_composite_output_schema(self):
+ def check_results(batch_df, batch_id):
+ batch_df.collect()
+ # Cannot use set() wrapper because Row objects contain unhashable types (lists)
+ if batch_id == 0:
+ assert batch_df.sort("primitiveValue").collect() == [
+ Row(
+ primitiveValue="key_0_count_2",
+ listOfPrimitive=["item_0", "item_1"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5)
+ }
+ ),
+ Row(
+ primitiveValue="key_1_count_2",
+ listOfPrimitive=["item_0", "item_1"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5)
+ }
+ )
+ ]
+ else:
+ assert batch_df.sort("primitiveValue").collect() == [
+ Row(
+ primitiveValue="key_0_count_5",
+ listOfPrimitive=["item_0", "item_1", "item_2", "item_3", "item_4"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5),
+ Row(intValue=2, doubleValue=3.0),
+ Row(intValue=3, doubleValue=4.5),
+ Row(intValue=4, doubleValue=6.0)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5),
+ "nested_key2": Row(intValue=20, doubleValue=5.0),
+ "nested_key3": Row(intValue=30, doubleValue=7.5),
+ "nested_key4": Row(intValue=40, doubleValue=10.0)
+ }
+ ),
+ Row(
+ primitiveValue="key_1_count_4",
+ listOfPrimitive=["item_0", "item_1", "item_2", "item_3"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1", "key2": "value2", "key3": "value3"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5),
+ Row(intValue=2, doubleValue=3.0),
+ Row(intValue=3, doubleValue=4.5)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5),
+ "nested_key2": Row(intValue=20, doubleValue=5.0),
+ "nested_key3": Row(intValue=30, doubleValue=7.5)
+ }
+ )
+ ]
+
+ # Define the output schema matching Scala case class
+ inner_nested_class_schema = StructType([
Review Comment:
Can we add an Array type to the inner schema of the map state?
--
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-53822][PYTHON][SS][TESTS]Add Python TransformWithState test case for composite/nested output schemas [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db commented on PR #52536:
URL: https://github.com/apache/spark/pull/52536#issuecomment-3387300503
Will merge once CI is green
--
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-53822][PS][SS][TESTS]Add Python TransformWithState test case for composite/nested output schemas [spark]
Posted by "jiateoh (via GitHub)" <gi...@apache.org>.
jiateoh commented on code in PR #52536:
URL: https://github.com/apache/spark/pull/52536#discussion_r2412044093
##########
python/pyspark/sql/tests/pandas/test_pandas_transform_with_state.py:
##########
@@ -1595,6 +1599,98 @@ def check_results(batch_df, batch_id):
StatefulProcessorCompositeTypeFactory(), check_results, output_schema=output_schema
)
+ # run a test with composite types where the output of TWS (not just the states) are complex.
+ def test_composite_output_schema(self):
+ def check_results(batch_df, batch_id):
+ batch_df.collect()
+ # Cannot use set() wrapper because Row objects contain unhashable types (lists)
+ if batch_id == 0:
+ assert batch_df.sort("primitiveValue").collect() == [
+ Row(
+ primitiveValue="key_0_count_2",
+ listOfPrimitive=["item_0", "item_1"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5)
+ }
+ ),
+ Row(
+ primitiveValue="key_1_count_2",
+ listOfPrimitive=["item_0", "item_1"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5)
+ }
+ )
+ ]
+ else:
+ assert batch_df.sort("primitiveValue").collect() == [
+ Row(
+ primitiveValue="key_0_count_5",
+ listOfPrimitive=["item_0", "item_1", "item_2", "item_3", "item_4"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5),
+ Row(intValue=2, doubleValue=3.0),
+ Row(intValue=3, doubleValue=4.5),
+ Row(intValue=4, doubleValue=6.0)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5),
+ "nested_key2": Row(intValue=20, doubleValue=5.0),
+ "nested_key3": Row(intValue=30, doubleValue=7.5),
+ "nested_key4": Row(intValue=40, doubleValue=10.0)
+ }
+ ),
+ Row(
+ primitiveValue="key_1_count_4",
+ listOfPrimitive=["item_0", "item_1", "item_2", "item_3"],
+ mapOfPrimitive={"key0": "value0", "key1": "value1", "key2": "value2", "key3": "value3"},
+ listOfComposite=[
+ Row(intValue=0, doubleValue=0.0),
+ Row(intValue=1, doubleValue=1.5),
+ Row(intValue=2, doubleValue=3.0),
+ Row(intValue=3, doubleValue=4.5)
+ ],
+ mapOfComposite={
+ "nested_key0": Row(intValue=0, doubleValue=0.0),
+ "nested_key1": Row(intValue=10, doubleValue=2.5),
+ "nested_key2": Row(intValue=20, doubleValue=5.0),
+ "nested_key3": Row(intValue=30, doubleValue=7.5)
+ }
+ )
+ ]
+
+ # Define the output schema matching Scala case class
+ inner_nested_class_schema = StructType([
Review Comment:
Lost this commit due to a rebase/force push, but I've added both an array and map type into the inner nested class (which is in turn used in the array and map outputs)
--
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-53822][PYTHON][SS][TESTS]Add Python TransformWithState test case for composite/nested output schemas [spark]
Posted by "anishshri-db (via GitHub)" <gi...@apache.org>.
anishshri-db closed pull request #52536: [SPARK-53822][PYTHON][SS][TESTS]Add Python TransformWithState test case for composite/nested output schemas
URL: https://github.com/apache/spark/pull/52536
--
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-53822][PYTHON][SS][TESTS]Add Python TransformWithState test case for composite/nested output schemas [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #52536:
URL: https://github.com/apache/spark/pull/52536#issuecomment-3379340006
change `[PS]` to `[PYTHON]` since `PS` stands for `Pandas-API-on-Spark`
--
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