ENV VAR需要但未提供-DBT CLI

发布于 2025-01-22 06:12:51 字数 754 浏览 4 评论 0原文

我们在DBTCloud中具有一个环境变量,称为dbt_snowflake_env,根据使用了哪个环境选择右数据库。

目前,我正在尝试使用VSCODE设置DBT CLI。我创建了一个看起来像这样的profiles.yml文件:

default:
  target: development
  outputs:
    development:
      type: snowflake
      account: skxxxx.eu-central-1

      user: <name>
      password: <pass>

      role: sysadmin
      warehouse: transformations_dw
      database: " {{ env_var('DBT_SNOWFLAKE_ENV', 'analytics_dev') }} "
      schema: transformations
      threads: 4

在一些建议之后,我添加了env_var行,但我意识到环境变量仍然不存在。我看到的问题是,如果我硬码analytics_dev在该位置(这很有意义),则错误仍然存​​在。

我不希望任何要使用DBT的人如果想在生产中运行某些东西,就必须更改环境变量。

我在这里有什么选择?

We have an environment variable set in dbtCloud called DBT_SNOWFLAKE_ENV that selects the right database depending on which environment is used.

At the moment, I'm trying to set up dbt CLI with VSCode. I created a profiles.yml file that looks like this:

default:
  target: development
  outputs:
    development:
      type: snowflake
      account: skxxxx.eu-central-1

      user: <name>
      password: <pass>

      role: sysadmin
      warehouse: transformations_dw
      database: " {{ env_var('DBT_SNOWFLAKE_ENV', 'analytics_dev') }} "
      schema: transformations
      threads: 4

I added the env_var line after some suggestions but I realise that the environment variable still doesn't exist yet. The problem I see is that if I hardcode analytics_dev in that place (which makes sense), the error still persists.

I wouldn't want anybody who's going to use dbt to have to change the environment variable if they want to run something on production.

What are my options here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不乱于心 2025-01-29 06:12:51

您可以为DBT CLI上的变量设置源文件 - 例如,您将创建一个称为set_env_var.sh的bash脚本,然后在终端中source> source set_env_var.sh

BASH脚本的一个示例是:

export SNOWFLAKE_ACCOUNT=xxxxx
export SNOWFLAKE_USER=xxxxx
export SNOWFLAKE_ROLE=xxxx
export SNOWFLAKE_SCHEMA=xxxx
export SNOWFLAKE_WAREHOUSE=xxxxx

在您的profiles.yml中,您可以添加所需的所有变量。.

warehouse: "{{ env_var('SNOWFLAKE_WAREHOUSE') }}"
database: "{{ env_var('SNOWFLAKE_DATABASE') }}"

希望这会有所帮助。

You can set up a source file for the variables on dbt cli - for example you would create a bash script called set_env_var.sh and then source set_env_var.sh in your terminal.

An example of the bash script would be:

export SNOWFLAKE_ACCOUNT=xxxxx
export SNOWFLAKE_USER=xxxxx
export SNOWFLAKE_ROLE=xxxx
export SNOWFLAKE_SCHEMA=xxxx
export SNOWFLAKE_WAREHOUSE=xxxxx

and in your profiles.yml you can add all the variables you want, for example..

warehouse: "{{ env_var('SNOWFLAKE_WAREHOUSE') }}"
database: "{{ env_var('SNOWFLAKE_DATABASE') }}"

Hope this helps.

时光病人 2025-01-29 06:12:51

首先,您必须给出硬码数据库名称,而另一语法是错误的。其次,尝试为环境做一个动态变量,然后在要使用dbt时这样使用它,均值

** dbt快照 - profile -vars $ dbt_snowflake_env **
当您运行时,它很容易从Env拾取。

目前,我正在研究DBT,即使完整的配置文件也是动态的,根据Schema和DB的动态。

First of all younyou have to give hard code database name the other syntax is wrong. Secondly try to make a dynamic variable for environment and then use it like this when you want to use dbt, mean

**DBT snapshot --profile --vars $DBT_SNOWFLAKE_ENV **
As when you run it can easily pick up from env.

Currently i am working on dbt with everything dynamic even the full profile is dynamic according to schema and db.

末が日狂欢 2025-01-29 06:12:51

在我的DBT模型中,我的变量在我的vars的一部分中声明为dbt_project.yml file,因此,而不是访问变量,例如

” {{envy_var ('my_variable')}}}“

我应该使用:

“ {{var('my_variable')}}”>

In my case in my DBT model my variable was declared as part of vars within my dbt_project.yml file, so instead of accessing the variable like

"{{ env_var('MY_VARIABLE') }}"

I should have used:

"{{ var('MY_VARIABLE') }}"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文