Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Sep 12, 2023
1 parent b146895 commit 64164d9
Show file tree
Hide file tree
Showing 375 changed files with 25,409 additions and 25,405 deletions.
12 changes: 12 additions & 0 deletions metricflow/sql/render/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SqlTimeDeltaExpression,
)
from metricflow.sql.sql_plan import SqlSelectColumn
from metricflow.time.date_part import DatePart


class BigQuerySqlExpressionRenderer(DefaultSqlExpressionRenderer):
Expand Down Expand Up @@ -129,6 +130,17 @@ def visit_date_trunc_expr(self, node: SqlDateTruncExpression) -> SqlExpressionRe
bind_parameters=arg_rendered.bind_parameters,
)

@override
def render_date_part(self, date_part: DatePart) -> str:
if date_part == DatePart.DOY:
return "DAYOFYEAR"
if date_part == DatePart.DOW:
return "DAYOFWEEK"
if date_part == DatePart.WEEK:
return "ISOWEEK"

return super().render_date_part(date_part)

@override
def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRenderResult:
"""Render time delta for BigQuery, which requires ISO prefixing for the WEEK granularity value."""
Expand Down
8 changes: 0 additions & 8 deletions metricflow/sql/render/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
from metricflow.sql.sql_exprs import SqlPercentileExpression, SqlPercentileFunctionType
from metricflow.time.date_part import DatePart


class DatabricksSqlExpressionRenderer(DefaultSqlExpressionRenderer):
Expand Down Expand Up @@ -57,13 +56,6 @@ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionR
bind_parameters=params,
)

@override
def render_date_part(self, date_part: DatePart) -> str:
if date_part == DatePart.DAYOFYEAR:
return "DOY"

return super().render_date_part(date_part)


class DatabricksSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
"""Plan renderer for the Snowflake engine."""
Expand Down
2 changes: 1 addition & 1 deletion metricflow/sql/render/expr_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def visit_extract_expr(self, node: SqlExtractExpression) -> SqlExpressionRenderR

def render_date_part(self, date_part: DatePart) -> str:
"""Render DATE PART for an EXTRACT expression."""
return date_part.name
return date_part.value

def visit_time_delta_expr(self, node: SqlTimeDeltaExpression) -> SqlExpressionRenderResult: # noqa: D
arg_rendered = node.arg.accept(self)
Expand Down
24 changes: 12 additions & 12 deletions metricflow/test/dataset/test_convert_semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def test_convert_table_semantic_model_without_measures( # noqa: D
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DAY
),
TimeDimensionSpec(
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DAYOFWEEK
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DOW
),
TimeDimensionSpec(
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DAYOFYEAR
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DOY
),
TimeDimensionSpec(
element_name="ds",
Expand Down Expand Up @@ -130,13 +130,13 @@ def test_convert_table_semantic_model_without_measures( # noqa: D
element_name="ds",
entity_links=(EntityReference(element_name="user"),),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFWEEK,
date_part=DatePart.DOW,
),
TimeDimensionSpec(
element_name="ds",
entity_links=(EntityReference(element_name="user"),),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFYEAR,
date_part=DatePart.DOY,
),
),
)
Expand Down Expand Up @@ -205,10 +205,10 @@ def test_convert_table_semantic_model_with_measures( # noqa: D
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DAY
),
TimeDimensionSpec(
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DAYOFWEEK
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DOW
),
TimeDimensionSpec(
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DAYOFYEAR
element_name="ds", entity_links=(), time_granularity=TimeGranularity.DAY, date_part=DatePart.DOY
),
TimeDimensionSpec(element_name="ds_partitioned", entity_links=(), time_granularity=TimeGranularity.DAY),
TimeDimensionSpec(element_name="ds_partitioned", entity_links=(), time_granularity=TimeGranularity.WEEK),
Expand Down Expand Up @@ -249,13 +249,13 @@ def test_convert_table_semantic_model_with_measures( # noqa: D
element_name="ds_partitioned",
entity_links=(),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFWEEK,
date_part=DatePart.DOW,
),
TimeDimensionSpec(
element_name="ds_partitioned",
entity_links=(),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFYEAR,
date_part=DatePart.DOY,
),
TimeDimensionSpec(
element_name="ds",
Expand Down Expand Up @@ -316,13 +316,13 @@ def test_convert_table_semantic_model_with_measures( # noqa: D
element_name="ds",
entity_links=(EntityReference(element_name="verification"),),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFWEEK,
date_part=DatePart.DOW,
),
TimeDimensionSpec(
element_name="ds",
entity_links=(EntityReference(element_name="verification"),),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFYEAR,
date_part=DatePart.DOY,
),
TimeDimensionSpec(
element_name="ds_partitioned",
Expand Down Expand Up @@ -383,13 +383,13 @@ def test_convert_table_semantic_model_with_measures( # noqa: D
element_name="ds_partitioned",
entity_links=(EntityReference(element_name="verification"),),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFWEEK,
date_part=DatePart.DOW,
),
TimeDimensionSpec(
element_name="ds_partitioned",
entity_links=(EntityReference(element_name="verification"),),
time_granularity=TimeGranularity.DAY,
date_part=DatePart.DAYOFYEAR,
date_part=DatePart.DOY,
),
),
)
Expand Down
40 changes: 20 additions & 20 deletions metricflow/test/generate_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,30 @@ class MetricFlowTestCredentialSetForAllEngines(FrozenBaseModel): # noqa: D
@property
def as_configurations(self) -> Sequence[MetricFlowTestConfiguration]: # noqa: D
return (
MetricFlowTestConfiguration(
engine=SqlEngine.DUCKDB,
credential_set=self.duck_db,
),
MetricFlowTestConfiguration(
engine=SqlEngine.REDSHIFT,
credential_set=self.redshift,
),
MetricFlowTestConfiguration(
engine=SqlEngine.SNOWFLAKE,
credential_set=self.snowflake,
),
# MetricFlowTestConfiguration(
# engine=SqlEngine.DUCKDB,
# credential_set=self.duck_db,
# ),
# MetricFlowTestConfiguration(
# engine=SqlEngine.REDSHIFT,
# credential_set=self.redshift,
# ),
# MetricFlowTestConfiguration(
# engine=SqlEngine.SNOWFLAKE,
# credential_set=self.snowflake,
# ),
MetricFlowTestConfiguration(
engine=SqlEngine.BIGQUERY,
credential_set=self.big_query,
),
MetricFlowTestConfiguration(
engine=SqlEngine.DATABRICKS,
credential_set=self.databricks,
),
MetricFlowTestConfiguration(
engine=SqlEngine.POSTGRES,
credential_set=self.postgres,
),
# MetricFlowTestConfiguration(
# engine=SqlEngine.DATABRICKS,
# credential_set=self.databricks,
# ),
# MetricFlowTestConfiguration(
# engine=SqlEngine.POSTGRES,
# credential_set=self.postgres,
# ),
)


Expand Down
8 changes: 4 additions & 4 deletions metricflow/test/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,15 +1067,15 @@ integration_test:
SELECT
SUM(1) AS bookings
, {{ render_extract("ds", DatePart.QUARTER) }} AS metric_time__extract_quarter
, {{ render_extract("ds", DatePart.DAYOFWEEK) }} AS metric_time__extract_dow
, {{ render_extract("ds", DatePart.DAYOFYEAR) }} AS metric_time__extract_doy
, {{ render_extract("ds", DatePart.DOW) }} AS metric_time__extract_dow
, {{ render_extract("ds", DatePart.DOY) }} AS metric_time__extract_doy
, {{ render_extract("ds", DatePart.DAY) }} AS metric_time__extract_day
, {{ render_extract("ds", DatePart.WEEK) }} AS metric_time__extract_week
FROM {{ source_schema }}.fct_bookings
GROUP BY
{{ render_extract("ds", DatePart.QUARTER) }}
, {{ render_extract("ds", DatePart.DAYOFWEEK) }}
, {{ render_extract("ds", DatePart.DAYOFYEAR) }}
, {{ render_extract("ds", DatePart.DOW) }}
, {{ render_extract("ds", DatePart.DOY) }}
, {{ render_extract("ds", DatePart.DAY) }}
, {{ render_extract("ds", DatePart.WEEK) }};
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ SELECT
, DATE_TRUNC(revenue_src_10006.created_at, month) AS ds__month
, DATE_TRUNC(revenue_src_10006.created_at, quarter) AS ds__quarter
, DATE_TRUNC(revenue_src_10006.created_at, year) AS ds__year
, EXTRACT(YEAR FROM revenue_src_10006.created_at) AS ds__extract_year
, EXTRACT(QUARTER FROM revenue_src_10006.created_at) AS ds__extract_quarter
, EXTRACT(MONTH FROM revenue_src_10006.created_at) AS ds__extract_month
, EXTRACT(WEEK FROM revenue_src_10006.created_at) AS ds__extract_week
, EXTRACT(DAY FROM revenue_src_10006.created_at) AS ds__extract_day
, EXTRACT(DAYOFWEEK FROM revenue_src_10006.created_at) AS ds__extract_dayofweek
, EXTRACT(DAYOFYEAR FROM revenue_src_10006.created_at) AS ds__extract_dayofyear
, EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month
, EXTRACT(ISOWEEK FROM revenue_src_10006.created_at) AS ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day
, EXTRACT(DAYOFWEEK FROM revenue_src_10006.created_at) AS ds__extract_dow
, EXTRACT(DAYOFYEAR FROM revenue_src_10006.created_at) AS ds__extract_doy
, revenue_src_10006.created_at AS company__ds__day
, DATE_TRUNC(revenue_src_10006.created_at, isoweek) AS company__ds__week
, DATE_TRUNC(revenue_src_10006.created_at, month) AS company__ds__month
, DATE_TRUNC(revenue_src_10006.created_at, quarter) AS company__ds__quarter
, DATE_TRUNC(revenue_src_10006.created_at, year) AS company__ds__year
, EXTRACT(YEAR FROM revenue_src_10006.created_at) AS company__ds__extract_year
, EXTRACT(QUARTER FROM revenue_src_10006.created_at) AS company__ds__extract_quarter
, EXTRACT(MONTH FROM revenue_src_10006.created_at) AS company__ds__extract_month
, EXTRACT(WEEK FROM revenue_src_10006.created_at) AS company__ds__extract_week
, EXTRACT(DAY FROM revenue_src_10006.created_at) AS company__ds__extract_day
, EXTRACT(DAYOFWEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dayofweek
, EXTRACT(DAYOFYEAR FROM revenue_src_10006.created_at) AS company__ds__extract_dayofyear
, EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month
, EXTRACT(ISOWEEK FROM revenue_src_10006.created_at) AS company__ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day
, EXTRACT(DAYOFWEEK FROM revenue_src_10006.created_at) AS company__ds__extract_dow
, EXTRACT(DAYOFYEAR FROM revenue_src_10006.created_at) AS company__ds__extract_doy
, revenue_src_10006.user_id AS user
, revenue_src_10006.user_id AS company__user
FROM ***************************.fct_revenue revenue_src_10006
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@ SELECT
, DATE_TRUNC(id_verifications_src_10003.ds, month) AS ds__month
, DATE_TRUNC(id_verifications_src_10003.ds, quarter) AS ds__quarter
, DATE_TRUNC(id_verifications_src_10003.ds, year) AS ds__year
, EXTRACT(YEAR FROM id_verifications_src_10003.ds) AS ds__extract_year
, EXTRACT(QUARTER FROM id_verifications_src_10003.ds) AS ds__extract_quarter
, EXTRACT(MONTH FROM id_verifications_src_10003.ds) AS ds__extract_month
, EXTRACT(WEEK FROM id_verifications_src_10003.ds) AS ds__extract_week
, EXTRACT(DAY FROM id_verifications_src_10003.ds) AS ds__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds) AS ds__extract_dayofweek
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds) AS ds__extract_dayofyear
, EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month
, EXTRACT(ISOWEEK FROM id_verifications_src_10003.ds) AS ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds) AS ds__extract_dow
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds) AS ds__extract_doy
, id_verifications_src_10003.ds_partitioned AS ds_partitioned__day
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, isoweek) AS ds_partitioned__week
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, month) AS ds_partitioned__month
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, quarter) AS ds_partitioned__quarter
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, year) AS ds_partitioned__year
, EXTRACT(YEAR FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year
, EXTRACT(QUARTER FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter
, EXTRACT(MONTH FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month
, EXTRACT(WEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week
, EXTRACT(DAY FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dayofweek
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dayofyear
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month
, EXTRACT(ISOWEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy
, id_verifications_src_10003.verification_type
, id_verifications_src_10003.ds AS verification__ds__day
, DATE_TRUNC(id_verifications_src_10003.ds, isoweek) AS verification__ds__week
, DATE_TRUNC(id_verifications_src_10003.ds, month) AS verification__ds__month
, DATE_TRUNC(id_verifications_src_10003.ds, quarter) AS verification__ds__quarter
, DATE_TRUNC(id_verifications_src_10003.ds, year) AS verification__ds__year
, EXTRACT(YEAR FROM id_verifications_src_10003.ds) AS verification__ds__extract_year
, EXTRACT(QUARTER FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter
, EXTRACT(MONTH FROM id_verifications_src_10003.ds) AS verification__ds__extract_month
, EXTRACT(WEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_week
, EXTRACT(DAY FROM id_verifications_src_10003.ds) AS verification__ds__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_dayofweek
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds) AS verification__ds__extract_dayofyear
, EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month
, EXTRACT(ISOWEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy
, id_verifications_src_10003.ds_partitioned AS verification__ds_partitioned__day
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, isoweek) AS verification__ds_partitioned__week
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, month) AS verification__ds_partitioned__month
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, quarter) AS verification__ds_partitioned__quarter
, DATE_TRUNC(id_verifications_src_10003.ds_partitioned, year) AS verification__ds_partitioned__year
, EXTRACT(YEAR FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year
, EXTRACT(QUARTER FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter
, EXTRACT(MONTH FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month
, EXTRACT(WEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week
, EXTRACT(DAY FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dayofweek
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dayofyear
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month
, EXTRACT(ISOWEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day
, EXTRACT(DAYOFWEEK FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow
, EXTRACT(DAYOFYEAR FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy
, id_verifications_src_10003.verification_type AS verification__verification_type
, id_verifications_src_10003.verification_id AS verification
, id_verifications_src_10003.user_id AS user
Expand Down
Loading

0 comments on commit 64164d9

Please sign in to comment.