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

Feature/databricks insert by period #44

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 1 deletion insert_by_period/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]

# This setting configures which "profile" dbt uses for this project.
profile: 'insert_by_period'
profile: 'dbt_labs_experimental_features__databricks'
matt-winkler marked this conversation as resolved.
Show resolved Hide resolved

dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils']

# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
Expand Down
9 changes: 9 additions & 0 deletions insert_by_period/integration_tests/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ integration_tests:
warehouse: "{{ env_var('SNOWFLAKE_TEST_WAREHOUSE') }}"
schema: dbt_utils_integration_tests_snowflake
threads: 10

databricks:
type: databricks
catalog: "{{ env_var('DATABRICKS_TEST_CATALOG') }}"
host: "{{ env_var('DATABRICKS_TEST_HOST') }}"
http_path: "{{ env_var('DATABRICKS_TEST_HTTP_PATH') }}"
token: "{{ env_var('DATABRICKS_TEST_TOKEN') }}"
schema: dbt_utils_integration_tests_databricks
threads: 4
10 changes: 8 additions & 2 deletions insert_by_period/integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
name: 'insert_by_period_integration_tests'
version: '1.0'

profile: 'integration_tests'

# require-dbt-version: inherit this from dbt-utils

config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'integration_tests'

dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils', 'insert_by_period_integration_tests']


model-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
Expand Down
4 changes: 3 additions & 1 deletion insert_by_period/integration_tests/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
packages:
- local: ../
- package: dbt-labs/dbt_utils
version: [">0.9.0", "<2.0.0"]
version: [">0.9.0", "<2.0.0"]
- package: dbt-labs/spark_utils
version: 0.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
{% do return (api.Relation.create(identifier=tmp_identifier,
schema=None, type=type)) %}
{%- endmacro %}

{% macro databricks__create_relation_for_insert_by_period(tmp_identifier, schema, type) -%}
{% do return (api.Relation.create(identifier=tmp_identifier,
schema=None, type=type)) %}
{%- endmacro %}
7 changes: 6 additions & 1 deletion insert_by_period/macros/insert_by_period_materialization.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@
);
{%- endcall %}
{% set result = load_result('main-' ~ i) %}
{% if 'response' in result.keys() %} {# added in v0.19.0 #}

{% if target.type == 'databricks' %} {# databricks provides rows affected in 'data' and not 'response' #}
b-per marked this conversation as resolved.
Show resolved Hide resolved
{% if 'data' in result.keys() %}
{% set rows_inserted = result['data'][0][0] | int %}
{% endif %}
{% elif 'response' in result.keys() %} {# added in v0.19.0 #}
{% set rows_inserted = result['response']['rows_affected'] %}
{% else %} {# older versions #}
{% set rows_inserted = result['status'].split(" ")[2] | int %}
Expand Down