GoogleCloud BigQuery 异常处理

Ale*_*x L 4 google-bigquery google-cloud-platform

我正在尝试运行以下 GooleCould 的 BigQuery:

select REGEXP_REPLACE(SPLIT(site, "=")[OFFSET(1)], r'%\d+', ' ')
    from some_db
    where site = 'something'
    and STARTS_WITH(site, 'XXX')
Run Code Online (Sandbox Code Playgroud)

在执行过程中,我收到以下错误:

数组索引 1 越界(溢出)

当我使用 AWS Athena 时,我曾经使用try语句解决此类错误,但我找不到与 BigQuery 等效的任何内容。

我应该如何处理异常?

Mik*_*ant 5

您应该使用 SAFE_OFFSET 而不是 OFFSET

select REGEXP_REPLACE(SPLIT(site, "=")[SAFE_OFFSET(1)], r'%\d+', ' ')
from some_db
where site = 'something'
and STARTS_WITH(site, 'XXX')   
Run Code Online (Sandbox Code Playgroud)

至于更通用的 try/catch 问题 - BigQuery 没有 - 但有一个 SAFE 前缀,可以在大多数函数中用作 SAFE.function_name() - https://cloud.google.com/bigquery/docs/reference /standard-sql/functions-and-operators#safe-prefix