Skip to content

Commit

Permalink
Add SQL rendering tests for no-metric queries
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 29, 2024
1 parent e796355 commit 5267413
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import pytest
from _pytest.fixtures import FixtureRequest
from dbt_semantic_interfaces.references import EntityReference
from dbt_semantic_interfaces.type_enums.date_part import DatePart
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
from metricflow_semantics.specs.metric_spec import MetricSpec
from metricflow_semantics.specs.query_spec import MetricFlowQuerySpec
from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration

from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder
Expand Down Expand Up @@ -99,3 +101,53 @@ def test_offset_window_with_date_part( # noqa: D103
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_sub_daily_metric_time( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
) -> None:
query_spec = MetricFlowQuerySpec(
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.MILLISECOND),),
)

render_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=dataflow_to_sql_converter,
sql_client=sql_client,
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_sub_daily_dimension( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
) -> None:
query_spec = MetricFlowQuerySpec(
time_dimension_specs=(
TimeDimensionSpec(
element_name="bio_added_ts",
time_granularity=TimeGranularity.SECOND,
entity_links=(EntityReference("user"),),
),
),
)

render_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=dataflow_to_sql_converter,
sql_client=sql_client,
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
-- Pass Only Elements: ['user__bio_added_ts__second',]
SELECT
subq_0.user__bio_added_ts__second
FROM (
-- Read Elements From Semantic Model 'users_ds_source'
SELECT
DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day
, DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week
, DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year
, EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy
, DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day
, DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week
, DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year
, EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy
, DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day
, DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week
, DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year
, EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy
, users_ds_source_src_28000.home_state
, DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond
, DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second
, DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute
, DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour
, DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day
, DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week
, DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year
, EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy
, DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second
, DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute
, DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour
, DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day
, DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week
, DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year
, EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy
, DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute
, DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour
, DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day
, DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week
, DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year
, EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy
, DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour
, DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day
, DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week
, DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year
, EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy
, DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day
, DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week
, DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year
, EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy
, DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day
, DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week
, DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year
, EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy
, DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day
, DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week
, DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year
, EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy
, users_ds_source_src_28000.home_state AS user__home_state
, DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond
, DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second
, DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute
, DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour
, DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day
, DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week
, DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year
, EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy
, DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second
, DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute
, DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour
, DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day
, DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week
, DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year
, EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy
, DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute
, DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour
, DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day
, DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week
, DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year
, EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy
, DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour
, DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day
, DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week
, DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month
, DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter
, DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year
, EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year
, EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter
, EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month
, EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day
, EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow
, EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy
, users_ds_source_src_28000.user_id AS user
FROM ***************************.dim_users users_ds_source_src_28000
) subq_0
GROUP BY
subq_0.user__bio_added_ts__second
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Read Elements From Semantic Model 'users_ds_source'
-- Pass Only Elements: ['user__bio_added_ts__second',]
SELECT
DATE_TRUNC('second', bio_added_ts) AS user__bio_added_ts__second
FROM ***************************.dim_users users_ds_source_src_28000
GROUP BY
DATE_TRUNC('second', bio_added_ts)
Loading

0 comments on commit 5267413

Please sign in to comment.