-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/github_actions/actions/setup-py…
…thon-5
- Loading branch information
Showing
12 changed files
with
363 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "1.8.0rc1" | ||
version = "1.8.0rc2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import pytest | ||
from dbt.tests.util import get_connection, run_dbt | ||
|
||
snapshot_sql = """ | ||
{% snapshot claims_snapshot %} | ||
{{ | ||
config( | ||
target_database='secondary_db', | ||
target_schema='dbo', | ||
unique_key='id', | ||
strategy='timestamp', | ||
updated_at='updated_at', | ||
) | ||
}} | ||
select * from {{source('mysource', 'claims')}} | ||
{% endsnapshot %} | ||
""" | ||
|
||
source_csv = """id,updated_date | ||
1,2024-01-01 | ||
2,2024-01-01 | ||
3,2024-01-01 | ||
""" | ||
|
||
sources_yml = """ | ||
version: 2 | ||
sources: | ||
- name: mysource | ||
database: TestDB | ||
tables: | ||
- name: claims | ||
""" | ||
|
||
|
||
class TestCrossDB: | ||
def create_secondary_db(self, project): | ||
create_sql = """ | ||
DECLARE @col NVARCHAR(256) | ||
SET @col = (SELECT CONVERT (varchar(256), SERVERPROPERTY('collation'))); | ||
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='secondary_db') | ||
BEGIN | ||
EXEC ('CREATE DATABASE secondary_db COLLATE ' + @col) | ||
END | ||
""" | ||
|
||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
create_sql.format(database=project.database), | ||
fetch=True, | ||
) | ||
|
||
def cleanup_secondary_database(self, project): | ||
drop_sql = "DROP DATABASE IF EXISTS secondary_db" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
drop_sql.format(database=project.database), | ||
fetch=True, | ||
) | ||
|
||
def cleanup_primary_table(self, project): | ||
drop_sql = "DROP TABLE IF EXISTS {database}.mysource.claims" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
drop_sql.format(database=project.database), | ||
fetch=True, | ||
) | ||
|
||
def cleanup_snapshot_table(self, project): | ||
drop_sql = "DROP TABLE IF EXISTS TestDB_Secondary.dbo.claims_snapshot" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
drop_sql, | ||
fetch=True, | ||
) | ||
|
||
def create_source_schema(self, project): | ||
create_sql = """ | ||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'mysource') | ||
BEGIN | ||
EXEC('CREATE SCHEMA mysource') | ||
END | ||
""" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
create_sql, | ||
fetch=True, | ||
) | ||
|
||
def create_primary_table(self, project): | ||
src_query = """ | ||
SELECT * | ||
INTO | ||
{database}.mysource.claims | ||
FROM | ||
( | ||
SELECT | ||
1 as id, | ||
CAST('2024-01-01' as DATETIME2(6)) updated_at | ||
UNION ALL | ||
SELECT | ||
2 as id, | ||
CAST('2024-01-01' as DATETIME2(6)) updated_at | ||
UNION ALL | ||
SELECT | ||
3 as id, | ||
CAST('2024-01-01' as DATETIME2(6)) updated_at | ||
) as src_data | ||
""" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
src_query.format(database=project.database, schema=project.test_schema), | ||
fetch=True, | ||
) | ||
|
||
def create_secondary_schema(self, project): | ||
src_query = """ | ||
USE [secondary_db] | ||
EXEC ('CREATE SCHEMA {schema}') | ||
""" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
src_query.format(database=project.database, schema=project.test_schema), | ||
fetch=True, | ||
) | ||
|
||
def update_primary_table(self, project): | ||
sql = """ | ||
UPDATE [{database}].[mysource].[claims] | ||
SET | ||
updated_at = CAST('2024-02-01' as datetime2(6)) | ||
WHERE | ||
id = 3 | ||
""" | ||
with get_connection(project.adapter): | ||
project.adapter.execute( | ||
sql.format(database=project.database), | ||
fetch=True, | ||
) | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"sources.yml": sources_yml} | ||
|
||
@pytest.fixture(scope="class") | ||
def snapshots(self): | ||
return {"claims_snapshot.sql": snapshot_sql} | ||
|
||
def test_cross_db_snapshot(self, project): | ||
self.create_secondary_db(project) | ||
|
||
self.cleanup_primary_table(project) | ||
self.cleanup_snapshot_table(project) | ||
|
||
self.create_source_schema(project) | ||
self.create_primary_table(project) | ||
run_dbt(["snapshot"]) | ||
self.update_primary_table(project) | ||
run_dbt(["snapshot"]) | ||
|
||
self.cleanup_snapshot_table(project) | ||
self.cleanup_secondary_database(project) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
|
||
seed_schema_yml = """ | ||
version: 2 | ||
seeds: | ||
- name: raw_data | ||
""" | ||
|
||
|
||
class TestLargeSeed: | ||
def build_large_seed_file(self): | ||
row_count = 3000 | ||
column_count = 10 | ||
|
||
headers = ",".join(["id"] + [f"column_{_}" for _ in range(1, column_count)]) | ||
seed_data = [headers] | ||
for row in range(1, row_count): | ||
row_data = [str(row)] | ||
for column in range(1, column_count): | ||
row_data += [str(column)] | ||
|
||
row_data = ",".join(row_data) | ||
seed_data += [row_data] | ||
|
||
large_seed_file = "\n".join(seed_data) | ||
return large_seed_file | ||
|
||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return {"name": "generic_tests"} | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"raw_data.csv": self.build_large_seed_file(), | ||
"schema.yml": seed_schema_yml, | ||
} | ||
|
||
def test_large_seed(self, project): | ||
run_dbt(["seed"]) |
Oops, something went wrong.