Last active
March 22, 2024 21:39
-
-
Save eng-rodrigocunha/4df449761d3df6316f9daa345cc683f2 to your computer and use it in GitHub Desktop.
dbt schema.yml generator query using the information_schema of the generated tables for BigQuery
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
WITH | |
columns AS ( | |
SELECT | |
" " || "- name: " || column_name || "\n" || | |
" " || ' description: "' || column_name || '"' AS column_statement, | |
table_name | |
FROM | |
`rj-smtr.veiculo`.INFORMATION_SCHEMA.COLUMNS ), | |
tables AS ( | |
SELECT | |
table_name, | |
" - name: " || table_name || "\n" || | |
' description: "' || table_name || '"\n' || | |
" columns:\n" || STRING_AGG(column_statement, "\n") AS yml_file | |
FROM | |
columns | |
GROUP BY | |
table_name | |
ORDER BY | |
table_name ) | |
SELECT | |
"version: 2\n" || | |
"\n" || | |
"models:\n" || | |
STRING_AGG(yml_file, "\n") AS yml_file | |
FROM | |
tables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment