-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #326: do not match unsupported ddl followed by open parens
- Loading branch information
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{# Source: https://github.com/tconbeer/sqlfmt/issues/326 #} | ||
{% macro get_unique_attributes(source_table, node_col) %} | ||
|
||
{% set attribute_query %} | ||
select | ||
distinct x.key as attributes | ||
from {{ source_table }} x | ||
where startswith(x.key, '@') -- attributes get parsed as keys that start with '@' | ||
and length(x.key) > 1 -- but keys of just '@' designate the node itself | ||
and regexp_count(x.path, '\\[') > 1 -- we don't need the attributes from the xml root node | ||
and not startswith(x.key, '@xmlns') -- we don't need attributed data about xml namespaces | ||
{% endset %} | ||
|
||
{% set results = run_query(attribute_query) %} | ||
|
||
{% if execute %} | ||
{% set results_list = results.columns[0].values() %} | ||
{% else %} | ||
{% set results_list = [] %} | ||
{% endif %} | ||
|
||
{% for attribute in results_list %} | ||
, get({{ node_col }}, '{{ attribute }}')::varchar(256) as attribute_{{ dbt_utils.slugify(attribute) | replace("@", "") }} | ||
{% endfor %} | ||
|
||
{% endmacro %} | ||
)))))__SQLFMT_OUTPUT__((((( | ||
{# Source: https://github.com/tconbeer/sqlfmt/issues/326 #} | ||
{% macro get_unique_attributes(source_table, node_col) %} | ||
|
||
{% set attribute_query %} | ||
select | ||
distinct x.key as attributes | ||
from {{ source_table }} x | ||
where startswith(x.key, '@') -- attributes get parsed as keys that start with '@' | ||
and length(x.key) > 1 -- but keys of just '@' designate the node itself | ||
and regexp_count(x.path, '\\[') > 1 -- we don't need the attributes from the xml root node | ||
and not startswith(x.key, '@xmlns') -- we don't need attributed data about xml namespaces | ||
{% endset %} | ||
|
||
{% set results = run_query(attribute_query) %} | ||
|
||
{% if execute %} {% set results_list = results.columns[0].values() %} | ||
{% else %} {% set results_list = [] %} | ||
{% endif %} | ||
|
||
{% for attribute in results_list %} | ||
, | ||
get({{ node_col }}, '{{ attribute }}')::varchar( | ||
256 | ||
) as attribute_{{ dbt_utils.slugify(attribute) | replace("@", "") }} | ||
{% endfor %} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters