This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
[Query Planning Refactor]: SimpleExecute #1008
Draft
chewselene
wants to merge
10
commits into
main
Choose a base branch
from
sc_query_execution
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.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
21ff9de
WIP SimpleExecute
0b04429
generate_query_plan implementation
c31d8f1
add execute_query_plan
68b8ebe
merge main
029be77
Merge branch 'main' into sc_query_execution
41f7bb5
merge main
8fd07cc
merge main
ba8c663
fix spacing
3fa161f
Merge branch 'main' into sc_query_execution
646db34
use enums for backend type
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
# Copyright 2021-present Kensho Technologies, LLC. | ||
from typing import Any, Callable, ContextManager, Dict, Iterable, Mapping | ||
|
||
from ..post_processing.sql_post_processing import post_process_mssql_folds | ||
from ..query_formatting.common import deserialize_multiple_arguments | ||
from .typedefs import QueryExecutionFunc, QueryPlan, SimpleExecute | ||
|
||
|
||
def _execute_simple_execute_node( | ||
provider_client_makers: Dict[str, Callable[[], ContextManager[QueryExecutionFunc]]], | ||
query_plan_node: SimpleExecute, | ||
) -> Iterable[Mapping[str, Any]]: | ||
"""Execute a SimpleExecute.""" | ||
provider_client_maker = provider_client_makers[query_plan_node.provider_id] | ||
arguments = deserialize_multiple_arguments( | ||
query_plan_node.arguments, query_plan_node.input_metadata | ||
) | ||
requires_postprocessing = query_plan_node.provider_metadata.requires_fold_postprocessing | ||
|
||
with provider_client_maker() as query_client: | ||
result = query_client(query_plan_node.query, query_plan_node.input_metadata, arguments) | ||
|
||
# Apply post processing for MSSQL folds if applicable. | ||
if requires_postprocessing: | ||
list_dict_result = [dict(entry) for entry in result] | ||
post_process_mssql_folds(list_dict_result, query_plan_node.output_metadata) | ||
return list_dict_result | ||
|
||
# Otherwise, return result as is. | ||
return result | ||
|
||
|
||
###### | ||
# Public API | ||
###### | ||
|
||
|
||
def execute_query_plan( | ||
provider_client_makers: Dict[str, Callable[[], ContextManager[QueryExecutionFunc]]], | ||
query_plan: QueryPlan, | ||
) -> Iterable[Mapping[str, Any]]: | ||
"""Execute a QueryPlan.""" | ||
# TODO(selene): figure out if we want some sort of class to contain provider_client_makers | ||
if isinstance(query_plan.plan_root_node, SimpleExecute): | ||
return _execute_simple_execute_node(provider_client_makers, query_plan.plan_root_node) | ||
else: | ||
raise NotImplementedError( | ||
f"Received plan_root_node with unsupported type " | ||
f"{type(query_plan.plan_root_node)}: {query_plan.plan_root_node}" | ||
) |
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.
I'm unsure of how to deal with InterpreterAdapters. The public methods are
interpret_ir
andinterpret_query
.SimpleExecute
is set up to contain a query string, which is the input ofinterpret_query
, but that function also requires the schema to be passed. It seems like to want to use the schema to compile the query in this function, but then our output (the equivalent of thequery
inSimpleExecute
) would beIrAndMetadata
rather than a query string. Making the type ofquery
beUnion[str, IrAndMetadata]
doesn't really seem to make sense, but maybe it would be more tolerable if we renamedquery
tobackend_input
or something similar? Thoughts?