From 6dad059215745967ee14d95ff594e0d1bd16af0b Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 10 Dec 2024 12:31:02 -0800 Subject: [PATCH] Remove generic time delta language to differentiate from date add expr --- metricflow/sql/render/big_query.py | 2 +- metricflow/sql/render/duckdb_renderer.py | 2 +- metricflow/sql/render/expr_renderer.py | 4 +++- metricflow/sql/render/postgres.py | 2 +- metricflow/sql/render/trino.py | 2 +- metricflow/sql/sql_exprs.py | 8 +++++--- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/metricflow/sql/render/big_query.py b/metricflow/sql/render/big_query.py index bef39e99fc..0f1f989dbd 100644 --- a/metricflow/sql/render/big_query.py +++ b/metricflow/sql/render/big_query.py @@ -167,7 +167,7 @@ def visit_extract_expr(self, node: SqlExtractExpression) -> SqlExpressionRenderR ) @override - def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: + def visit_subtract_time_interval_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: """Render time delta for BigQuery, which requires ISO prefixing for the WEEK granularity value.""" column = node.arg.accept(self) diff --git a/metricflow/sql/render/duckdb_renderer.py b/metricflow/sql/render/duckdb_renderer.py index 6ff7fb9e7d..ed69b980ff 100644 --- a/metricflow/sql/render/duckdb_renderer.py +++ b/metricflow/sql/render/duckdb_renderer.py @@ -37,7 +37,7 @@ def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctio } @override - def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: + def visit_subtract_time_interval_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: """Render time delta expression for DuckDB, which requires slightly different syntax from other engines.""" arg_rendered = node.arg.accept(self) diff --git a/metricflow/sql/render/expr_renderer.py b/metricflow/sql/render/expr_renderer.py index 0fd9e81e86..f7e3fcf758 100644 --- a/metricflow/sql/render/expr_renderer.py +++ b/metricflow/sql/render/expr_renderer.py @@ -303,7 +303,9 @@ def render_date_part(self, date_part: DatePart) -> str: return date_part.value - def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: # noqa: D102 + def visit_subtract_time_interval_expr( + self, node: SqlSubtractTimeIntervalExpression + ) -> SqlExpressionRenderResult: # noqa: D102 arg_rendered = node.arg.accept(self) count = node.count diff --git a/metricflow/sql/render/postgres.py b/metricflow/sql/render/postgres.py index 36a1b687e9..121622c567 100644 --- a/metricflow/sql/render/postgres.py +++ b/metricflow/sql/render/postgres.py @@ -40,7 +40,7 @@ def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctio return {SqlPercentileFunctionType.CONTINUOUS, SqlPercentileFunctionType.DISCRETE} @override - def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: + def visit_subtract_time_interval_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: """Render time delta operations for PostgreSQL, which needs custom support for quarterly granularity.""" arg_rendered = node.arg.accept(self) diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py index 23bd65ab66..155fb6e466 100644 --- a/metricflow/sql/render/trino.py +++ b/metricflow/sql/render/trino.py @@ -45,7 +45,7 @@ def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpres ) @override - def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: + def visit_subtract_time_interval_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult: """Render time delta for Trino, require granularity in quotes and function name change.""" arg_rendered = node.arg.accept(self) diff --git a/metricflow/sql/sql_exprs.py b/metricflow/sql/sql_exprs.py index 62d8e96874..16671de048 100644 --- a/metricflow/sql/sql_exprs.py +++ b/metricflow/sql/sql_exprs.py @@ -210,7 +210,9 @@ def visit_extract_expr(self, node: SqlExtractExpression) -> VisitorOutputT: # n pass @abstractmethod - def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> VisitorOutputT: # noqa: D102 + def visit_subtract_time_interval_expr( + self, node: SqlSubtractTimeIntervalExpression + ) -> VisitorOutputT: # noqa: D102 pass @abstractmethod @@ -1285,11 +1287,11 @@ def requires_parenthesis(self) -> bool: # noqa: D102 return False def accept(self, visitor: SqlExpressionNodeVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 - return visitor.visit_time_delta_expr(self) + return visitor.visit_subtract_time_interval_expr(self) @property def description(self) -> str: # noqa: D102 - return "Time delta" + return "Subtract time interval" def rewrite( # noqa: D102 self,