-
Notifications
You must be signed in to change notification settings - Fork 49
structure execution plan #148
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5d90df6
structure execution plan
AviAvni f621dce
lint
AviAvni 9b956cd
test operation tree
AviAvni 0e5b8c7
fix format
AviAvni b4d6d5d
lint
AviAvni 1214c1b
Merge branch 'master' into structure-execution-plan
AviAvni 5044b11
introduce operation class
AviAvni 94014c3
linter issues
AviAvni 7b83651
fix indent
AviAvni c5d7a51
fix indent
AviAvni fa6c271
fix comparison
AviAvni fa56af0
address review
AviAvni 92b8b88
indentation
swilly22 2a18643
address review
AviAvni ef428b2
compare plans
swilly22 412393a
document
AviAvni 94af356
Merge branch 'master' into structure-execution-plan
AviAvni 5d87a35
remove redundant equal
AviAvni 24a6bc2
Merge branch 'structure-execution-plan' of https://github.com/RedisGr…
AviAvni 247b3f2
review
AviAvni 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class Operation: | ||
def __init__(self, name, args=None): | ||
self.name = name | ||
self.args = args | ||
self.children = [] | ||
|
||
def append_child(self, child): | ||
self.children.append(child) | ||
return self | ||
|
||
def __eq__(self, o: object) -> bool: | ||
swilly22 marked this conversation as resolved.
Show resolved
Hide resolved
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not isinstance(o, Operation): | ||
return False | ||
|
||
if self.name != o.name or self.args != o.args or len(self.children) != len(o.children): | ||
return False | ||
|
||
for i in range(len(self.children)): | ||
if not self.children[i] == o.children[i]: | ||
return False | ||
|
||
return True | ||
|
||
|
||
class ExecutionPlan: | ||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def __init__(self, plan): | ||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.plan = plan | ||
self.structured_plan = self._operation_tree() | ||
|
||
def __str__(self) -> str: | ||
return "\n".join(self.plan) | ||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _operation_tree(self): | ||
swilly22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
i = 0 | ||
level = 0 | ||
stack = [] | ||
current = None | ||
|
||
while i < len(self.plan): | ||
op = self.plan[i] | ||
op_level = op.count(" ") | ||
if op_level == level: | ||
args = op.split("|") | ||
current = Operation(args[0].strip(), None if len(args) == 1 else args[1].strip()) | ||
i += 1 | ||
elif op_level == level + 1: | ||
args = op.split("|") | ||
child = Operation(args[0].strip(), None if len(args) == 1 else args[1].strip()) | ||
current.children.append(child) | ||
AviAvni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stack.append(current) | ||
current = child | ||
level += 1 | ||
i += 1 | ||
elif op_level < level: | ||
levels_back = level - op_level + 1 | ||
for _ in range(levels_back): | ||
current = stack.pop() | ||
level -= levels_back | ||
else: | ||
raise Exception("corrupted plan") | ||
return stack[0] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.