Skip to content
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

Renames related to SqlPlan - Part 3 #1583

Open
wants to merge 7 commits into
base: p--misc--12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

from metricflow.data_table.mf_table import MetricFlowDataTable
from metricflow.protocols.sql_client import SqlEngine
from metricflow.sql.render.big_query import BigQuerySqlQueryPlanRenderer
from metricflow.sql.render.databricks import DatabricksSqlQueryPlanRenderer
from metricflow.sql.render.duckdb_renderer import DuckDbSqlQueryPlanRenderer
from metricflow.sql.render.postgres import PostgresSQLSqlQueryPlanRenderer
from metricflow.sql.render.redshift import RedshiftSqlQueryPlanRenderer
from metricflow.sql.render.snowflake import SnowflakeSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import SqlQueryPlanRenderer
from metricflow.sql.render.trino import TrinoSqlQueryPlanRenderer
from metricflow.sql.render.big_query import BigQuerySqlPlanRenderer
from metricflow.sql.render.databricks import DatabricksSqlPlanRenderer
from metricflow.sql.render.duckdb_renderer import DuckDbSqlPlanRenderer
from metricflow.sql.render.postgres import PostgresSQLSqlPlanRenderer
from metricflow.sql.render.redshift import RedshiftSqlPlanRenderer
from metricflow.sql.render.snowflake import SnowflakeSqlPlanRenderer
from metricflow.sql.render.sql_plan_renderer import SqlPlanRenderer
from metricflow.sql.render.trino import TrinoSqlPlanRenderer
from metricflow.sql_request.sql_request_attributes import SqlRequestId

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,22 +64,22 @@ def sql_engine_type(self) -> SqlEngine:
assert_values_exhausted(self)

@property
def sql_query_plan_renderer(self) -> SqlQueryPlanRenderer:
def sql_query_plan_renderer(self) -> SqlPlanRenderer:
"""Return the SqlQueryPlanRenderer corresponding to the supported adapter type."""
if self is SupportedAdapterTypes.BIGQUERY:
return BigQuerySqlQueryPlanRenderer()
return BigQuerySqlPlanRenderer()
elif self is SupportedAdapterTypes.DATABRICKS:
return DatabricksSqlQueryPlanRenderer()
return DatabricksSqlPlanRenderer()
elif self is SupportedAdapterTypes.POSTGRES:
return PostgresSQLSqlQueryPlanRenderer()
return PostgresSQLSqlPlanRenderer()
elif self is SupportedAdapterTypes.REDSHIFT:
return RedshiftSqlQueryPlanRenderer()
return RedshiftSqlPlanRenderer()
elif self is SupportedAdapterTypes.SNOWFLAKE:
return SnowflakeSqlQueryPlanRenderer()
return SnowflakeSqlPlanRenderer()
elif self is SupportedAdapterTypes.DUCKDB:
return DuckDbSqlQueryPlanRenderer()
return DuckDbSqlPlanRenderer()
elif self is SupportedAdapterTypes.TRINO:
return TrinoSqlQueryPlanRenderer()
return TrinoSqlPlanRenderer()
else:
assert_values_exhausted(self)

Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(self, adapter: BaseAdapter):
) from e

self._sql_engine_type = adapter_type.sql_engine_type
self._sql_query_plan_renderer = adapter_type.sql_query_plan_renderer
self._sql_plan_renderer = adapter_type.sql_query_plan_renderer
logger.debug(
LazyFormat(lambda: f"Initialized AdapterBackedSqlClient with dbt adapter type `{adapter_type.value}`")
)
Expand All @@ -120,9 +120,9 @@ def sql_engine_type(self) -> SqlEngine:
return self._sql_engine_type

@property
def sql_query_plan_renderer(self) -> SqlQueryPlanRenderer:
def sql_plan_renderer(self) -> SqlPlanRenderer:
"""Dialect-specific SQL query plan renderer used for converting MetricFlow's query plan to executable SQL."""
return self._sql_query_plan_renderer
return self._sql_plan_renderer

def query(
self,
Expand Down
2 changes: 1 addition & 1 deletion metricflow/engine/metricflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def _create_execution_plan(self, mf_query_request: MetricFlowQueryRequest) -> Me
logger.info(LazyFormat("Building execution plan"))
_to_execution_plan_converter = DataflowToExecutionPlanConverter(
sql_plan_converter=self._to_sql_plan_converter,
sql_plan_renderer=self._sql_client.sql_query_plan_renderer,
sql_plan_renderer=self._sql_client.sql_plan_renderer,
sql_client=self._sql_client,
sql_optimization_level=mf_query_request.sql_optimization_level,
)
Expand Down
6 changes: 3 additions & 3 deletions metricflow/execution/dataflow_to_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlPlanConverter
from metricflow.protocols.sql_client import SqlClient
from metricflow.sql.optimizer.optimization_levels import SqlOptimizationLevel
from metricflow.sql.render.sql_plan_renderer import SqlPlanRenderResult, SqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import SqlPlanRenderer, SqlPlanRenderResult

logger = logging.getLogger(__name__)

Expand All @@ -53,7 +53,7 @@ class DataflowToExecutionPlanConverter(DataflowPlanNodeVisitor[ConvertToExecutio
def __init__(
self,
sql_plan_converter: DataflowToSqlPlanConverter,
sql_plan_renderer: SqlQueryPlanRenderer,
sql_plan_renderer: SqlPlanRenderer,
sql_client: SqlClient,
sql_optimization_level: SqlOptimizationLevel,
) -> None:
Expand Down Expand Up @@ -81,7 +81,7 @@ def _convert_to_sql_plan(self, node: DataflowPlanNode) -> ConvertToSqlPlanResult
return result

def _render_sql(self, convert_to_sql_plan_result: ConvertToSqlPlanResult) -> SqlPlanRenderResult:
return self._sql_plan_renderer.render_sql_query_plan(convert_to_sql_plan_result.sql_plan)
return self._sql_plan_renderer.render_sql_plan(convert_to_sql_plan_result.sql_plan)

@override
def visit_write_to_result_data_table_node(self, node: WriteToResultDataTableNode) -> ConvertToExecutionPlanResult:
Expand Down
4 changes: 2 additions & 2 deletions metricflow/protocols/sql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from metricflow_semantics.sql.sql_bind_parameters import SqlBindParameterSet

from metricflow.data_table.mf_table import MetricFlowDataTable
from metricflow.sql.render.sql_plan_renderer import SqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import SqlPlanRenderer


class SqlEngine(Enum):
Expand Down Expand Up @@ -67,7 +67,7 @@ def sql_engine_type(self) -> SqlEngine:

@property
@abstractmethod
def sql_query_plan_renderer(self) -> SqlQueryPlanRenderer:
def sql_plan_renderer(self) -> SqlPlanRenderer:
"""Dialect-specific SQL query plan renderer used for converting MetricFlow's query plan to executable SQL.

This is bundled with the SqlClient partly as a convenenience for accessing a single instance of the renderer,
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import (
SqlAddTimeExpression,
SqlCastToTimestampExpression,
Expand Down Expand Up @@ -196,7 +196,7 @@ def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpres
)


class BigQuerySqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class BigQuerySqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the BigQuery engine."""

EXPR_RENDERER = BigQuerySqlExpressionRenderer()
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import SqlPercentileExpression, SqlPercentileFunctionType


Expand Down Expand Up @@ -68,7 +68,7 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR
)


class DatabricksSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class DatabricksSqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the Snowflake engine."""

EXPR_RENDERER = DatabricksSqlExpressionRenderer()
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/duckdb_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import (
SqlAddTimeExpression,
SqlGenerateUuidExpression,
Expand Down Expand Up @@ -106,7 +106,7 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR
)


class DuckDbSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class DuckDbSqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the DuckDB engine."""

EXPR_RENDERER = DuckDbSqlExpressionRenderer()
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import (
SqlAddTimeExpression,
SqlGenerateUuidExpression,
Expand Down Expand Up @@ -108,7 +108,7 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR
)


class PostgresSQLSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class PostgresSQLSqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the PostgreSQL engine."""

EXPR_RENDERER = PostgresSqlExpressionRenderer()
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import (
SqlExtractExpression,
SqlGenerateUuidExpression,
Expand Down Expand Up @@ -108,7 +108,7 @@ def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpres
)


class RedshiftSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class RedshiftSqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the Redshift engine."""

EXPR_RENDERER = RedshiftSqlExpressionRenderer()
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import (
SqlGenerateUuidExpression,
SqlPercentileExpression,
Expand Down Expand Up @@ -80,7 +80,7 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR
)


class SnowflakeSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class SnowflakeSqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the Snowflake engine."""

EXPR_RENDERER = SnowflakeSqlExpressionRenderer()
Expand Down
6 changes: 3 additions & 3 deletions metricflow/sql/render/sql_plan_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class SqlPlanRenderResult: # noqa: D101
bind_parameter_set: SqlBindParameterSet


class SqlQueryPlanRenderer(SqlPlanNodeVisitor[SqlPlanRenderResult], ABC):
class SqlPlanRenderer(SqlPlanNodeVisitor[SqlPlanRenderResult], ABC):
"""Renders SQL plans to a string."""

def _render_node(self, node: SqlPlanNode) -> SqlPlanRenderResult:
return node.accept(self)

def render_sql_query_plan(self, sql_query_plan: SqlPlan) -> SqlPlanRenderResult: # noqa: D102
def render_sql_plan(self, sql_query_plan: SqlPlan) -> SqlPlanRenderResult: # noqa: D102
return self._render_node(sql_query_plan.render_node)

@property
Expand All @@ -69,7 +69,7 @@ class StringJoinDescription:
on_condition_str: str


class DefaultSqlQueryPlanRenderer(SqlQueryPlanRenderer):
class DefaultSqlPlanRenderer(SqlPlanRenderer):
"""Renders an SQL plan following ANSI SQL."""

# The renderer that is used to render the SQL expressions.
Expand Down
4 changes: 2 additions & 2 deletions metricflow/sql/render/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
SqlExpressionRenderer,
SqlExpressionRenderResult,
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer
from metricflow.sql.sql_exprs import (
SqlAddTimeExpression,
SqlBetweenExpression,
Expand Down Expand Up @@ -135,7 +135,7 @@ def render_date_part(self, date_part: DatePart) -> str:
return date_part.value


class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
class TrinoSqlPlanRenderer(DefaultSqlPlanRenderer):
"""Plan renderer for the Trino engine."""

EXPR_RENDERER = TrinoSqlExpressionRenderer()
Expand Down
2 changes: 1 addition & 1 deletion metricflow/validation/data_warehouse_model_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def renderize(
)
sql_plan = conversion_result.sql_plan

rendered_plan = sql_client.sql_query_plan_renderer.render_sql_query_plan(sql_plan)
rendered_plan = sql_client.sql_plan_renderer.render_sql_plan(sql_plan)
return (rendered_plan.sql, rendered_plan.bind_parameter_set)

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions tests_metricflow/examples/test_node_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from metricflow.dataset.convert_semantic_model import SemanticModelToDataSetConverter
from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlPlanConverter
from metricflow.protocols.sql_client import SqlClient
from metricflow.sql.render.sql_plan_renderer import SqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import SqlPlanRenderer

logger = logging.getLogger(__name__)

Expand All @@ -44,7 +44,7 @@ def test_view_sql_generated_at_a_node(
column_association_resolver=DunderColumnAssociationResolver(simple_semantic_manifest_lookup),
semantic_manifest_lookup=simple_semantic_manifest_lookup,
)
sql_renderer: SqlQueryPlanRenderer = sql_client.sql_query_plan_renderer
sql_renderer: SqlPlanRenderer = sql_client.sql_plan_renderer
node_output_resolver = DataflowPlanNodeOutputDataSetResolver(
column_association_resolver=column_association_resolver,
semantic_manifest_lookup=simple_semantic_manifest_lookup,
Expand All @@ -58,7 +58,7 @@ def test_view_sql_generated_at_a_node(
dataflow_plan_node=read_source_node,
)
sql_plan_at_read_node = conversion_result.sql_plan
sql_at_read_node = sql_renderer.render_sql_query_plan(sql_plan_at_read_node).sql
sql_at_read_node = sql_renderer.render_sql_plan(sql_plan_at_read_node).sql
spec_set_at_read_node = node_output_resolver.get_output_data_set(read_source_node).instance_set.spec_set
logger.debug(LazyFormat(lambda: f"SQL generated at {read_source_node} is:\n\n{sql_at_read_node}"))
logger.debug(LazyFormat(lambda: f"Spec set at {read_source_node} is:\n\n{mf_pformat(spec_set_at_read_node)}"))
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_view_sql_generated_at_a_node(
dataflow_plan_node=filter_elements_node,
)
sql_plan_at_filter_elements_node = conversion_result.sql_plan
sql_at_filter_elements_node = sql_renderer.render_sql_query_plan(sql_plan_at_filter_elements_node).sql
sql_at_filter_elements_node = sql_renderer.render_sql_plan(sql_plan_at_filter_elements_node).sql
spec_set_at_filter_elements_node = node_output_resolver.get_output_data_set(
filter_elements_node
).instance_set.spec_set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def _get_sql_type(self, column_description: ColumnDescription) -> str:
elif column_type is int:
return "bigint"
elif column_type is float:
return self._sql_query_plan_renderer.expr_renderer.double_data_type
return self._sql_plan_renderer.expr_renderer.double_data_type
elif column_type is datetime.datetime:
return self._sql_query_plan_renderer.expr_renderer.timestamp_data_type
return self._sql_plan_renderer.expr_renderer.timestamp_data_type
else:
raise ValueError(f"Encountered unexpected {column_type=}!")

Expand Down
6 changes: 3 additions & 3 deletions tests_metricflow/fixtures/sql_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import pytest

from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlPlanConverter
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer, SqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import DefaultSqlPlanRenderer, SqlPlanRenderer
from tests_metricflow.fixtures.manifest_fixtures import MetricFlowEngineTestFixture, SemanticManifestSetup


@pytest.fixture
def default_sql_plan_renderer() -> SqlQueryPlanRenderer: # noqa: D103
return DefaultSqlQueryPlanRenderer()
def default_sql_plan_renderer() -> SqlPlanRenderer: # noqa: D103
return DefaultSqlPlanRenderer()


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def test_cumulative_metric_with_non_adjustable_filter(
) -> None:
"""Tests a cumulative metric with a filter that cannot be adjusted to ensure all data is included."""
# Handle ds expression based on engine to support Trino.
first_ds_expr = f"CAST('2020-03-15' AS {sql_client.sql_query_plan_renderer.expr_renderer.timestamp_data_type})"
second_ds_expr = f"CAST('2020-04-30' AS {sql_client.sql_query_plan_renderer.expr_renderer.timestamp_data_type})"
first_ds_expr = f"CAST('2020-03-15' AS {sql_client.sql_plan_renderer.expr_renderer.timestamp_data_type})"
second_ds_expr = f"CAST('2020-04-30' AS {sql_client.sql_plan_renderer.expr_renderer.timestamp_data_type})"
where_constraint = f"{{{{ TimeDimension('metric_time', 'day') }}}} = {first_ds_expr} or"
where_constraint += f" {{{{ TimeDimension('metric_time', 'day') }}}} = {second_ds_expr}"

Expand Down
Loading
Loading