Snowflake 存储过程因 dbt 而失败

Snowflake stored procedure fails from dbt

我在通过 dbt 在 Snowflake 中执行存储过程时遇到问题:

我的程序描述如下:MyStoredProcedure(ARRAY, VARCHAR, VARCHAR)

所以,当我想 运行 它时,我使用 array_construct 函数来创建第一个参数,例如: call MyStoredProcedure(array_construct(array_construct('str_1', 'str_2')), 'schema_name', 'table_name');

当我在 Snowflake 中 运行 它时,这有效。但是,当我 运行 来自 dbt 时,它失败并出现此错误:

Modifying a transaction that has started at a different scope is not allowed.

我确定这与在此调用中调用 array_construct 有关。

我应该向 运行 提到来自 dbt 的这个,我定义了一个这样的宏:

{% macro MyStoredProcedure() %}
    {% set query -%}
        CALL MyStoredProcedure(
           array_construct(array_construct('str_1', 'str_2')),
           'schema_name',
           'table_name');
    {%- endset %}

    {% do run_query(query) %}
{% endmacro %}

和运行它当然像:dbt run-operation MyStoredProcedure

感谢任何能帮助我解决这个问题的提示或想法。

谢谢

我仍然非常了解雪花,但是通过阅读 this section 在文档中,在我看来,这可能只是您的多范围过程调用的机制。

据我所知,在雪花中执行此操作的典型(非 dbt)方法是:

begin transaction;
insert 1; 
call storedprocedure();
insert 2;
commit;

也许您可以像这样调整您的宏,这将克服范围嵌套问题,因为一切都将在一个事务中完成?

{% macro MyStoredProcedure() %}

    {% set query -%}
        begin transaction;
        CALL MyStoredProcedure(
           array_construct(array_construct('str_1', 'str_2')),
           'schema_name',
           'table_name');
        commit;
    {%- endset %}

    {% do run_query(query) %}
{% endmacro %}

无法测试这个,因为我无法重现程序本身。

最终我运行如下:

{% macro MyStoredProcedure() %}
    {% set query -%}
        CALL MyStoredProcedure(
            array_construct(array_construct('str_1', 'str_2')),
            'schema_name',
            'table_name');
        commit;
    {%- endset %}

    {% do run_query(query) %}
{% endmacro %}