Skip to content
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

SPIKE - BigQuery support for iceberg materialisations #1371

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{%- set raw_partition_by = config.get('partition_by', none) -%}
{%- set raw_cluster_by = config.get('cluster_by', none) -%}
{%- set sql_header = config.get('sql_header', none) -%}

{%- set table_format = config.get('table_format', 'default') -%}
{%- set partition_config = adapter.parse_partition_by(raw_partition_by) -%}
{%- if partition_config.time_ingestion_partitioning -%}
{%- set columns = get_columns_with_types_in_query_sql(sql) -%}
Expand All @@ -23,10 +23,41 @@
{#-- cannot do contracts at the same time as time ingestion partitioning -#}
{{ columns }}
{% endif %}
{{ partition_by(partition_config) }}
{%- if table_format == "iceberg" and partition_config is not none-%}
{% do exceptions.raise_compiler_error("Partition by not yet available in iceberg tables, use cluster by instead") %}
{#-- PARTITION BY cannot be used in iceberg-#}
{%- else -%}
{{ partition_by(partition_config) }}
{% endif %}

{{ cluster_by(raw_cluster_by) }}

{{ bigquery_table_options(config, model, temporary) }}
{% if table_format == "iceberg" %}

{% set base_location = config.get('base_location') %}
{%- if not base_location-%}
{% do exceptions.raise_compiler_error("base_location not found") %}
{% endif %}
{% set connection = config.get('connection') %}
{%- if not connection-%}
{% do exceptions.raise_compiler_error("Bq connection not found") %}
{% endif %}
{% set sub_path = relation.identifier %}
{% set connection = "WITH CONNECTION `"~connection~"`" %}
{#-- pass this through {{ bigquery_table_options(config, model, temporary) }}-#}
{% set options %}
OPTIONS(
file_format = 'PARQUET',
table_format = 'ICEBERG',
storage_uri = '{{base_location}}/{{sub_path}}'
)
{%- endset -%}

{{ connection }}
{{ options }}

{% endif %}


{#-- PARTITION BY cannot be used with the AS query_statement clause.
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#partition_expression
Expand Down