Emit COMMENT and DEFAULT for function arguments and descriptions in CREATE FUNCTION
Los mantenedores suelen responder en 6 días
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
The issue specifies changes to the scalar function argument and creation macros, persist_docs, unit tests, a SQL warehouse functional test, and the CHANGELOG. First inspect the existing Databricks function macros and the PostgreSQL and Snowflake argument rendering patterns named in the issue. Done means SQL and Python scalar functions handle defaults, comments, escaping, and persist_docs as proposed, with the tests and changelog entry; an open linked pull request already covers this work.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the feature
dbt-core already parses description on a function and its arguments, and default_value on its arguments. dbt-databricks doesn't render any of them, so the function is created without comments or defaults:
functions:
- name: double_it
description: Doubles a value
arguments:
- name: x
data_type: double
description: Input value
- name: factor
data_type: int
default_value: 2
returns:
data_type: double
renders today as
CREATE OR REPLACE FUNCTION `cat`.`sch`.`double_it` (x double, factor int)
RETURNS double
LANGUAGE SQL
RETURN ...
Unity Catalog can only set a function's comment inside CREATE FUNCTION. There's no COMMENT ON FUNCTION, and ALTER FUNCTION can't change it. So today there's no way to get yml descriptions into Unity Catalog. Those comments are what Genie, AI agents and Catalog Explorer show to describe a function.
There is also a related failure. With persist_docs: {relation: true}, the default function_execute_build_sql calls persist_docs. databricks__persist_docs then runs COMMENT ON FUNCTION ... IS '...', which Databricks rejects, so the model fails.
Proposal (scalar functions, SQL and Python):
-
Override
databricks__formatted_scalar_function_args_sqlto rendername type [DEFAULT <default_value>] [COMMENT '<description>'], the order in the CREATE FUNCTION syntax.DEFAULTis rendered like dbt-postgres and dbt-snowflake already do (default_valueis inserted as a raw SQL expression). The docs say "DEFAULT is supported for LANGUAGE SQL only", so Python UDFs skipDEFAULTand warn, the way an unsupportedvolatilityis handled. dbt-core already rejects a non-defaulted argument after a defaulted one, which matches the Databricks ordering rule. -
Add
COMMENT '<description>'to the function'sCREATE FUNCTIONstatement, using the existingget_create_sql_commentfor escaping. -
Gate the comments behind
persist_docs, the same waydatabricks__comment_clausedoes for tables:persist_docs.relationcontrols the function comment;persist_docs.columnscontrols the argument comments.
Projects that don't opt in get exactly the same SQL as today.
-
Make
persist_docsskip the post-createCOMMENT ONfor function relations, because the comment is now part ofCREATE FUNCTION. This fixes the failure above.
Table functions (RETURNS TABLE (...)) are out of scope until dbt-core models return columns (dbt-labs/dbt#12492).
Describe alternatives you've considered
- Write the clauses inside
data_type, for exampledata_type: "int DEFAULT 2 COMMENT 'Row limit'", plusCOMMENTafter the type inreturns.data_type. It works becausedata_typeis pasted into the SQL as-is, and that's what we run in production today. But the descriptions stay out of dbt docs, and it relies on unvalidated passthrough. - Override the macros in each project. It works, but every project has to maintain a copy of adapter internals, and it breaks silently if the macros are renamed.
- Always emit the comment, ungated. This is simpler, but it changes the generated SQL for every existing project with function descriptions. Gating on
persist_docsmatches how tables, views, MVs and STs already behave. - Setting the comment after creation: not possible, as explained above.
Additional context
- Versions: dbt-databricks 1.13.0, dbt-core 1.12.x.
- dbt-postgres and dbt-snowflake already render
default_valuein theirformatted_scalar_function_args_sqloverrides, so per-adapter rendering is the established pattern. - Newer dbt-tests-adapter releases ship
SqlUDFDefaultArgSupport/PythonUDFDefaultArgSupport(used by the Postgres, Snowflake, BigQuery and Redshift adapters), but the version dbt-databricks pins doesn't include them yet. The PR adds Databricks functional tests that check the same behaviour againstinformation_schema: the SQL default applies, and the Python default is ignored.
Who will this benefit?
Teams that use dbt functions as a governed definition layer in Unity Catalog. We manage about 50 shared business-logic UDFs (time-zone conversion, cohort assignment, funnel metrics, and so on) with dbt. Analysts, Genie spaces and AI agents find and choose them through their UC comments. We currently keep the comments inside data_type, and this change would let us move them into normal description fields.
Are you interested in contributing this feature?
Yes, I'd like to implement it: the macros plus unit tests for argument and function comments, defaults, escaping, persist_docs gating and the persist_docs skip, a functional test against a SQL warehouse, and a CHANGELOG entry. Happy to adjust the design, especially the persist_docs gating, before opening the PR.
- 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
-
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
-
Metadata queries break on catalog, schema or table names containing a quote or backslashPosiblemente ocupada @MsMansiDhruv la tomó hace 14 días. Abiertobug
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
databricks/dbt-databricks#1747 ·
Los mantenedores suelen responder en 6 días
Todos los issues de databricks/dbt-databricks
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
aws-samples/sample-per-model-bedrock#857 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
521xueweihan/HelloGitHub#4328 ·
-
documentation maintainer-managed
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
awslabs/visual-asset-management-system#1418 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día