Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnamed reflections now take the model name/alias #264

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# dbt-dremio v1.8.2

## Changes

- When naming reflections, if a `name` config is not set, the `alias` config parameter will be used instead. If also undefined, it will refer to the model name instead of using `Unnamed Reflection`

# dbt-dremio v1.8.1

## Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.*/

{% materialization reflection, adapter='dremio' %}

{% set reflection_name = config.get('name', validator=validation.any[basetring]) or 'Unnamed Reflection' %}
{% set reflection_name = config.get('name', validator=validation.any[basetring]) or config.get('alias', validator=validation.any[basetring]) or model.name %}
{% set raw_reflection_type = config.get('reflection_type', validator=validation.any[basestring]) or 'raw' %}
{% set raw_anchor = config.get('anchor', validator=validation.any[list, basestring]) %}
{% set raw_external_target = config.get('external_target', validator=validation.any[list, basestring]) %}
Expand Down
49 changes: 49 additions & 0 deletions tests/functional/adapter/dremio_specific/test_reflections.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@
-- depends_on: {{ ref('view1') }}
"""

name_reflection_from_alias_model = """
{{ config(alias='Reflection name from alias',
materialized='reflection',
display=['Date', 'DayOfWeek', 'PdDistrict', 'Category'],
reflection_type='raw')}}
-- depends_on: {{ ref('view1') }}
"""

name_reflection_from_filename_model = """
{{ config(materialized='reflection',
display=['Date', 'DayOfWeek', 'PdDistrict', 'Category'],
reflection_type='raw')}}
-- depends_on: {{ ref('view1') }}
"""


class TestReflectionsDremio:
@pytest.fixture(scope="class")
Expand Down Expand Up @@ -153,6 +168,8 @@ def models(self):
"default_transformations.sql": default_transformations_model,
"default_computations.sql": default_computations_model,
"default_displays_model.sql": default_displays_model,
"name_reflection_from_alias.sql": name_reflection_from_alias_model,
"name_reflection_from_filename.sql": name_reflection_from_filename_model,
}

def _create_path_list(self, database, schema):
Expand Down Expand Up @@ -358,3 +375,35 @@ def testDefaultDisplaysReflection(self, project, client):
assert "partitionFields" not in reflection
assert "sortFields" not in reflection
assert reflection["partitionDistributionStrategy"] == "STRIPED"

def testNameReflectionFromAlias(self, project, client):
run_dbt(["run", "--select", "view1", "name_reflection_from_alias"])

reflection = self._get_reflection(project, client, "view1", "Reflection name from alias")

assert reflection
assert reflection["name"] == "Reflection name from alias"
assert reflection["type"] == "RAW"
assert reflection["displayFields"] == [{"name": x} for x in ["Date", "DayOfWeek", "PdDistrict", "Category"]]
assert "dimensionFields" not in reflection
assert "measureFields" not in reflection
assert "distributionFields" not in reflection
assert "partitionFields" not in reflection
assert "sortFields" not in reflection
assert reflection["partitionDistributionStrategy"] == "STRIPED"

def testNameReflectionFromFilename(self, project, client):
run_dbt(["run", "--select", "view1", "name_reflection_from_filename"])

reflection = self._get_reflection(project, client, "view1", "name_reflection_from_filename")

assert reflection
assert reflection["name"] == "name_reflection_from_filename"
assert reflection["type"] == "RAW"
assert reflection["displayFields"] == [{"name": x} for x in ["Date", "DayOfWeek", "PdDistrict", "Category"]]
assert "dimensionFields" not in reflection
assert "measureFields" not in reflection
assert "distributionFields" not in reflection
assert "partitionFields" not in reflection
assert "sortFields" not in reflection
assert reflection["partitionDistributionStrategy"] == "STRIPED"
Loading