Python model - more customization options
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
调研方向
首先阅读 dbt/include/databricks/macros/adapters/python.sql,尤其是 databricks__py_write_table 和 py_get_writer_options,然后比较此处所示的覆盖宏和模型配置。在实现并验证约定的行为之前,先定义对写入选项和 ref 处理的受支持自定义方式,以及相应的配置和文档。
由索引模型根据 Issue 内容生成。
描述
Describe the feature
The current Python model macro is quite restrictive:
- Model is forced to do full overwrite: https://github.com/databricks/dbt-databricks/blob/main/dbt/include/databricks/macros/adapters/python.sql#L42
- Model hardcodes the interface used to read refs.
Would it be possible to offer more customization (e.g. including the overwriteSchema as option into py_get_writer_options() ?
Would it also be possible to allow more customization on the way refs are treated?
Describe alternatives you've considered
The alternative I went for now is overriding this macro. I don't mind, but I'm wondering if there could be a better way?
Additional context
Here is the macro I'm using (yes, i essentially just cut everything out, and changed spark.table to str):
{% macro databricks__py_write_table(compiled_code, target_relation) %}
{{ compiled_code }}
dbt = dbtObj(str)
df = model(dbt, spark)
{% endmacro %}
And here is my model:
version: 2
models:
- name: test_model
config:
test_var: "{{ var('test_var') }}"
materialized: "table"
submission_method: "serverless_cluster"
partition_by:
- test_var
columns:
- name: test_var
data_type: int
- name: some_data
data_type: int
from datetime import datetime, timedelta
def model(dbt, session):
test_var = dbt.config.get("test_var", None)
partition_by = dbt.config.get('partition_by', [])
query = f"""
select
'{test_var}' as test_var,
123 as some_data
from {dbt.ref('other_sql_model')}
where test_var = '{test_var}'
"""
df = session.sql(query)
target_table = f"{dbt.this.database}.{dbt.this.schema}.{dbt.this.identifier}"
print(f"Target table: {target_table}")
(
df.write
.mode("overwrite")
.format("delta")
.option("partitionOverwriteMode", "dynamic")
.partitionBy(*partition_by)
.saveAsTable(target_table)
)
return session.table(target_table)
Who will this benefit?
I think this customization (and associated documentation) would benefit teams that consider migrating to dbt, but having a lot of legacy python pipelines. Wrapping those pipelines with dbt with such simplified macro will allow "lift and shift" kind of move, and then gradual evolution of the pipelines to become more dbt-friendly.
Are you interested in contributing this feature?
I am happy to contribute, but I'd like to hear some critique and arguments against this. Overall, my primary interest is to enable usage of dbt also for the cases where logic is objectively too complex to be migrated to SQL in any reasonable time.
- 主要语言
- Python
- 星标
- 391
- 派生
- 231
- 平均合并
- 9 天 7 小时
- 30 天内合并 PR
- 29
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
databricks/dbt-databricks 的其他 Issue
-
persist_docs.columns triggers a full-plan probe query on views even when the model has no column docs可能已有人在做 @DelorneN007 于 59 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
databricks/dbt-databricks#1680 · 1 条评论 ·
维护者通常 6 天内回复
-
bug
难度 2/5 半天 新手友好度 68/100
databricks/dbt-databricks#1003 · 1 条评论 ·
维护者通常 6 天内回复
-
Emit COMMENT and DEFAULT for function arguments and descriptions in CREATE FUNCTION可能已有人在做 @alvinism 于 7 天前认领。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 25/100
databricks/dbt-databricks#1764 ·
维护者通常 6 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 46/100
databricks/dbt-databricks#1762 ·
维护者通常 6 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
databricks/dbt-databricks#1761 ·
维护者通常 6 天内回复
查看 databricks/dbt-databricks 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 88/100
aws-samples/sample-per-model-bedrock#857 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
521xueweihan/HelloGitHub#4328 ·
-
documentation maintainer-managed
难度 2/5 1-3 小时 新手友好度 84/100
awslabs/visual-asset-management-system#1418 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复