generate_dbt_yml_schema - BigQuery

Function

generate_dbt_yml_schema(project_id, dataset_id)

Description

Generate Dbt Yml Schema - Generates a DBT schema.yml using the information_schema of the generated tables for the specified <project_id> and <dataset_id>. For this function to work you need to create your own function in your dataset.

Example Query


SELECT `justfunctions.eu.generate_dbt_yml_schema`("justfunctions", "eu")
                                            
/*--Output--
version: 2 models: - name: country_distinct columns: - name: service_country - name: official_name - name: alpha_2
*/

Statement

CREATE OR REPLACE FUNCTION `your_project_id.your_dataset_id.generate_dbt_yml_schema`(`project_id` string, `dataset_id` string) 
  RETURNS string AS ((with columns as (
    select '- name: ' || column_name || '' as column_statement,
        table_name
    from `your_project_id.your_dataset_id`.INFORMATION_SCHEMA.COLUMNS

),
tables as (
select table_name,
"  - name: " || 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)
)
  OPTIONS ( description = '''Generates a DBT schema.yml using the information_schema of the generated tables for the specified <project_id> and <dataset_id>. For this function to work you need to create your own function in your dataset.''')

Regions

justfunctions.eu.generate_dbt_yml_schema(project_id, dataset_id),
justfunctions.us.generate_dbt_yml_schema(project_id, dataset_id)

Source

Type

SQL User Defined Function (SQL UDF)

How to Use

Frequently Asked Questions

User-Defined Functions (UDFs) in Google BigQuery are custom functions that you can create to perform operations that aren't available through the standard SQL functions. These UDFs allow you to extend BigQuery's SQL capabilities to suit your specific data processing needs. JustFunctions is a collection of open-source user-defined functions (UDFs).

JustFunctions is a collection of open-source User-Defined Functions (UDFs) designed to extend the capabilities of Google BigQuery. These functions cover a wide range of applications, including text manipulation, URL processing, date processing, email handling, similarity measures, and more. Moreover, JustFunctions is frequently updated to include more use cases.

We welcome any feedback or questions you may have. You can Contact us or report an issue on Github.

Functions and procedures from JustFunctions can be used directly in any of your projects.
To start, simply click 👆 on any function,  Copy  the 'Example Query' and run it in your BigQuery console.
You can also  Copy  the 'Statement' to create your own private user-defined function.

Yes, JustFunctions is completely free to use.

Yes, currently JustFunctions is only available for Google BigQuery. In the future, we will also support PostgreSQL.

See something wrong? Contact us or report an issue on Github.