From dd99776075547741a0bea2b8f01114fa512b7dcf Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 2 Nov 2023 14:06:04 -0700 Subject: [PATCH 1/3] Bug fix: CLI saved queries dropping order_by_names param --- metricflow/engine/metricflow_engine.py | 1 + metricflow/query/query_parser.py | 2 ++ .../test_cli.py/str/Snowflake/test_saved_query__cli_output.txt | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/metricflow/engine/metricflow_engine.py b/metricflow/engine/metricflow_engine.py index d866c6069a..ee791f400e 100644 --- a/metricflow/engine/metricflow_engine.py +++ b/metricflow/engine/metricflow_engine.py @@ -429,6 +429,7 @@ def _create_execution_plan(self, mf_query_request: MetricFlowQueryRequest) -> Me else None ), limit=mf_query_request.limit, + order_by_names=mf_query_request.order_by_names, order_by_parameters=mf_query_request.order_by, ) else: diff --git a/metricflow/query/query_parser.py b/metricflow/query/query_parser.py index 665295405c..cad5e9f0e1 100644 --- a/metricflow/query/query_parser.py +++ b/metricflow/query/query_parser.py @@ -188,6 +188,7 @@ def parse_and_validate_saved_query( saved_query_parameter: SavedQueryParameter, where_filter: Optional[WhereFilter], limit: Optional[int], + order_by_names: Optional[Sequence[str]], order_by_parameters: Optional[Sequence[OrderByQueryParameter]], ) -> MetricFlowQuerySpec: """Parse and validate a query using parameters from a pre-defined / saved query. @@ -210,6 +211,7 @@ def parse_and_validate_saved_query( ), where_constraint=merge_to_single_where_filter(PydanticWhereFilterIntersection(where_filters=where_filters)), limit=limit, + order_by_names=order_by_names, order_by=order_by_parameters, ) diff --git a/metricflow/test/snapshots/test_cli.py/str/Snowflake/test_saved_query__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Snowflake/test_saved_query__cli_output.txt index 26caef8593..ac707f6407 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Snowflake/test_saved_query__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Snowflake/test_saved_query__cli_output.txt @@ -6,6 +6,6 @@ | 2019-12-19 00:00:00 | 5 | 2 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | | 2020-01-01 00:00:00 | 4 | 2 | 1 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2020-01-02 00:00:00 | 4 | 3 | 3 | +| 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2020-01-03 00:00:00 | 5 | 1 | 0 | From 5041cc2d92cd8c574731e651034d950e55068d82 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 2 Nov 2023 14:11:01 -0700 Subject: [PATCH 2/3] Changelog --- .changes/unreleased/Fixes-20231102-141010.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20231102-141010.yaml diff --git a/.changes/unreleased/Fixes-20231102-141010.yaml b/.changes/unreleased/Fixes-20231102-141010.yaml new file mode 100644 index 0000000000..17134f1329 --- /dev/null +++ b/.changes/unreleased/Fixes-20231102-141010.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: The --order param was being dropped from CLI saved queries. +time: 2023-11-02T14:10:10.028618-07:00 +custom: + Author: courtneyholcomb + Issue: "835" From 2069a42ca4e67e699001e32224b99ecf30b26e88 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 2 Nov 2023 14:20:24 -0700 Subject: [PATCH 3/3] Update snapshots for all engines --- metricflow/test/generate_snapshots.py | 2 +- .../str/BigQuery/test_saved_query__cli_output.txt | 8 ++++---- .../test_saved_query_with_limit__cli_output.txt | 4 ++-- .../test_saved_query_with_where__cli_output.txt | 4 ++-- .../str/Databricks/test_saved_query__cli_output.txt | 10 +++++----- .../test_saved_query_with_limit__cli_output.txt | 4 ++-- .../test_saved_query_with_where__cli_output.txt | 4 ++-- .../str/Postgres/test_saved_query__cli_output.txt | 8 ++++---- .../test_saved_query_with_limit__cli_output.txt | 4 ++-- .../test_saved_query_with_where__cli_output.txt | 2 +- .../str/Redshift/test_saved_query__cli_output.txt | 12 ++++++------ .../test_saved_query_with_limit__cli_output.txt | 6 +++--- .../test_saved_query_with_where__cli_output.txt | 6 +++--- 13 files changed, 37 insertions(+), 37 deletions(-) diff --git a/metricflow/test/generate_snapshots.py b/metricflow/test/generate_snapshots.py index 642eebd890..5b74236428 100644 --- a/metricflow/test/generate_snapshots.py +++ b/metricflow/test/generate_snapshots.py @@ -138,7 +138,7 @@ def run_tests(test_configuration: MetricFlowTestConfiguration) -> None: # noqa: f"hatch -v run {hatch_env}:pytest -x -vv -n 4 " f"--overwrite-snapshots" f"{' --use-persistent-source-schema' if use_persistent_source_schema else ''}" - f"-m '{SQL_ENGINE_SNAPSHOT_MARKER_NAME}' " + f" -m '{SQL_ENGINE_SNAPSHOT_MARKER_NAME}' " f"{TEST_DIRECTORY}" ) else: diff --git a/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query__cli_output.txt index 30e79e45b0..138d8b140e 100644 --- a/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query__cli_output.txt @@ -1,11 +1,11 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| | 2019-12-01 00:00:00 | 5 | 1 | 0 | -| 2020-01-01 00:00:00 | 4 | 2 | 1 | -| 2020-01-02 00:00:00 | 4 | 3 | 3 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2019-12-18 00:00:00 | 4 | 4 | 2 | -| 2020-01-03 00:00:00 | 5 | 1 | 0 | | 2019-12-19 00:00:00 | 4 | 6 | 6 | | 2019-12-19 00:00:00 | 5 | 2 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | +| 2020-01-01 00:00:00 | 4 | 2 | 1 | +| 2020-01-02 00:00:00 | 4 | 3 | 3 | +| 2020-01-02 00:00:00 | 5 | 1 | 0 | +| 2020-01-03 00:00:00 | 5 | 1 | 0 | diff --git a/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_limit__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_limit__cli_output.txt index c2123f8ea1..313b03eda8 100644 --- a/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_limit__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_limit__cli_output.txt @@ -1,5 +1,5 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| | 2019-12-01 00:00:00 | 5 | 1 | 0 | -| 2020-01-01 00:00:00 | 4 | 2 | 1 | -| 2020-01-02 00:00:00 | 4 | 3 | 3 | +| 2019-12-18 00:00:00 | 4 | 4 | 2 | +| 2019-12-19 00:00:00 | 4 | 6 | 6 | diff --git a/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_where__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_where__cli_output.txt index cce16e9717..fc66131bbc 100644 --- a/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_where__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/BigQuery/test_saved_query_with_where__cli_output.txt @@ -1,7 +1,7 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| | 2019-12-01 00:00:00 | 5 | 1 | 0 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | -| 2020-01-03 00:00:00 | 5 | 1 | 0 | | 2019-12-19 00:00:00 | 5 | 2 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | +| 2020-01-02 00:00:00 | 5 | 1 | 0 | +| 2020-01-03 00:00:00 | 5 | 1 | 0 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query__cli_output.txt index 058e8f0608..d1e31bc2b6 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query__cli_output.txt @@ -1,11 +1,11 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------------|---------------------------:|-----------:|-------------------:| -| 2020-01-02 00:00:00+00:00 | 5 | 1 | 0 | -| 2019-12-19 00:00:00+00:00 | 4 | 6 | 6 | | 2019-12-01 00:00:00+00:00 | 5 | 1 | 0 | -| 2019-12-20 00:00:00+00:00 | 5 | 2 | 0 | -| 2019-12-19 00:00:00+00:00 | 5 | 2 | 0 | | 2019-12-18 00:00:00+00:00 | 4 | 4 | 2 | +| 2019-12-19 00:00:00+00:00 | 4 | 6 | 6 | +| 2019-12-19 00:00:00+00:00 | 5 | 2 | 0 | +| 2019-12-20 00:00:00+00:00 | 5 | 2 | 0 | +| 2020-01-01 00:00:00+00:00 | 4 | 2 | 1 | | 2020-01-02 00:00:00+00:00 | 4 | 3 | 3 | +| 2020-01-02 00:00:00+00:00 | 5 | 1 | 0 | | 2020-01-03 00:00:00+00:00 | 5 | 1 | 0 | -| 2020-01-01 00:00:00+00:00 | 4 | 2 | 1 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_limit__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_limit__cli_output.txt index 53ccdfa167..7d7b0f5f46 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_limit__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_limit__cli_output.txt @@ -1,5 +1,5 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------------|---------------------------:|-----------:|-------------------:| -| 2020-01-02 00:00:00+00:00 | 5 | 1 | 0 | -| 2019-12-19 00:00:00+00:00 | 4 | 6 | 6 | | 2019-12-01 00:00:00+00:00 | 5 | 1 | 0 | +| 2019-12-18 00:00:00+00:00 | 4 | 4 | 2 | +| 2019-12-19 00:00:00+00:00 | 4 | 6 | 6 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_where__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_where__cli_output.txt index 06daf91ce8..1f575ac83d 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_where__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Databricks/test_saved_query_with_where__cli_output.txt @@ -1,7 +1,7 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------------|---------------------------:|-----------:|-------------------:| -| 2020-01-02 00:00:00+00:00 | 5 | 1 | 0 | | 2019-12-01 00:00:00+00:00 | 5 | 1 | 0 | -| 2019-12-20 00:00:00+00:00 | 5 | 2 | 0 | | 2019-12-19 00:00:00+00:00 | 5 | 2 | 0 | +| 2019-12-20 00:00:00+00:00 | 5 | 2 | 0 | +| 2020-01-02 00:00:00+00:00 | 5 | 1 | 0 | | 2020-01-03 00:00:00+00:00 | 5 | 1 | 0 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query__cli_output.txt index 5746951b2c..138d8b140e 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query__cli_output.txt @@ -1,11 +1,11 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| -| 2019-12-19 00:00:00 | 4 | 6 | 6 | +| 2019-12-01 00:00:00 | 5 | 1 | 0 | | 2019-12-18 00:00:00 | 4 | 4 | 2 | +| 2019-12-19 00:00:00 | 4 | 6 | 6 | | 2019-12-19 00:00:00 | 5 | 2 | 0 | -| 2020-01-02 00:00:00 | 4 | 3 | 3 | -| 2019-12-01 00:00:00 | 5 | 1 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2020-01-01 00:00:00 | 4 | 2 | 1 | +| 2020-01-02 00:00:00 | 4 | 3 | 3 | +| 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2020-01-03 00:00:00 | 5 | 1 | 0 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_limit__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_limit__cli_output.txt index 099fe41d85..313b03eda8 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_limit__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_limit__cli_output.txt @@ -1,5 +1,5 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| -| 2019-12-19 00:00:00 | 4 | 6 | 6 | +| 2019-12-01 00:00:00 | 5 | 1 | 0 | | 2019-12-18 00:00:00 | 4 | 4 | 2 | -| 2019-12-19 00:00:00 | 5 | 2 | 0 | +| 2019-12-19 00:00:00 | 4 | 6 | 6 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_where__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_where__cli_output.txt index 7ae58549f0..fc66131bbc 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_where__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Postgres/test_saved_query_with_where__cli_output.txt @@ -1,7 +1,7 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| -| 2019-12-19 00:00:00 | 5 | 2 | 0 | | 2019-12-01 00:00:00 | 5 | 1 | 0 | +| 2019-12-19 00:00:00 | 5 | 2 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | | 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2020-01-03 00:00:00 | 5 | 1 | 0 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query__cli_output.txt index beccedd97c..138d8b140e 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query__cli_output.txt @@ -1,11 +1,11 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| -| 2019-12-19 00:00:00 | 5 | 2 | 0 | +| 2019-12-01 00:00:00 | 5 | 1 | 0 | +| 2019-12-18 00:00:00 | 4 | 4 | 2 | | 2019-12-19 00:00:00 | 4 | 6 | 6 | -| 2020-01-03 00:00:00 | 5 | 1 | 0 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | +| 2019-12-19 00:00:00 | 5 | 2 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | -| 2019-12-01 00:00:00 | 5 | 1 | 0 | -| 2020-01-02 00:00:00 | 4 | 3 | 3 | | 2020-01-01 00:00:00 | 4 | 2 | 1 | -| 2019-12-18 00:00:00 | 4 | 4 | 2 | +| 2020-01-02 00:00:00 | 4 | 3 | 3 | +| 2020-01-02 00:00:00 | 5 | 1 | 0 | +| 2020-01-03 00:00:00 | 5 | 1 | 0 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_limit__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_limit__cli_output.txt index f5456036e3..313b03eda8 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_limit__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_limit__cli_output.txt @@ -1,5 +1,5 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| -| 2020-01-03 00:00:00 | 5 | 1 | 0 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | -| 2019-12-20 00:00:00 | 5 | 2 | 0 | +| 2019-12-01 00:00:00 | 5 | 1 | 0 | +| 2019-12-18 00:00:00 | 4 | 4 | 2 | +| 2019-12-19 00:00:00 | 4 | 6 | 6 | diff --git a/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_where__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_where__cli_output.txt index 44f958aec2..fc66131bbc 100644 --- a/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_where__cli_output.txt +++ b/metricflow/test/snapshots/test_cli.py/str/Redshift/test_saved_query_with_where__cli_output.txt @@ -1,7 +1,7 @@ | metric_time__day | listing__capacity_latest | bookings | instant_bookings | |:--------------------|---------------------------:|-----------:|-------------------:| +| 2019-12-01 00:00:00 | 5 | 1 | 0 | | 2019-12-19 00:00:00 | 5 | 2 | 0 | -| 2020-01-03 00:00:00 | 5 | 1 | 0 | -| 2020-01-02 00:00:00 | 5 | 1 | 0 | | 2019-12-20 00:00:00 | 5 | 2 | 0 | -| 2019-12-01 00:00:00 | 5 | 1 | 0 | +| 2020-01-02 00:00:00 | 5 | 1 | 0 | +| 2020-01-03 00:00:00 | 5 | 1 | 0 |