我们目前正在实现雪花和 dbt,并希望在开发和生产之间拆分雪花数据库,以便我们在发布新数据模型之前有一个可以测试的数据库。我们计划使用 dbt 来创建未来的所有数据模型。我对工作流程的后勤工作有几个问题:
我们如何保持开发和生产同步?(或者应该是?)我知道雪花有一个克隆功能,您可以重新创建元数据,而无需复制数据。我们应该将产品数据库克隆到开发人员吗?以一天为周期?那些在开发中拥有物化资源的用户会怎么样——他们会丢失这些数据。
我们是否应该让部署到产品成为 CICD 流程的一部分,并且只有完全合并的拉取请求(在雪花开发上测试)才能部署到雪花产品?这会带来太多瓶颈吗?
很想了解人们如何构建工作流程来维护开发和生产雪花环境。
我正在尝试连接到 Databricks 上的 Spark 集群,并且正在遵循本教程: https: //docs.databricks.com/dev-tools/dbt.html。我已经dbt-databricks安装了连接器(https://github.com/databricks/dbt-databricks)。但是,无论我如何配置它,当我运行dbt test/时,我总是收到“数据库错误,无法连接” dbt debug。
这是我的profiles.yaml:
databricks_cluster:
outputs:
dev:
connect_retries: 5
connect_timeout: 60
host: <my_server_hostname>
http_path: <my_http_path>
schema: default
token: <my_token>
type: databricks
target: dev
Run Code Online (Sandbox Code Playgroud)
这是我的dbt_project.yml:
# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'dbt_dem'
version: '1.0.0'
config-version: 2 …Run Code Online (Sandbox Code Playgroud) 我对 dbt 很陌生,我想在一个项目中使用两种仓库,目前我声明了我的 clickhouse 仓库,我将为其制作表格,并且我需要添加另一个仓库 MindsDB 因为我想引用一些表格在里面
目前我的 prfofile.yml 看起来像这样
dbt-project:
target: dev
outputs:
dev:
type: clickhouse
schema : clickhouse_l
host: 8.77.780.70
port: 6000
user: xxx
password: xxxx
Run Code Online (Sandbox Code Playgroud)
我也想添加下面的仓库
type: mysql
host: mysql.mindsdb.com
user: mindsdb.user@example.com
password: xxx
port: 3306
dbname: mindsdb
schema: exampl_xxx
threads: 1
Run Code Online (Sandbox Code Playgroud)
有办法做到吗?谢谢
使用星形宏,除了列名之外,是否还有办法获取列数据类型(布尔值、数值等)?
例如,此查询使用星号宏从引用表中收集列名,将其保存为数组变量column_names,然后循环该数组并将 max 函数应用于所有列。
{% set column_names = star(
from=ref_table,
except=["a", "b", "c"],
as_list=True)
%}
select
date_trunc('week', day) as week,
name,
{%- for col in column_names %}
max({{ col|lower }}) as {{ col | lower }}{%- if not loop.last %},{{ '\n ' }}{% endif %}
{%- endfor %}
from {{ ref('my_table_name') }}
group by 1, 2
Run Code Online (Sandbox Code Playgroud)
我想有条件地将 max 函数仅应用于布尔列。
这可能看起来像
{%- for col in column_names %}
{% if is_boolean(col) %}
max({{ col|lower }}) as {{ col | lower …Run Code Online (Sandbox Code Playgroud) 有没有办法检查安装了哪些软件包?我会期待类似的事情dbt list packages?
上下文是:
dbt deps内容才packages.yml给我带来任何好处。并且在某些情况下模型可以在不运行的情况下被触发dbt deps我通过谷歌搜索,dbt --help但没有找到任何东西。
在 DBT YAML 文件(例如 dbt_project.yml)中,元素是什么+或符号是什么?-
models:
# Be sure to namespace your model configs to your project name
dbt_labs:
# This configures models found in models/events/
events:
+enabled: true # <--- What is the meaning of +?
+materialized: view # <--- What is the meaning of +?
# This configures models found in models/events/base
# These models will be ephemeral, as the config above is overridden
base:
+materialized: ephemeral # <--- What is the meaning of +?
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来应用 python UDF 在我的 dbt 模型上运行。我成功地在 Snowflake (DWH) 中创建了一个 Python 函数,并针对表运行了它。这似乎按预期工作,但在 dbt 上实现这一点似乎很困难。一些建议/帮助/指导会让我很高兴。
这是我在雪花上创建的 python UDF
create or replace function "077"."Unity".sha3_512(str varchar)
returns varchar
language python
runtime_version = '3.8'
handler = 'hash'
as
$$
import hashlib
def hash(str):
# create a sha3 hash object
hash_sha3_512 = hashlib.new("sha3_512", str.encode())
return hash_sha3_512.hexdigest()
$$
;
Run Code Online (Sandbox Code Playgroud)
目标是在 dbt 中创建 python 函数并将其应用到下面的模型中
{{ config(materialized = 'view') }}
WITH SEC AS(
SELECT
A."AccountID" AS AccountID,
A."AccountName" AS AccountName ,
A."Password" AS Passwords,
apply function here (A."Password") …Run Code Online (Sandbox Code Playgroud) 我有一个名为 的 DBT 包dbt_helpers,我打算在其中覆盖内置全局宏中的一些 dbt。在此示例中,我打算重写该宏dbt_spark_validate_get_file_format,该宏存在于此处的dbt Spark 适配器中。
我已参考此处指定的 dbt 文档来实现我的用例。以下是我在包文件夹下的包中实现宏的方法macros。
{% macro dbt_spark_validate_get_file_format(raw_file_format) -%}
{{ return(adapter.dispatch('dbt_spark_validate_get_file_format','dbt_helpers')(raw_file_format)) }}
{%- endmacro %}
{% macro default__dbt_spark_validate_get_file_format(raw_file_format) %}
{% do log('overriding global macro', info=true) %}
{# Custom implementation here #}
{% endmacro %}
Run Code Online (Sandbox Code Playgroud)
我使用了dbt_helpers与我的包名称相同的宏命名空间。我已在我的主 DBT 项目中将其指定为 中的包,并且在运行命令后packages.yml我能够看到目录中定义的宏。在我的主 dbt 项目中,我已包含项目级别调度配置,以从我的包中获取宏,如图所示,如dbt 文档的本节中所述。dbt_packagesdbt depsdbt_project.yml
dispatch:
- macro_namespace: dbt
search_order: ['dbt_helpers','dbt']
Run Code Online (Sandbox Code Playgroud)
但是,当我运行 dbt 模型时,包中定义的宏不会被调用,而是仍在调用内置的全局宏。我可以通过将宏直接放置在我的项目宏文件夹中来覆盖宏,但我需要从我的dbt_helpers包中覆盖宏。我怎样才能做到这一点?
我有一个 Python DBT 项目,它定义了以下数据模型(通过 YAML):
version: 2
models:
- name: company
description: ''
columns:
- name: ID
description: Unique identifier for the company entity. It is the company name
tests:
- unique
- not_null
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: VARCHAR
- name: REMOTE_ID
description: Company name
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: VARCHAR
- name: CREATED_AT
description: ''
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: TIMESTAMP_TZ
- not_null
- name: UPDATED_AT
description: ''
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: TIMESTAMP_TZ
Run Code Online (Sandbox Code Playgroud)
当我运行时dbt compile,然后dbt run我dbt test …
dbt 的内置文档对于跟踪数据沿袭、数据字典、业务规则等非常有用。但是事实证明,在不使用 dbt Cloud 的情况下以安全的方式将这些文档发布到中央位置并不是那么简单。
与许多企业一样,我们使用 Confluence 进行项目跟踪和文档记录。将所有文档集中在一个地方对于技术和业务用户来说都是有益的。以前有人在 Confluence 中嵌入过 dbt 文档吗?是否有任何现有的插件可以实现此目的?
最理想的状态是拥有一些 CI,它可以自动使嵌入的 dbt 文档保持最新,但这只是小步骤。
我在 Confluence 支持页面上找到了这个,该页面讨论了使用 Confluence 提供静态内容: https://confluence.atlassian.com/confkb/how-to-use-confluence-to-serve-static-content-677282407.html
但我不想乱搞后端 Confluence 服务器的事情。这有点超出我的专业领域。
dbt ×10
python ×2
snowflake-cloud-data-platform ×2
apache-spark ×1
confluence ×1
databricks ×1
sql ×1
workflow ×1
yaml ×1