Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/mypy-1.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-scott authored Sep 6, 2024
2 parents 64f0f5d + 26c89b4 commit 76f93ee
Show file tree
Hide file tree
Showing 21 changed files with 729 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-sqlserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
DBT_TEST_USER_3: DBT_TEST_USER_3
COLLATION: ${{ matrix.collation }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: pip install -r dev_requirements.txt
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2.1.0
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -50,10 +50,10 @@ jobs:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2.1.0
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
name: Release new version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
password: ${{ secrets.github_token }}
steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: pip install -r dev_requirements.txt
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Join us on the [dbt Slack](https://getdbt.slack.com/archives/CMRMDDQ9W) to ask q
## Installation

This adapter requires the Microsoft ODBC driver to be installed:
[Windows](https://docs.microsoft.com/nl-be/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16#download-for-windows) |
[macOS](https://docs.microsoft.com/nl-be/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver16) |
[Linux](https://docs.microsoft.com/nl-be/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16)
[Windows](https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16#download-for-windows) |
[macOS](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver16) |
[Linux](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16)

<details><summary>Debian/Ubuntu</summary>
<p>
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/sqlserver/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.0rc1"
version = "1.8.0rc2"
2 changes: 1 addition & 1 deletion dbt/adapters/sqlserver/sqlserver_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def open(cls, connection: Connection) -> Connection:

plugin_version = __version__.version
application_name = f"dbt-{credentials.type}/{plugin_version}"
con_str.append(f"Application Name={application_name}")
con_str.append(f"APP={application_name}")

con_str_concat = ";".join(con_str)

Expand Down
1 change: 1 addition & 0 deletions dbt/include/sqlserver/macros/adapter/indexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
inner join sys.tables {{ information_schema_hints() }}
on sys.indexes.object_id = sys.tables.object_id
where sys.indexes.[name] is not null
and SCHEMA_NAME(sys.tables.schema_id) = '{{ this.schema }}'
and sys.tables.[name] = '{{ this.table }}'
for xml path('')
); exec sp_executesql @drop_remaining_indexes_last;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
{% set strategy_arg_dict = ({'target_relation': target_relation, 'temp_relation': temp_relation, 'unique_key': unique_key, 'dest_columns': dest_columns, 'incremental_predicates': incremental_predicates }) %}
{% set build_sql = strategy_sql_macro_func(strategy_arg_dict) %}

{% do to_drop.append(temp_relation) %}
{% endif %}

{% call statement("main") %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

{% set temp_snapshot_relation_sql = model['compiled_code'].replace("'", "''") %}
{% call statement('create temp_snapshot_relation') %}
USE [{{ model.database}}];
EXEC('DROP VIEW IF EXISTS {{ temp_snapshot_relation.include(database=False) }};');
EXEC('create view {{ temp_snapshot_relation.include(database=False) }} as {{ temp_snapshot_relation_sql }};');
{% endcall %}
Expand Down
46 changes: 46 additions & 0 deletions dbt/include/sqlserver/macros/materializations/tests.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% macro sqlserver__get_test_sql(main_sql, fail_calc, warn_if, error_if, limit) -%}

-- Create target schema if it does not
USE [{{ target.database }}];
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ target.schema }}')
BEGIN
EXEC('CREATE SCHEMA [{{ target.schema }}]')
END

{% set with_statement_pattern = 'with .+ as\s*\(' %}
{% set re = modules.re %}
{% set is_match = re.search(with_statement_pattern, main_sql, re.IGNORECASE) %}

{% if is_match %}
{% set testview %}
[{{ target.schema }}.testview_{{ range(1300, 19000) | random }}]
{% endset %}

{% set sql = main_sql.replace("'", "''")%}
EXEC('create view {{testview}} as {{ sql }};')
select
{{ "top (" ~ limit ~ ')' if limit != none }}
{{ fail_calc }} as failures,
case when {{ fail_calc }} {{ warn_if }}
then 'true' else 'false' end as should_warn,
case when {{ fail_calc }} {{ error_if }}
then 'true' else 'false' end as should_error
from (
select * from {{testview}}
) dbt_internal_test;

EXEC('drop view {{testview}};')

{% else -%}
select
{{ "top (" ~ limit ~ ')' if limit != none }}
{{ fail_calc }} as failures,
case when {{ fail_calc }} {{ warn_if }}
then 'true' else 'false' end as should_warn,
case when {{ fail_calc }} {{ error_if }}
then 'true' else 'false' end as should_error
from (
{{ main_sql }}
) dbt_internal_test
{%- endif -%}
{%- endmacro %}
57 changes: 57 additions & 0 deletions dbt/include/sqlserver/macros/relations/seeds/helpers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% macro sqlserver__get_binding_char() %}
{{ return('?') }}
{% endmacro %}

{% macro sqlserver__get_batch_size() %}
{{ return(400) }}
{% endmacro %}

{% macro calc_batch_size(num_columns) %}
{#
SQL Server allows for a max of 2098 parameters in a single statement.
Check if the max_batch_size fits with the number of columns, otherwise
reduce the batch size so it fits.
#}
{% set max_batch_size = get_batch_size() %}
{% set calculated_batch = (2098 / num_columns)|int %}
{% set batch_size = [max_batch_size, calculated_batch] | min %}

{{ return(batch_size) }}
{% endmacro %}

{% macro sqlserver__load_csv_rows(model, agate_table) %}
{% set cols_sql = get_seed_column_quoted_csv(model, agate_table.column_names) %}
{% set batch_size = calc_batch_size(agate_table.column_names|length) %}
{% set bindings = [] %}
{% set statements = [] %}

{{ log("Inserting batches of " ~ batch_size ~ " records") }}

{% for chunk in agate_table.rows | batch(batch_size) %}
{% set bindings = [] %}

{% for row in chunk %}
{% do bindings.extend(row) %}
{% endfor %}

{% set sql %}
insert into {{ this.render() }} ({{ cols_sql }}) values
{% for row in chunk -%}
({%- for column in agate_table.column_names -%}
{{ get_binding_char() }}
{%- if not loop.last%},{%- endif %}
{%- endfor -%})
{%- if not loop.last%},{%- endif %}
{%- endfor %}
{% endset %}

{% do adapter.add_query(sql, bindings=bindings, abridge_sql_log=True) %}

{% if loop.index0 == 0 %}
{% do statements.append(sql) %}
{% endif %}
{% endfor %}

{# Return SQL so we can render it out into the compiled files #}
{{ return(statements[0]) }}
{% endmacro %}
1 change: 1 addition & 0 deletions dbt/include/sqlserver/macros/relations/table/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{%- set tmp_relation = relation.incorporate(path={"identifier": relation.identifier ~ '__dbt_tmp_vw'}, type='view') -%}

{%- do adapter.drop_relation(tmp_relation) -%}
USE [{{ relation.database }}];
{{ get_create_view_as_sql(tmp_relation, sql) }}

{%- set table_name -%}
Expand Down
2 changes: 1 addition & 1 deletion dbt/include/sqlserver/macros/relations/views/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% set tst %}
SELECT '1' as col
{% endset %}

USE [{{ relation.database }}];
EXEC('{{- escape_single_quotes(query) -}}')

{% endmacro %}
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
dbt-tests-adapter>=1.8.0, <1.9.0

ruff
black==24.2.0
black==24.8.0
bumpversion
flake8
flaky
Expand Down
Loading

0 comments on commit 76f93ee

Please sign in to comment.