首页 > 解决方案 > Bigquery dbt_external_tables 外部数据配置

问题描述

在使用 dbt_external_tables 包时我需要一些帮助。

我意识到在我在 GCS 中的 csv 中,有些行似乎有换行符,这在尝试查询由宏创建的表时会导致一些问题。

有时,手动配置外部表时,BigQuery UI 有两个选项: 允许锯齿状行 (CSV) 允许带引号的换行符 (CSV) true 我通常将这些选项设置为 true,有时问题就解决了。我不知道如何使用 dbt_external_tables 来做到这一点。

这很重要,因为我在尝试查询 dbt 创建的表时收到此错误“读取表时出错:kpi-process.file_csv.History,错误消息:CSV 表引用列位置 9,但从位置开始的行:10956 包含只有 7 列。”

标签: google-bigqueryexternal-tablescloud-storagedbt

解决方案


dbt-external-tables包支持传递BigQuery 外部表的字典,该字典映射到options此处记录的选项。在您的情况下,听起来您想打开allow_jagged_rowsand allow_quoted_newlines,因此您可以像这样指定它们:

version: 2
sources:
 - name: my_external_source
   tables:
     - name: my_external_table
       location: 'gs://bucket/path/*'
       options:
         format: csv
         allow_jagged_rows: true
         allow_quoted_newlines: true

并且 dbt 将相应地模板化 DDL 语句:

create or replace external statement my_external_source.my_external_table
options (
  format = 'csv',
  allow_jagged_rows = true,
  allow_quoted_newlines = true,
  uris = ['gs://bucket/path/*']
)

推荐阅读