diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index d5c33c13b0..be1a89bdca 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -1252,6 +1252,7 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet parent_alias = self._next_unique_table_alias() if node.use_custom_agg_time_dimension: + # TODO: do we need the `requested_agg_time_dimension_specs` property anymore? agg_time_dimension = node.requested_agg_time_dimension_specs[0] agg_time_element_name = agg_time_dimension.element_name agg_time_entity_links: Tuple[EntityReference, ...] = agg_time_dimension.entity_links @@ -1300,6 +1301,16 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet # Select all instances from the parent data set, EXCEPT the requested agg_time_dimension. # The agg_time_dimension will be selected from the time spine data set. + time_dimensions_to_select_from_parent: Tuple[TimeDimensionInstance, ...] = () + time_dimensions_to_select_from_time_spine: Tuple[TimeDimensionInstance, ...] = () + for time_dimension_instance in parent_data_set.instance_set.time_dimension_instances: + if ( + time_dimension_instance.spec.element_name == agg_time_element_name + and time_dimension_instance.spec.entity_links == agg_time_entity_links + ): + time_dimensions_to_select_from_time_spine += (time_dimension_instance,) + else: + time_dimensions_to_select_from_parent += (time_dimension_instance,) parent_instance_set = InstanceSet( measure_instances=parent_data_set.instance_set.measure_instances, dimension_instances=parent_data_set.instance_set.dimension_instances, @@ -1335,14 +1346,17 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet time_spine_select_columns = [] time_spine_dim_instances = [] where: Optional[SqlExpressionNode] = None - for requested_time_dimension_spec in node.requested_agg_time_dimension_specs: + for time_dimension_instance in time_dimensions_to_select_from_time_spine: + time_dimension_spec = time_dimension_instance.spec + # Apply granularity to time spine column select expression. - if requested_time_dimension_spec.time_granularity == time_spine_dim_instance.spec.time_granularity: + if time_dimension_spec.time_granularity == time_spine_dim_instance.spec.time_granularity: select_expr: SqlExpressionNode = time_spine_column_select_expr else: select_expr = SqlDateTruncExpression( - time_granularity=requested_time_dimension_spec.time_granularity, arg=time_spine_column_select_expr + time_granularity=time_dimension_spec.time_granularity, arg=time_spine_column_select_expr ) + # Does this work if multiple are selected? if node.offset_to_grain: # Filter down to one row per granularity period new_filter = SqlComparisonExpression( @@ -1353,13 +1367,13 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet else: where = SqlLogicalExpression(operator=SqlLogicalOperator.OR, args=(where, new_filter)) # Apply date_part to time spine column select expression. - if requested_time_dimension_spec.date_part: - select_expr = SqlExtractExpression(date_part=requested_time_dimension_spec.date_part, arg=select_expr) + if time_dimension_spec.date_part: + select_expr = SqlExtractExpression(date_part=time_dimension_spec.date_part, arg=select_expr) time_dim_spec = TimeDimensionSpec( element_name=time_spine_dim_instance.spec.element_name, entity_links=time_spine_dim_instance.spec.entity_links, - time_granularity=requested_time_dimension_spec.time_granularity, - date_part=requested_time_dimension_spec.date_part, + time_granularity=time_dimension_spec.time_granularity, + date_part=time_dimension_spec.date_part, aggregation_state=time_spine_dim_instance.spec.aggregation_state, ) time_spine_dim_instance = TimeDimensionInstance( diff --git a/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py b/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py index 01494ab5b7..83553e59fd 100644 --- a/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py +++ b/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py @@ -5,6 +5,7 @@ import pytest from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilter from dbt_semantic_interfaces.naming.keywords import METRIC_TIME_ELEMENT_NAME from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity @@ -1117,4 +1118,36 @@ def test_min_max_only_time_year( ) +@pytest.mark.sql_engine_snapshot +def test_offset_metric_filter_and_query_have_different_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset metrics is queried with one granularity and filtered by a different one.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("booking_fees_last_week_per_booker_this_week",), + group_by_names=("metric_time__month",), + where_constraint=PydanticWhereFilter( + where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01' ") + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + assert_plan_snapshot_text_equal( + request=request, + mf_test_session_state=mf_test_session_state, + plan=dataflow_plan, + plan_snapshot_text=dataflow_plan.text_structure(), + ) + + display_graph_if_requested( + request=request, + mf_test_session_state=mf_test_session_state, + dag_graph=dataflow_plan, + ) + + # TODO: add test for min max metric_time (various granularities) when supported diff --git a/metricflow/test/query_rendering/test_derived_metric_rendering.py b/metricflow/test/query_rendering/test_derived_metric_rendering.py index 5fc8f52bd5..b28abeadc2 100644 --- a/metricflow/test/query_rendering/test_derived_metric_rendering.py +++ b/metricflow/test/query_rendering/test_derived_metric_rendering.py @@ -6,7 +6,9 @@ import pytest from _pytest.fixtures import FixtureRequest -from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilter +from dbt_semantic_interfaces.implementations.filters.where_filter import ( + PydanticWhereFilter, +) from dbt_semantic_interfaces.naming.keywords import METRIC_TIME_ELEMENT_NAME from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder @@ -701,3 +703,38 @@ def test_nested_fill_nulls_without_time_spine_multi_metric( # noqa: D sql_client=sql_client, node=dataflow_plan.sink_output_nodes[0].parent_node, ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_metric_filter_and_query_have_different_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset metrics is queried with one granularity and filtered by a different one.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("booking_fees_last_week_per_booker_this_week",), + group_by_names=("metric_time__month",), + where_constraint=PydanticWhereFilter( + where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01' ") + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + print(dataflow_plan) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) + + +# Dataflow plan is constructed properly +# Issue happens in JoinToTimeSpineNdoe +# we remove that column too soon? is that in DFP or DF to SQL? diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_metric_filter_and_query_have_different_granularities__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_metric_filter_and_query_have_different_granularities__dfp_0.xml new file mode 100644 index 0000000000..23dd3b71f7 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index b2c5912232..a366dbfa75 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 243d2d1af4..c024f5be49 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index 36c1caf422..3f375c31cf 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month @@ -532,6 +542,23 @@ FROM ( ) subq_6 ON DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_7.metric_time__day) = subq_7.metric_time__day + ) OR ( + DATE_TRUNC('month', subq_7.metric_time__day) = subq_7.metric_time__day + ) + ) OR ( + DATE_TRUNC('quarter', subq_7.metric_time__day) = subq_7.metric_time__day + ) + ) OR ( + DATE_TRUNC('year', subq_7.metric_time__day) = subq_7.metric_time__day + ) + ) OR ( + DATE_TRUNC('day', subq_7.metric_time__day) = subq_7.metric_time__day + ) ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index aa15f38c06..0ff32bcfd5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -45,6 +45,23 @@ FROM ( ) subq_20 ON DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_22.ds) = subq_22.ds + ) OR ( + DATE_TRUNC('month', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('quarter', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('year', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('day', subq_22.ds) = subq_22.ds + ) GROUP BY subq_22.ds ) subq_26 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 328247b22e..f05cbf97eb 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month @@ -532,7 +542,23 @@ FROM ( ) subq_6 ON DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - WHERE DATE_TRUNC('week', subq_7.metric_time__day) = subq_7.metric_time__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_7.metric_time__day) = subq_7.metric_time__day + ) OR ( + DATE_TRUNC('month', subq_7.metric_time__day) = subq_7.metric_time__day + ) + ) OR ( + DATE_TRUNC('quarter', subq_7.metric_time__day) = subq_7.metric_time__day + ) + ) OR ( + DATE_TRUNC('year', subq_7.metric_time__day) = subq_7.metric_time__day + ) + ) OR ( + DATE_TRUNC('day', subq_7.metric_time__day) = subq_7.metric_time__day + ) ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 808ffc27a1..8f66d6a7cd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -45,7 +45,23 @@ FROM ( ) subq_20 ON DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day - WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_22.ds) = subq_22.ds + ) OR ( + DATE_TRUNC('month', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('quarter', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('year', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('day', subq_22.ds) = subq_22.ds + ) GROUP BY DATE_TRUNC('week', subq_22.ds) ) subq_26 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index e258c3e3e1..a740353bfc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 1f27b4fb18..aed26331bc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 23552032b5..596f56509a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month @@ -317,6 +327,23 @@ FROM ( ) subq_1 ON DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_2.metric_time__day) = subq_2.metric_time__day + ) OR ( + DATE_TRUNC('month', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) OR ( + DATE_TRUNC('quarter', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) OR ( + DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) OR ( + DATE_TRUNC('day', subq_2.metric_time__day) = subq_2.metric_time__day + ) ) subq_4 ) subq_5 GROUP BY @@ -342,6 +369,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 0c68fbd1a2..92e9ae7868 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -27,6 +27,23 @@ FROM ( ) subq_18 ON DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_20.ds) = subq_20.ds + ) OR ( + DATE_TRUNC('month', subq_20.ds) = subq_20.ds + ) + ) OR ( + DATE_TRUNC('quarter', subq_20.ds) = subq_20.ds + ) + ) OR ( + DATE_TRUNC('year', subq_20.ds) = subq_20.ds + ) + ) OR ( + DATE_TRUNC('day', subq_20.ds) = subq_20.ds + ) GROUP BY subq_20.ds ) subq_24 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index ceb6876814..8d1ccac951 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month @@ -317,7 +327,23 @@ FROM ( ) subq_1 ON DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_2.metric_time__day) = subq_2.metric_time__day + ) OR ( + DATE_TRUNC('month', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) OR ( + DATE_TRUNC('quarter', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) OR ( + DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) OR ( + DATE_TRUNC('day', subq_2.metric_time__day) = subq_2.metric_time__day + ) ) subq_4 ) subq_5 GROUP BY @@ -342,7 +368,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 76ccda3ffe..f8b3fc7ab3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -27,7 +27,23 @@ FROM ( ) subq_18 ON DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_20.ds) = subq_20.ds + ) OR ( + DATE_TRUNC('month', subq_20.ds) = subq_20.ds + ) + ) OR ( + DATE_TRUNC('quarter', subq_20.ds) = subq_20.ds + ) + ) OR ( + DATE_TRUNC('year', subq_20.ds) = subq_20.ds + ) + ) OR ( + DATE_TRUNC('day', subq_20.ds) = subq_20.ds + ) GROUP BY DATE_TRUNC('year', subq_20.ds) ) subq_24 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index bc137eca65..30e762031e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_8.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_8.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_8.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_8.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_8.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_8.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_8.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_8.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_8.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_8.metric_time__day) AS metric_time__extract_doy , subq_7.ds__day AS ds__day , subq_7.ds__week AS ds__week , subq_7.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql index 06eead6220..bd4671a650 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql index aa7ea1e0dd..e60b7053b8 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_2.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql index 9c53e70d60..6dd8959273 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index d5dc31c413..f34d48abce 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql index b999d7b87f..f75f60c01d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql index c0ba874670..06ad04b135 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql index 2bd4dfdf68..342e0c87d5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..ee6af42a72 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy + , subq_1.ds__day AS ds__day + , subq_1.ds__week AS ds__week + , subq_1.ds__month AS ds__month + , subq_1.ds__quarter AS ds__quarter + , subq_1.ds__year AS ds__year + , subq_1.ds__extract_year AS ds__extract_year + , subq_1.ds__extract_quarter AS ds__extract_quarter + , subq_1.ds__extract_month AS ds__extract_month + , subq_1.ds__extract_day AS ds__extract_day + , subq_1.ds__extract_dow AS ds__extract_dow + , subq_1.ds__extract_doy AS ds__extract_doy + , subq_1.ds_partitioned__day AS ds_partitioned__day + , subq_1.ds_partitioned__week AS ds_partitioned__week + , subq_1.ds_partitioned__month AS ds_partitioned__month + , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_1.ds_partitioned__year AS ds_partitioned__year + , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_1.paid_at__day AS paid_at__day + , subq_1.paid_at__week AS paid_at__week + , subq_1.paid_at__month AS paid_at__month + , subq_1.paid_at__quarter AS paid_at__quarter + , subq_1.paid_at__year AS paid_at__year + , subq_1.paid_at__extract_year AS paid_at__extract_year + , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_1.paid_at__extract_month AS paid_at__extract_month + , subq_1.paid_at__extract_day AS paid_at__extract_day + , subq_1.paid_at__extract_dow AS paid_at__extract_dow + , subq_1.paid_at__extract_doy AS paid_at__extract_doy + , subq_1.booking__ds__day AS booking__ds__day + , subq_1.booking__ds__week AS booking__ds__week + , subq_1.booking__ds__month AS booking__ds__month + , subq_1.booking__ds__quarter AS booking__ds__quarter + , subq_1.booking__ds__year AS booking__ds__year + , subq_1.booking__ds__extract_year AS booking__ds__extract_year + , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_1.booking__ds__extract_month AS booking__ds__extract_month + , subq_1.booking__ds__extract_day AS booking__ds__extract_day + , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_1.booking__paid_at__day AS booking__paid_at__day + , subq_1.booking__paid_at__week AS booking__paid_at__week + , subq_1.booking__paid_at__month AS booking__paid_at__month + , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_1.booking__paid_at__year AS booking__paid_at__year + , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_1.listing AS listing + , subq_1.guest AS guest + , subq_1.host AS host + , subq_1.booking__listing AS booking__listing + , subq_1.booking__guest AS booking__guest + , subq_1.booking__host AS booking__host + , subq_1.is_instant AS is_instant + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings + , subq_1.instant_bookings AS instant_bookings + , subq_1.booking_value AS booking_value + , subq_1.max_booking_value AS max_booking_value + , subq_1.min_booking_value AS min_booking_value + , subq_1.bookers AS bookers + , subq_1.average_booking_value AS average_booking_value + , subq_1.referred_bookings AS referred_bookings + , subq_1.median_booking_value AS median_booking_value + , subq_1.booking_value_p99 AS booking_value_p99 + , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + FROM ( + -- Time Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..0def7f4cf6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + subq_21.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql index 0c969a8f90..07f3908080 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month @@ -532,6 +542,23 @@ FROM ( ) subq_6 ON DATE_TRUNC('month', subq_7.booking__ds__day) = subq_6.booking__ds__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_7.booking__ds__day) = subq_7.booking__ds__day + ) OR ( + DATE_TRUNC('month', subq_7.booking__ds__day) = subq_7.booking__ds__day + ) + ) OR ( + DATE_TRUNC('quarter', subq_7.booking__ds__day) = subq_7.booking__ds__day + ) + ) OR ( + DATE_TRUNC('year', subq_7.booking__ds__day) = subq_7.booking__ds__day + ) + ) OR ( + DATE_TRUNC('day', subq_7.booking__ds__day) = subq_7.booking__ds__day + ) ) subq_9 ) subq_10 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 87a86d9826..90042b7eee 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql @@ -45,6 +45,23 @@ FROM ( ) subq_20 ON DATE_TRUNC('month', subq_22.ds) = subq_20.booking__ds__day + WHERE ( + ( + ( + ( + DATE_TRUNC('week', subq_22.ds) = subq_22.ds + ) OR ( + DATE_TRUNC('month', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('quarter', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('year', subq_22.ds) = subq_22.ds + ) + ) OR ( + DATE_TRUNC('day', subq_22.ds) = subq_22.ds + ) GROUP BY subq_22.ds ) subq_26 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql index 49f6b12f7c..d4128818f7 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql index ad4182373a..b17e12fe70 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 8e8f2d15e5..62ea44b0ec 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index c913c089ee..63fb598198 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month