Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fabric support #229

Closed
wants to merge 4 commits into from
Closed

Conversation

mattiasthalen
Copy link

Added support for Microsoft Fabric by copying the SQLServer macros and changing the prefix to fabric.

@koillinengit
Copy link

koillinengit commented Dec 11, 2024

In my mind the concat_ws.sql could be done something like below (done for automatedv 0.11.0 version). Because concat_ws accept in newer versions only 254 arguments: https://learn.microsoft.com/en-us/sql/t-sql/functions/concat-ws-transact-sql?view=sql-server-ver16 . Note: Separators are also listed as arguments.

/*
 * Copyright (c) Business Thinking Ltd. 2019-2024
 * This software includes code developed by the AutomateDV (f.k.a dbtvault) Team at Business Thinking Ltd. Trading as Datavault
 */

{%- macro concat_ws(string_list, separator="||") -%}

    {{- adapter.dispatch('concat_ws', 'automate_dv')(string_list=string_list, separator=separator) -}}

{%- endmacro %}

{%- macro default__concat_ws(string_list, separator="||") -%}

{%- set batch_size = 100 -%}
{%- set batched_lists = string_list | batch(batch_size) -%}

{# Case 1: If there are fewer than 100 strings, use a single CONCAT_WS #}
{%- if string_list | length <= batch_size -%}
    CONCAT_WS('{{ separator }}',
        {%- for str_obj in string_list %}
            {{ str_obj }}{% if not loop.last %},{% endif %}
        {%- endfor %}
    )

{# Case 2: If there are more than 100 strings, batch and nest CONCAT_WS calls #}
{%- else -%}
    CONCAT_WS('{{ separator }}',
        {%- for batch in batched_lists %}
            CONCAT_WS('{{ separator }}',
                {%- for str_obj in batch %}
                    {{ str_obj }}{% if not loop.last %},{% endif %}
                {%- endfor %}
            )
            {%- if not loop.last %},{% endif %}
        {%- endfor %}
    )
{%- endif %}

{%- endmacro %}

{%- macro bigquery__concat_ws(string_list, separator="||") -%}

CONCAT(
{%- for str in string_list %}
    {{ str }}
{%- if not loop.last %}, '{{ separator }}', {%- endif -%}
{%- endfor %}
)

{%- endmacro -%}

{%- macro sqlserver__concat_ws(string_list, separator="||") -%}

    {{ automate_dv.default__concat_ws(string_list=string_list, separator=separator) }}

{%- endmacro -%}

 {%- macro postgres__concat_ws(string_list, separator="||") -%}

    {{ automate_dv.default__concat_ws(string_list=string_list, separator=separator) }}

{%- endmacro -%}

{%- macro databricks__concat_ws(string_list, separator="||") -%}

    {{ automate_dv.default__concat_ws(string_list=string_list, separator=separator) }}

{%- endmacro -%}

{%- macro fabric__concat_ws(string_list, separator="||") -%}

    {{ default__concat_ws(string_list=string_list, separator=separator) }}

{%- endmacro -%}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants