Skip to content

Commit 7e296a2

Browse files
committed
clean up code a bit
1 parent 2a54d69 commit 7e296a2

File tree

1 file changed

+16
-25
lines changed
  • dbt/include/sqlserver/macros/materializations/seeds

1 file changed

+16
-25
lines changed
Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
{% macro calc_batch_size(num_columns,max_batch_size) %}
2-
{#
3-
SQL Server allows for a max of 2100 parameters in a single statement.
4-
Check if the max_batch_size fits with the number of columns, otherwise
5-
reduce the batch size so it fits.
6-
#}
7-
{% if num_columns * max_batch_size < 2100 %}
8-
{% set batch_size = max_batch_size %}
9-
{% else %}
10-
{% set batch_size = (2100 / num_columns)|int %}
11-
{% endif %}
12-
13-
{{ return(batch_size) }}
14-
{% endmacro %}
15-
161
{% macro sqlserver__get_binding_char() %}
172
{{ return('?') }}
183
{% endmacro %}
@@ -21,13 +6,27 @@
216
{{ return(400) }}
227
{% endmacro %}
238

24-
{% macro basic_load_csv_rows(model, batch_size, agate_table) %}
9+
{% macro calc_batch_size(num_columns) %}
10+
{#
11+
SQL Server allows for a max of 2100 parameters in a single statement.
12+
Check if the max_batch_size fits with the number of columns, otherwise
13+
reduce the batch size so it fits.
14+
#}
15+
{% set max_batch_size = get_batch_size() %}
16+
{% set calculated_batch = (2100 / num_columns)|int %}
17+
{% set batch_size = [max_batch_size, calculated_batch] | min %}
18+
19+
{{ return(batch_size) }}
20+
{% endmacro %}
2521

22+
{% macro sqlserver__load_csv_rows(model, agate_table) %}
2623
{% set cols_sql = get_seed_column_quoted_csv(model, agate_table.column_names) %}
24+
{% set batch_size = calc_batch_size(agate_table.column_names|length) %}
2725
{% set bindings = [] %}
28-
2926
{% set statements = [] %}
3027

28+
{{ log("Inserting batches of " ~ batch_size ~ " records") }}
29+
3130
{% for chunk in agate_table.rows | batch(batch_size) %}
3231
{% set bindings = [] %}
3332

@@ -56,11 +55,3 @@
5655
{# Return SQL so we can render it out into the compiled files #}
5756
{{ return(statements[0]) }}
5857
{% endmacro %}
59-
60-
{% macro sqlserver__load_csv_rows(model, agate_table) %}
61-
{% set max_batch_size = get_batch_size() %}
62-
{% set cols_sql = agate_table.column_names %}
63-
{% set batch_size = calc_batch_size(cols_sql|length, max_batch_size) %}
64-
65-
{{ return(basic_load_csv_rows(model, batch_size, agate_table) )}}
66-
{% endmacro %}

0 commit comments

Comments
 (0)