From 10bc49100be2afa63be91e26af8987775dd188bd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:09:27 -0400 Subject: [PATCH] Fix null column index issue during `dbt docs generate` for external tables (#1085) (#1257) (#1258) * coalesce column metadata columns with a value to avoid null errors for external tables in docs generate Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> (cherry picked from commit 995ebcba164241f1390b637953bf4192c06d63db) Co-authored-by: Jeremy Cohen --- .changes/unreleased/Fixes-20240201-145323.yaml | 6 ++++++ dbt/include/bigquery/macros/catalog/catalog.sql | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Fixes-20240201-145323.yaml diff --git a/.changes/unreleased/Fixes-20240201-145323.yaml b/.changes/unreleased/Fixes-20240201-145323.yaml new file mode 100644 index 000000000..ea198e54a --- /dev/null +++ b/.changes/unreleased/Fixes-20240201-145323.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix null column index issue during `dbt docs generate` for external tables +time: 2024-02-01T14:53:23.434624-05:00 +custom: + Author: mikealfare + Issue: "1079" diff --git a/dbt/include/bigquery/macros/catalog/catalog.sql b/dbt/include/bigquery/macros/catalog/catalog.sql index de16f82bf..268debc5f 100644 --- a/dbt/include/bigquery/macros/catalog/catalog.sql +++ b/dbt/include/bigquery/macros/catalog/catalog.sql @@ -121,10 +121,12 @@ end as table_name, tables.table_type, tables.table_comment, - columns.column_name, - columns.column_index, - columns.column_type, - columns.column_comment, + -- coalesce column metadata fields to ensure they are non-null for catalog generation + -- external table columns are not present in COLUMN_FIELD_PATHS + coalesce(columns.column_name, '') as column_name, + coalesce(columns.column_index, 1) as column_index, + coalesce(columns.column_type, '') as column_type, + coalesce(columns.column_comment, '') as column_comment, 'Shard count' as `stats__date_shards__label`, table_stats.shard_count as `stats__date_shards__value`,