diff --git a/.changes/unreleased/Breaking Changes-20230727-170535.yaml b/.changes/unreleased/Breaking Changes-20230727-170535.yaml new file mode 100644 index 00000000..f432d06f --- /dev/null +++ b/.changes/unreleased/Breaking Changes-20230727-170535.yaml @@ -0,0 +1,6 @@ +kind: Breaking Changes +body: Use CamelCase in the `WhereFilter` Template Calls +time: 2023-07-27T17:05:35.447535-07:00 +custom: + Author: plypaul + Issue: "129" diff --git a/dbt_semantic_interfaces/parsing/where_filter_parser.py b/dbt_semantic_interfaces/parsing/where_filter_parser.py index 71bc893a..40a367ec 100644 --- a/dbt_semantic_interfaces/parsing/where_filter_parser.py +++ b/dbt_semantic_interfaces/parsing/where_filter_parser.py @@ -121,9 +121,9 @@ def _entity_call(entity_name: str, entity_path: Sequence[str] = ()) -> str: try: SandboxedEnvironment(undefined=StrictUndefined).from_string(where_sql_template).render( - dimension=_dimension_call, - time_dimension=_time_dimension_call, - entity=_entity_call, + Dimension=_dimension_call, + TimeDimension=_time_dimension_call, + Entity=_entity_call, ) except (UndefinedError, TemplateSyntaxError, SecurityError) as e: raise ParseWhereFilterException(f"Error while parsing Jinja template:\n{where_sql_template}") from e diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/metrics.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/metrics.yaml index 57555077..a185117f 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/metrics.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/metrics.yaml @@ -54,7 +54,7 @@ metric: type_params: measure: name: booking_value - filter: "{{ dimension('booking__is_instant') }}" + filter: "{{ Dimension('booking__is_instant') }}" --- metric: name: "average_instant_booking_value" @@ -63,7 +63,7 @@ metric: type_params: measure: name: average_booking_value - filter: "{{ dimension('booking__is_instant') }}" + filter: "{{ Dimension('booking__is_instant') }}" --- metric: name: "booking_value_for_non_null_listing_id" @@ -72,7 +72,7 @@ metric: type_params: measure: name: booking_value - filter: "{{ entity('listing') }} IS NOT NULL" + filter: "{{ Entity('listing') }} IS NOT NULL" --- metric: name: "bookers" @@ -113,7 +113,7 @@ metric: type_params: measure: name: listings - filter: "{{ dimension('listing__is_lux_latest') }}" + filter: "{{ Dimension('listing__is_lux_latest') }}" --- metric: name: "smallest_listing" @@ -276,7 +276,7 @@ metric: type_params: numerator: name: average_booking_value - filter: "{{ dimension('booking__is_instant') }}" + filter: "{{ Dimension('booking__is_instant') }}" denominator: name: max_booking_value --- @@ -289,7 +289,7 @@ metric: type_params: numerator: name: average_booking_value - filter: "{{ dimension('listing__is_lux_latest', entity_path=['listing']) }}" + filter: "{{ Dimension('listing__is_lux_latest', entity_path=['listing']) }}" denominator: name: max_booking_value --- @@ -303,9 +303,9 @@ metric: expr: "average_booking_value * bookings / NULLIF(booking_value, 0)" metrics: - name: average_booking_value - filter: "{{ dimension('listing__is_lux_latest', entity_path=['listing']) }}" + filter: "{{ Dimension('listing__is_lux_latest', entity_path=['listing']) }}" - name: bookings - filter: "{{ dimension('listing__is_lux_latest', entity_path=['listing']) }}" + filter: "{{ Dimension('listing__is_lux_latest', entity_path=['listing']) }}" - name: booking_value --- metric: @@ -317,7 +317,7 @@ metric: type_params: numerator: name: booking_value - filter: "{{ dimension('booking__is_instant') }}" + filter: "{{ Dimension('booking__is_instant') }}" alias: booking_value_with_is_instant_constraint denominator: name: booking_value @@ -331,11 +331,11 @@ metric: type_params: numerator: name: total_account_balance_first_day - filter: "{{ dimension('user__home_state_latest') }} IN ('CA', 'HI', 'WA')" + filter: "{{ Dimension('user__home_state_latest') }} IN ('CA', 'HI', 'WA')" alias: west_coast_balance_first_day denominator: name: total_account_balance_first_day - filter: "{{ dimension('user__home_state_latest') }} IN ('MD', 'NY', 'TX')" + filter: "{{ Dimension('user__home_state_latest') }} IN ('MD', 'NY', 'TX')" alias: east_coast_balance_first_dat --- metric: @@ -347,7 +347,7 @@ metric: expr: delayed_bookings * 2 metrics: - name: bookings - filter: "NOT {{ dimension('booking__is_instant') }}" + filter: "NOT {{ Dimension('booking__is_instant') }}" alias: delayed_bookings --- metric: @@ -398,7 +398,7 @@ metric: - name: bookings - name: listings alias: lux_listing - filter: "{{ dimension('listing__is_lux_latest') }}" + filter: "{{ Dimension('listing__is_lux_latest') }}" --- metric: name: "instant_plus_non_referred_bookings_pct" diff --git a/tests/implementations/where_filter/test_parse_calls.py b/tests/implementations/where_filter/test_parse_calls.py index 7c113b53..0fb7d04b 100644 --- a/tests/implementations/where_filter/test_parse_calls.py +++ b/tests/implementations/where_filter/test_parse_calls.py @@ -23,8 +23,8 @@ def test_extract_dimension_call_parameter_sets() -> None: # noqa: D parse_result = PydanticWhereFilter( where_sql_template=( """\ - {{ dimension('booking__is_instant') }} \ - AND {{ dimension('user__country', entity_path=['listing']) }} == 'US'\ + {{ Dimension('booking__is_instant') }} \ + AND {{ Dimension('user__country', entity_path=['listing']) }} == 'US'\ """ ) ).call_parameter_sets @@ -50,7 +50,7 @@ def test_extract_dimension_call_parameter_sets() -> None: # noqa: D def test_extract_time_dimension_call_parameter_sets() -> None: # noqa: D parse_result = PydanticWhereFilter( where_sql_template=( - """{{ time_dimension('user__created_at', 'month', entity_path=['listing']) }} = '2020-01-01'""" + """{{ TimeDimension('user__created_at', 'month', entity_path=['listing']) }} = '2020-01-01'""" ) ).call_parameter_sets @@ -70,7 +70,7 @@ def test_extract_time_dimension_call_parameter_sets() -> None: # noqa: D def test_extract_metric_time_dimension_call_parameter_sets() -> None: # noqa: D parse_result = PydanticWhereFilter( - where_sql_template=("""{{ time_dimension('metric_time', 'month') }} = '2020-01-01'""") + where_sql_template=("""{{ TimeDimension('metric_time', 'month') }} = '2020-01-01'""") ).call_parameter_sets assert parse_result == FilterCallParameterSets( @@ -87,7 +87,7 @@ def test_extract_metric_time_dimension_call_parameter_sets() -> None: # noqa: D def test_extract_entity_call_parameter_sets() -> None: # noqa: D parse_result = PydanticWhereFilter( where_sql_template=( - """{{ entity('listing') }} AND {{ entity('user', entity_path=['listing']) }} == 'TEST_USER_ID'""" + """{{ Entity('listing') }} AND {{ Entity('user', entity_path=['listing']) }} == 'TEST_USER_ID'""" ) ).call_parameter_sets