-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-52511][SDP] Support dry-run mode in spark-pipelines command #51489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8aec6f
dry run
sryza 143fdd4
add Python end to end test
sryza 9e0dd6f
fix lint
sryza 5a00043
cli fix
sryza 8f5c457
Merge remote-tracking branch 'apache/master' into dry-run
sryza 5956c54
fix refresh tests after merge conflict
sryza 63282a0
fix test_spark_connect after merge conflict
sryza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,7 +217,7 @@ def change_dir(path: Path) -> Generator[None, None, None]: | |
| os.chdir(prev) | ||
|
|
||
|
|
||
| def run(spec_path: Path) -> None: | ||
| def run(spec_path: Path, dry: bool) -> None: | ||
| """Run the pipeline defined with the given spec.""" | ||
| log_with_curr_timestamp(f"Loading pipeline spec from {spec_path}...") | ||
| spec = load_pipeline_spec(spec_path) | ||
|
|
@@ -242,7 +242,7 @@ def run(spec_path: Path) -> None: | |
| register_definitions(spec_path, registry, spec) | ||
|
|
||
| log_with_curr_timestamp("Starting run...") | ||
| result_iter = start_run(spark, dataflow_graph_id) | ||
| result_iter = start_run(spark, dataflow_graph_id, dry=dry) | ||
| try: | ||
| handle_pipeline_events(result_iter) | ||
| finally: | ||
|
|
@@ -257,6 +257,13 @@ def run(spec_path: Path) -> None: | |
| run_parser = subparsers.add_parser("run", help="Run a pipeline.") | ||
| run_parser.add_argument("--spec", help="Path to the pipeline spec.") | ||
|
|
||
| # "dry-run" subcommand | ||
| run_parser = subparsers.add_parser( | ||
| "dry-run", | ||
| help="Launch a run that just validates the graph and checks for errors.", | ||
| ) | ||
| run_parser.add_argument("--spec", help="Path to the pipeline spec.") | ||
|
||
|
|
||
| # "init" subcommand | ||
| init_parser = subparsers.add_parser( | ||
| "init", | ||
|
|
@@ -270,9 +277,9 @@ def run(spec_path: Path) -> None: | |
| ) | ||
|
|
||
| args = parser.parse_args() | ||
| assert args.command in ["run", "init"] | ||
| assert args.command in ["run", "dry-run", "init"] | ||
|
|
||
| if args.command == "run": | ||
| if args.command in ["run", "dry-run"]: | ||
| if args.spec is not None: | ||
| spec_path = Path(args.spec) | ||
| if not spec_path.is_file(): | ||
|
|
@@ -283,6 +290,6 @@ def run(spec_path: Path) -> None: | |
| else: | ||
| spec_path = find_pipeline_spec(Path.cwd()) | ||
|
|
||
| run(spec_path=spec_path) | ||
| run(spec_path=spec_path, dry=(args.command == "dry-run")) | ||
| elif args.command == "init": | ||
| init(args.name) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| """ | ||
| Tests that run Pipelines against a Spark Connect server. | ||
| """ | ||
|
|
||
| import unittest | ||
|
|
||
| from pyspark.errors.exceptions.connect import AnalysisException | ||
| from pyspark.pipelines.graph_element_registry import graph_element_registration_context | ||
| from pyspark.pipelines.spark_connect_graph_element_registry import ( | ||
| SparkConnectGraphElementRegistry, | ||
| ) | ||
| from pyspark.pipelines.spark_connect_pipeline import ( | ||
| create_dataflow_graph, | ||
| start_run, | ||
| handle_pipeline_events, | ||
| ) | ||
| from pyspark import pipelines as sdp | ||
| from pyspark.testing.connectutils import ( | ||
| ReusedConnectTestCase, | ||
| should_test_connect, | ||
| connect_requirement_message, | ||
| ) | ||
|
|
||
|
|
||
| @unittest.skipIf(not should_test_connect, connect_requirement_message) | ||
| class SparkConnectPipelinesTest(ReusedConnectTestCase): | ||
| def test_dry_run(self): | ||
| dataflow_graph_id = create_dataflow_graph(self.spark, None, None, None) | ||
| registry = SparkConnectGraphElementRegistry(self.spark, dataflow_graph_id) | ||
|
|
||
| with graph_element_registration_context(registry): | ||
|
|
||
| @sdp.materialized_view | ||
| def mv(): | ||
| return self.spark.range(1) | ||
|
|
||
| result_iter = start_run(self.spark, dataflow_graph_id, dry=True) | ||
| handle_pipeline_events(result_iter) | ||
|
|
||
| def test_dry_run_failure(self): | ||
| dataflow_graph_id = create_dataflow_graph(self.spark, None, None, None) | ||
| registry = SparkConnectGraphElementRegistry(self.spark, dataflow_graph_id) | ||
|
|
||
| with graph_element_registration_context(registry): | ||
|
|
||
| @sdp.table | ||
| def st(): | ||
| # Invalid because a streaming query is expected | ||
| return self.spark.range(1) | ||
|
|
||
| result_iter = start_run(self.spark, dataflow_graph_id, dry=True) | ||
| with self.assertRaises(AnalysisException) as context: | ||
| handle_pipeline_events(result_iter) | ||
| self.assertIn( | ||
| "INVALID_FLOW_QUERY_TYPE.BATCH_RELATION_FOR_STREAMING_TABLE", str(context.exception) | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| import xmlrunner # type: ignore | ||
|
|
||
| testRunner = xmlrunner.XMLTestRunner(output="target/test-reports", verbosity=2) | ||
| except ImportError: | ||
| testRunner = None | ||
| unittest.main(testRunner=testRunner, verbosity=2) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sryza shall we have an end-to-end test for the dry run mode? We should check that it can detect failures without side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing – just added, in test_spark_connect.py