Skip to content

Commit

Permalink
Use CamelCase in the 'WhereFilter' Template Calls
Browse files Browse the repository at this point in the history
Got a request to change the name of the calls in the Jinja template for the
`WhereFilter` to use CamelCase to be similar to objects.

e.g.

```
{{ dimension('user__country', entity_path=['listing']) }} == 'US'

->

{{ Dimension('user__country', entity_path=['listing']) }} == 'US'
```
  • Loading branch information
plypaul committed Jul 28, 2023
1 parent f322968 commit fee9276
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Breaking Changes-20230727-170535.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 3 additions & 3 deletions dbt_semantic_interfaces/parsing/where_filter_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
---
Expand All @@ -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
---
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions tests/implementations/where_filter/test_parse_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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(
Expand All @@ -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

Expand Down

0 comments on commit fee9276

Please sign in to comment.