-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
persist view column comments #866
Changes from all commits
82ee516
2bc4914
2b8fef6
a15cada
9c5138f
5658e5b
50e602e
1ea4178
9916483
f8ff20a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Persist Column level comments when creating views | ||
time: 2023-08-17T13:07:31.6812862Z | ||
custom: | ||
Author: jurasan | ||
Issue: CT-764 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,9 +229,29 @@ | |
{% endfor %} | ||
{% endmacro %} | ||
|
||
{% macro get_column_comment_sql(column_name, column_dict) -%} | ||
{% if column_name in column_dict and column_dict[column_name]["description"] -%} | ||
{% set column_comment_clause = "comment '" ~ column_dict[column_name]["description"] ~ "'" %} | ||
{%- endif -%} | ||
{{ adapter.quote(column_name) }} {{ column_comment_clause }} | ||
mikealfare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{% endmacro %} | ||
|
||
{% macro get_persist_docs_column_list(model_columns, query_columns) %} | ||
{% for column_name in query_columns %} | ||
{{ get_column_comment_sql(column_name, model_columns) }} | ||
{{- ", " if not loop.last else "" }} | ||
mikealfare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{% endfor %} | ||
{% endmacro %} | ||
|
||
{% macro spark__create_view_as(relation, sql) -%} | ||
create or replace view {{ relation }} | ||
{% if config.persist_column_docs() -%} | ||
{% set model_columns = model.columns %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are the model columns coming from? |
||
{% set query_columns = get_columns_in_query(sql) %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that the SQL of the view executed when creating the view with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issuing the get_columns_in_query query against one of the largest table internally at Databricks returned in 148 ms. It is sufficiently performant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regardless of the time, does it execute the SQL to get the columns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It executes a limit 0. |
||
( | ||
{{ get_persist_docs_column_list(model_columns, query_columns) }} | ||
) | ||
{% endif %} | ||
{{ comment_clause() }} | ||
{%- set contract_config = config.get('contract') -%} | ||
{%- if contract_config.enforced -%} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this what you mean? could TLDR's the filter's purpose for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its to escape single-quotes to allow them to be used in the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need it to operate only on the description, I think here you have it operating either on the whole string or on the final ' (I'm not the best at Jinja). In my local copy I moved the extraction and filtering to separate 'set' statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.