Create
These functions are used to create resources from arbitrary SQL definitions and options.
Functions
create_table
Attribute | Value |
---|---|
Name | create_table |
ID | bqtools.[region].create_table |
Description | Creates or replaces a single BASE TABLE defined by an arbitrary sql query_statement , with options defined in alignment with the CREATE TABLE DDL statement. See the example below for table_options structure. |
Type | PROCEDURE |
Arguments | table_id STRING, query_statement STRING, table_options JSON |
Returns | None |
Dependencies | bqtools-qb.[region].create_table |
Beta
This create_table
function is in beta as only the partition_expression
and clustering_column_list
options of the table_options
have been implemented. See the example below for the JSON argument structure.
execution: create_table
CALL bqtools.eu.create_table(table_id, query_statement, table_options);
CALL bqtools.us.create_table(table_id, query_statement, table_options);
example: create_table
DECLARE table_id, query_statement STRING;
DECLARE table_options JSON;
SET table_id = 'project_id.dataset_name.destination_table_name';
SET query_statement = 'SELECT * FROM `project_id.dataset_name.source_table_name`';
SET table_options = JSON """
{
"partition_expression": "DATE(_PARTITIONTIME)",
"clustering_column_list": "column_a, column_b"
}
""";
CALL bqtools.[region].create_table(table_id, query_statement, table_options);
create_view
Attribute | Value |
---|---|
Name | create_view |
ID | bqtools.[region].create_view |
Description | Creates or replaces a single VIEW defined by an arbitrary sql query_statement , with options defined in alignment with the CREATE VIEW DDL statement. |
Type | PROCEDURE |
Arguments | view_id STRING, query_statement STRING, view_options JSON |
Returns | None |
Dependencies | bqtools-qb.[region].create_view |
Beta
This create_view
function is in beta as not all of the view_options
have been implemented.
execution: create_view
CALL bqtools.eu.create_view(view_id, query_statement, view_options);
CALL bqtools.us.create_view(view_id, query_statement, view_options);
create_table_from_table_function
Attribute | Value |
---|---|
Name | create_table_from_table_function |
ID | bqtools.[region].create_table_from_table_function |
Description | Creates or replaces a single Table defined by an arbitrary sql Table Function ID , with options defined in alignment with the CREATE TABLE DDL statement. |
Type | PROCEDURE |
Arguments | destination_table_id STRING, source_table_function_id STRING, start_date DATE, end_date DATE, table_options JSON |
Returns | None |
Dependencies | bqtools-qb.[region].create_table_from_table_function , bqtools-qb.[region].create_table |
Beta
This create_table_from_table_function
function is in beta as only the partition_expression
and clustering_column_list
options of the table_options
have been implemented. See the example below for the JSON argument structure.
execution: create_table_from_table_function
CALL bqtools.eu.create_table_from_table_function(destination_table_id, source_table_function_id, start_date, end_date, table_options);
CALL bqtools.us.create_table_from_table_function(destination_table_id, source_table_function_id, start_date, end_date, table_options);
example: create_table
DECLARE destination_table_id STRING;
DECLARE source_table_function_id STRING;
DECLARE start_date DATE;
DECLARE end_date DATE;
DECLARE table_options JSON;
SET destination_table_id = 'project_id.dataset_name.destination_table_name';
SET source_table_function_id = 'project_id.dataset_name.function_table_name';
SET start_date = PARSE_DATE('%Y%m%d', '20081231');
SET end_date = PARSE_DATE('%Y%m%d', '20231231');
SET table_options = JSON """
{
"partition_expression": "DATE(_PARTITIONTIME)",
"clustering_column_list": "column_a, column_b"
}
""";
SELECT `bqtools-qb.us.create_table_from_table_function`(destination_table_id, source_table_function_id, start_date, end_date, table_options);