Skip to content

Commit

Permalink
Added support for truncate, fixed seed batch calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
prdpsvs committed Aug 29, 2024
1 parent 09ff851 commit 72a01da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
17 changes: 2 additions & 15 deletions dbt/include/fabric/macros/adapters/relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,8 @@
{%- endcall %}
{% endmacro %}

-- DROP fabric__truncate_relation when TRUNCATE TABLE is supported
{% macro fabric__truncate_relation(relation) -%}
{% set random_int %}
{{ range(21000, 109000) | random }}
{% endset %}

{% set temp_relation = relation.incorporate(path={ "identifier": relation.identifier ~ random_int }, type='table')-%}
{# {% set tempTableName %}
{{ relation.identifier.replace("#", "") }}_{{ range(21000, 109000) | random }}
{% endset %} #}
{{ log("Truncate Statement is not supported, Using random table as a temp table. - " ~ tempTableName) }}
{% call statement('truncate_relation') -%}
CREATE TABLE {{ temp_relation}} AS SELECT * FROM {{ relation }} WHERE 1=2
DROP TABLE IF EXISTS {{ relation }}
EXEC sp_rename '{{temp_relation.include(database=False)}}','{{relation.identifier}}'
{%- endcall %}

truncate table {{ relation }}
{%- endcall %}
{% endmacro %}
30 changes: 20 additions & 10 deletions dbt/include/fabric/macros/adapters/show.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{% macro fabric__get_limit_subquery_sql(sql, limit) %}
{% macro fabric__get_limit_sql(sql, limit) %}

{% if sql.strip().lower().startswith('with') %}
{{ sql }} order by (select null)
offset 0 rows fetch first {{ limit }} rows only
{% else -%}
select *
from (
{% if limit == -1 or limit is none %}
{% if sql.strip().lower().startswith('with') %}
{{ sql }}
) as model_limit_subq order by (select null)
offset 0 rows fetch first {{ limit }} rows only
{% else -%}
select *
from (
{{ sql }}
) as model_limit_subq
{%- endif -%}
{% else -%}
{% if sql.strip().lower().startswith('with') %}
{{ sql }} order by (select null)
offset 0 rows fetch first {{ limit }} rows only
{% else -%}
select *
from (
{{ sql }}
) as model_limit_subq order by (select null)
offset 0 rows fetch first {{ limit }} rows only
{%- endif -%}
{%- endif -%}

{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#}
{% set max_batch_size = get_batch_size() %}
{% set calculated_batch = (2100 / num_columns)-1|int %}
{% set calculated_batch = ((2100 / num_columns)-1)|int %}
{% set batch_size = [max_batch_size, calculated_batch] | min %}

{{ return(batch_size) }}
Expand Down

0 comments on commit 72a01da

Please sign in to comment.