Python model - more customization options
Los mantenedores suelen responder en 6 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Tranquilo
- Área
- data-engineering
Línea de trabajo
Comienza leyendo dbt/include/databricks/macros/adapters/python.sql, especialmente databricks__py_write_table y py_get_writer_options; después, compara la macro que sobrescribe y la configuración del modelo que se muestran aquí. Define la personalización compatible para las opciones de escritura y el manejo de ref, junto con su configuración y documentación, antes de implementar y validar el comportamiento acordado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 391
- Forks
- 231
- Merge medio
- 9 d 7 h
- PR fusionados (30 d)
- 29
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de databricks/dbt-databricks
-
persist_docs.columns triggers a full-plan probe query on views even when the model has no column docsPosiblemente ocupada @DelorneN007 la tomó hace 59 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
databricks/dbt-databricks#1680 · 1 comentario ·
Los mantenedores suelen responder en 6 días
-
bug
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
databricks/dbt-databricks#1003 · 1 comentario ·
Los mantenedores suelen responder en 6 días
-
Emit COMMENT and DEFAULT for function arguments and descriptions in CREATE FUNCTIONPosiblemente ocupada @alvinism la tomó hace 7 días. Abiertoenhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
databricks/dbt-databricks#1764 ·
Los mantenedores suelen responder en 6 días
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 46/100
databricks/dbt-databricks#1762 ·
Los mantenedores suelen responder en 6 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
databricks/dbt-databricks#1761 ·
Los mantenedores suelen responder en 6 días
Todos los issues de databricks/dbt-databricks
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
FinanceFlash/unvibecode#699 ·
Los mantenedores suelen responder en 1 día
-
enhancement Website
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OWASP/OWASP-Hunting#96 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
micropython/micropython#19942 ·
Los mantenedores suelen responder en 1 día
-
A rebuild posts "not part of this build" success to the commit's failed `nix-build` gate and effectsPosiblemente ocupada @Padraic-O-Mhuiris la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`epoch.Integer` raises a raw OverflowError for integers too large to convert to a floatPosiblemente ocupada @arindam77 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pydantic/pydantic-extra-types#479 ·
Los mantenedores suelen responder en 1 día