Skip to content

Commit

Permalink
Unnamed reflections now take the model name/alias (#264)
Browse files Browse the repository at this point in the history
### Summary

When creating a model for a reflection, if the name config parameter was
not set, the reflection would be named `Unnamed Reflection` inside
Dremio.

### Description

Instead, the default behavior should be for the reflection to be named
after the model name/alias
The default behavior has been changed, it will now set the name
attending to the following priority list:

1. Model config `name` parameter
2. Model config `alias` parameter
3. Model name

### Test Results

Two new tests have been added to the test suit for reflections, one with
the `alias` parameter and another one with the model name

### Changelog

-   [X] Added a summary of what this PR accomplishes to CHANGELOG.md

### Related Issue

#263
  • Loading branch information
bcmeireles authored Jan 16, 2025
1 parent 5c61612 commit 990e846
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
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"

0 comments on commit 990e846

Please sign in to comment.