Skip to content

Commit

Permalink
Merge pull request #201 from microsoft/v1.8.8-draft
Browse files Browse the repository at this point in the history
Added support for truncate, fixed seed batch calculation and fixed dbt-show errors
  • Loading branch information
prdpsvs authored Aug 29, 2024
2 parents d4f99e7 + 72a01da commit 46bb72f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/fabric/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.7"
version = "1.8.8"
14 changes: 2 additions & 12 deletions dbt/include/fabric/macros/adapters/relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,8 @@
{%- endcall %}
{% endmacro %}

-- DROP fabric__truncate_relation when TRUNCATE TABLE is supported
{% macro fabric__truncate_relation(relation) -%}

{% set tempTableName %}
{{ relation.include(database=False).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 {{ tempTableName }} AS SELECT * FROM {{ relation }} WHERE 1=2
EXEC('DROP TABLE IF EXISTS {{ relation.include(database=False) }};');
EXEC('CREATE TABLE {{ relation.include(database=False) }} AS SELECT * FROM {{ tempTableName }};');
EXEC('DROP TABLE IF EXISTS {{ tempTableName }};');
{%- 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 46bb72f

Please sign in to comment.