-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add Plan.ExecutionBehavior support #224
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
Open
nielspardon
wants to merge
1
commit into
substrait-io:main
Choose a base branch
from
nielspardon:feat/issue-185-execution-behavior
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+258
−23
Open
Changes from all commits
Commits
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
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,92 @@ | ||
| import substrait.algebra_pb2 as stalg | ||
| import substrait.plan_pb2 as stp | ||
| import substrait.type_pb2 as stt | ||
|
|
||
| from substrait.builders.plan import ( | ||
| default_version, | ||
| exchange, | ||
| read_named_table, | ||
| set, | ||
| with_execution_behavior, | ||
| ) | ||
| from substrait.builders.type import boolean, i64 | ||
|
|
||
| struct = stt.Type.Struct( | ||
| types=[i64(nullable=False), boolean()], | ||
| nullability=stt.Type.Nullability.NULLABILITY_REQUIRED, | ||
| ) | ||
|
|
||
| named_struct = stt.NamedStruct(names=["id", "is_applicable"], struct=struct) | ||
|
|
||
| PER_PLAN = stp.ExecutionBehavior.VARIABLE_EVALUATION_MODE_PER_PLAN | ||
| PER_RECORD = stp.ExecutionBehavior.VARIABLE_EVALUATION_MODE_PER_RECORD | ||
|
|
||
|
|
||
| def test_with_execution_behavior_per_record(): | ||
| base = read_named_table("example_table", named_struct) | ||
|
|
||
| actual = with_execution_behavior(base, PER_RECORD)(None) | ||
|
|
||
| expected = read_named_table("example_table", named_struct)(None) | ||
| expected.execution_behavior.CopyFrom( | ||
| stp.ExecutionBehavior(variable_eval_mode=PER_RECORD) | ||
| ) | ||
|
|
||
| assert actual == expected | ||
| assert actual.version == default_version | ||
|
|
||
|
|
||
| def test_with_execution_behavior_per_plan_preserves_relations(): | ||
| base = read_named_table("example_table", named_struct) | ||
|
|
||
| actual = with_execution_behavior(base, PER_PLAN)(None) | ||
|
|
||
| assert actual.execution_behavior.variable_eval_mode == PER_PLAN | ||
| # the underlying relation is left untouched | ||
| assert actual.relations == base(None).relations | ||
|
|
||
|
|
||
| def test_with_execution_behavior_accepts_bound_plan_without_mutating_it(): | ||
| bound = read_named_table("example_table", named_struct)(None) | ||
|
|
||
| actual = with_execution_behavior(bound, PER_PLAN)(None) | ||
|
|
||
| assert actual.execution_behavior.variable_eval_mode == PER_PLAN | ||
| # the caller's input plan is not mutated in place | ||
| assert not bound.HasField("execution_behavior") | ||
|
|
||
|
|
||
| def test_execution_behavior_survives_subsequent_builder(): | ||
| # Applying a builder after the setting must not drop it: the fresh output | ||
| # Plan carries the execution behavior over from its input. | ||
| base = with_execution_behavior(read_named_table("t", named_struct), PER_RECORD) | ||
|
|
||
| actual = exchange(base, partition_count=2)(None) | ||
|
|
||
| assert actual.execution_behavior.variable_eval_mode == PER_RECORD | ||
|
|
||
|
|
||
| def test_with_execution_behavior_overwrites_existing(): | ||
| # Applying it again replaces the previous mode (last wins), rather than | ||
| # merging or keeping the earlier value. | ||
| base = with_execution_behavior(read_named_table("t", named_struct), PER_PLAN) | ||
|
|
||
| actual = with_execution_behavior(base, PER_RECORD)(None) | ||
|
|
||
| assert actual.execution_behavior.variable_eval_mode == PER_RECORD | ||
|
|
||
|
|
||
| def test_execution_behavior_taken_from_first_input(): | ||
| # For multi-input builders the first input that declares one wins. | ||
| left = with_execution_behavior(read_named_table("l", named_struct), PER_RECORD) | ||
| right = with_execution_behavior(read_named_table("r", named_struct), PER_PLAN) | ||
|
|
||
| actual = set([left, right], stalg.SetRel.SET_OP_UNION_ALL)(None) | ||
|
|
||
| assert actual.execution_behavior.variable_eval_mode == PER_RECORD | ||
|
|
||
|
|
||
| def test_plans_have_no_execution_behavior_by_default(): | ||
| plan = read_named_table("example_table", named_struct)(None) | ||
|
|
||
| assert not plan.HasField("execution_behavior") |
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.
modefeels too generic here, maybevariable_eval_mode?