-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add Support for Consistent SQL Query Generation #1015
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3ddac7f
Move from constants to IdPrefix enum.
plypaul 5dabed6
Update calls to IdGeneratorRegistry.for_class() / str -> IdPrefix.
plypaul c861514
Streamline DagId generation.
plypaul 1b1ca31
Change SqlQueryPlan() to use an optional plan ID.
plypaul 72def15
Change GroupByItemResolutionNode.id_prefix_enum() to .id_prefix().
plypaul 5c34b86
Add PrefixIdGenerator.reset().
plypaul 775618f
Update patching of ID generators.
plypaul 8c62f31
Add repr to sequential ID.
plypaul 1906f54
Rename PrefixIdGenerator -> SequentialIdGenerator.
plypaul efa31d8
Remove id_generation.py since it was replaced by sequential_id.py.
plypaul 5f20d39
Reset ID generation for MetricFlowEngine queries.
plypaul 952b648
Address comments.
plypaul 0751515
Make IdPrefix an interface and add StaticIdPrefix, DynamicIdPrefix.
plypaul 3d33b6a
Revert changes that caused non-number changes in snapshots.
plypaul c600de3
Revert changes that caused snapshot file names to change.
plypaul 68dacde
Add test for ID enumeration.
plypaul 6b8857a
Add change log for #1020.
plypaul f4b1f1e
Update snapshots (should only contain number changes).
plypaul ed8324d
Rebase fixes.
plypaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,6 @@ | ||
kind: Features | ||
body: Add Support for Consistent SQL Query Generation | ||
time: 2024-01-31T15:51:00.673728-08:00 | ||
custom: | ||
Author: plypaul | ||
Issue: "1020" |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,17 +1,114 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from abc import ABC, ABCMeta, abstractmethod | ||
from dataclasses import dataclass | ||
from enum import Enum, EnumMeta | ||
|
||
from typing_extensions import override | ||
|
||
class IdPrefix(Enum): | ||
"""Enumerates the prefixes used for generating IDs. | ||
|
||
TODO: Move all ID prefixes here. | ||
class IdPrefix(ABC): | ||
"""A prefix for generating IDs. e.g. prefix=foo -> id=foo_0.""" | ||
|
||
@property | ||
@abstractmethod | ||
def str_value(self) -> str: | ||
"""Return the string value of this ID prefix.""" | ||
raise NotImplementedError | ||
|
||
|
||
class EnumMetaClassHelper(ABCMeta, EnumMeta): | ||
"""Metaclass to allow subclassing of IdPrefix / Enum. | ||
|
||
Without this, you'll get an error: | ||
|
||
Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all | ||
its bases | ||
|
||
since Enum has a special metaclass. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class StaticIdPrefix(IdPrefix, Enum, metaclass=EnumMetaClassHelper): | ||
"""Enumerates the prefixes used for generating IDs.""" | ||
|
||
DATAFLOW_NODE_AGGREGATE_MEASURES_ID_PREFIX = "am" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commit is a thing of beauty. |
||
DATAFLOW_NODE_COMPUTE_METRICS_ID_PREFIX = "cm" | ||
DATAFLOW_NODE_JOIN_AGGREGATED_MEASURES_BY_GROUPBY_COLUMNS_PREFIX = "jamgc" | ||
DATAFLOW_NODE_JOIN_TO_STANDARD_OUTPUT_ID_PREFIX = "jso" | ||
DATAFLOW_NODE_JOIN_SELF_OVER_TIME_RANGE_ID_PREFIX = "jotr" | ||
DATAFLOW_NODE_ORDER_BY_LIMIT_ID_PREFIX = "obl" | ||
DATAFLOW_NODE_PASS_FILTER_ELEMENTS_ID_PREFIX = "pfe" | ||
DATAFLOW_NODE_READ_SQL_SOURCE_ID_PREFIX = "rss" | ||
DATAFLOW_NODE_WHERE_CONSTRAINT_ID_PREFIX = "wcc" | ||
DATAFLOW_NODE_WRITE_TO_RESULT_DATAFRAME_ID_PREFIX = "wrd" | ||
DATAFLOW_NODE_WRITE_TO_RESULT_TABLE_ID_PREFIX = "wrt" | ||
DATAFLOW_NODE_COMBINE_AGGREGATED_OUTPUTS_ID_PREFIX = "cao" | ||
DATAFLOW_NODE_CONSTRAIN_TIME_RANGE_ID_PREFIX = "ctr" | ||
DATAFLOW_NODE_SET_MEASURE_AGGREGATION_TIME = "sma" | ||
DATAFLOW_NODE_SEMI_ADDITIVE_JOIN_ID_PREFIX = "saj" | ||
DATAFLOW_NODE_JOIN_TO_TIME_SPINE_ID_PREFIX = "jts" | ||
DATAFLOW_NODE_MIN_MAX_ID_PREFIX = "mm" | ||
DATAFLOW_NODE_ADD_UUID_COLUMN_PREFIX = "auid" | ||
DATAFLOW_NODE_JOIN_CONVERSION_EVENTS_PREFIX = "jce" | ||
|
||
SQL_EXPR_COLUMN_REFERENCE_ID_PREFIX = "cr" | ||
SQL_EXPR_COMPARISON_ID_PREFIX = "cmp" | ||
SQL_EXPR_FUNCTION_ID_PREFIX = "fnc" | ||
SQL_EXPR_PERCENTILE_ID_PREFIX = "perc" | ||
SQL_EXPR_STRING_ID_PREFIX = "str" | ||
SQL_EXPR_NULL_PREFIX = "null" | ||
SQL_EXPR_LOGICAL_OPERATOR_PREFIX = "lo" | ||
SQL_EXPR_STRING_LITERAL_PREFIX = "sl" | ||
SQL_EXPR_IS_NULL_PREFIX = "isn" | ||
SQL_EXPR_CAST_TO_TIMESTAMP_PREFIX = "ctt" | ||
SQL_EXPR_DATE_TRUNC = "dt" | ||
SQL_EXPR_SUBTRACT_TIME_INTERVAL_PREFIX = "sti" | ||
SQL_EXPR_EXTRACT = "ex" | ||
SQL_EXPR_RATIO_COMPUTATION = "rc" | ||
SQL_EXPR_BETWEEN_PREFIX = "betw" | ||
SQL_EXPR_WINDOW_FUNCTION_ID_PREFIX = "wfnc" | ||
SQL_EXPR_GENERATE_UUID_PREFIX = "uuid" | ||
|
||
SQL_PLAN_SELECT_STATEMENT_ID_PREFIX = "ss" | ||
SQL_PLAN_TABLE_FROM_CLAUSE_ID_PREFIX = "tfc" | ||
|
||
EXEC_NODE_READ_SQL_QUERY = "rsq" | ||
EXEC_NODE_NOOP = "noop" | ||
EXEC_NODE_WRITE_TO_TABLE = "wtt" | ||
|
||
# Group by item resolution | ||
GROUP_BY_ITEM_RESOLUTION_DAG = "gbir" | ||
QUERY_GROUP_BY_ITEM_RESOLUTION_NODE = "qr" | ||
METRIC_GROUP_BY_ITEM_RESOLUTION_NODE = "mtr" | ||
MEASURE_GROUP_BY_ITEM_RESOLUTION_NODE = "msr" | ||
VALUES_GROUP_BY_ITEM_RESOLUTION_NODE = "vr" | ||
|
||
DATAFLOW_PLAN_PREFIX = "dfp" | ||
OPTIMIZED_DATAFLOW_PLAN_PREFIX = "dfpo" | ||
SQL_QUERY_PLAN_PREFIX = "sqp" | ||
EXEC_PLAN_PREFIX = "ep" | ||
|
||
MF_DAG = "mfd" | ||
|
||
TIME_SPINE_SOURCE = "time_spine_src" | ||
SUB_QUERY = "subq" | ||
|
||
@property | ||
@override | ||
def str_value(self) -> str: | ||
return self.value | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamicIdPrefix(IdPrefix): | ||
"""ID prefixes based on any string value.""" | ||
|
||
prefix: str | ||
|
||
@property | ||
@override | ||
def str_value(self) -> str: | ||
return self.prefix |
This file contains 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 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 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
Oops, something went wrong.
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.
Oh I see.
The other option is to make IdPrefix a protocol, but we've been over the tradeoffs there and I think having it be a superclass makes sense even though enum-type subclasses are a bit weird.