在 Google Cloud Build YAML 脚本中分隔 BigQuery REGEXP_EXTRACT 字符串
Delimit BigQuery REGEXP_EXTRACT strings in Google Cloud Build YAML script
我有一个复杂的查询,它在 BigQuery 控制台中创建一个视图。
我已将其简化为以下内容以说明问题
SELECT
REGEXP_EXTRACT(FIELD1, r"[\d]*") as F1,
REGEXP_REPLACE(FIELD2, r"\'", "") AS F2,
FROM `project.mydataset.mytable`
现在我正在尝试使用云构建自动创建视图。
我无法锻炼如何分隔正则表达式中的字符串以同时使用 yaml 和 SQL.
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bq'
args: [
'mk',
'--use_legacy_sql=false',
'--project_id=${_PROJECT_ID}',
'--expiration=0',
'--view=
REGEXP_EXTRACT(FIELD1, r"[\d]*") as F1 ,
REGEXP_REPLACE(FIELD2, r"\'", "") AS F2,
REGEXP_EXTRACT(FIELD3, r"\[(\d{3,12}).*\]") AS F3
FROM `project.mydataset.mytable`"
'${_TARGET_DATASET}.${_TARGET_VIEW}'
]
我收到以下错误
Failed to trigger build: failed unmarshalling build config
cloudbuild/build-views.yaml: json: cannot unmarshal number into Go
value of type string
我已经尝试使用 Cloud Build 替换参数,以及尽可能多的 SQL and YAML 转义序列组合来找到可行的解决方案。
一般来说,在这种情况下您希望使用 block scalars,因为它们不处理其中的任何特殊字符并通过缩进终止。
我不知道该命令应该看起来如何,但这里有一些至少是有效的 YAML:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bq'
args:
- 'mk'
- '--use_legacy_sql=false'
- '--project_id=${_PROJECT_ID}'
- '--expiration=0'
- >- # folded block scalar; newlines are folded into spaces
--view=
REGEXP_EXTRACT(FIELD1, r"[\d]*") as F1,
REGEXP_REPLACE(FIELD2, r"\'", "") AS F2,
REGEXP_EXTRACT(FIELD3, r"\[(\d{3,12}).*\]") AS F3
FROM `project.mydataset.mytable`"
'${_TARGET_DATASET}.${_TARGET_VIEW}'
- dummy value to show that the scalar ends here
折叠块标量以 >
开头,后面的减号告诉 YAML 不要将最后的换行符附加到它的值。
我有一个复杂的查询,它在 BigQuery 控制台中创建一个视图。 我已将其简化为以下内容以说明问题
SELECT
REGEXP_EXTRACT(FIELD1, r"[\d]*") as F1,
REGEXP_REPLACE(FIELD2, r"\'", "") AS F2,
FROM `project.mydataset.mytable`
现在我正在尝试使用云构建自动创建视图。 我无法锻炼如何分隔正则表达式中的字符串以同时使用 yaml 和 SQL.
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bq'
args: [
'mk',
'--use_legacy_sql=false',
'--project_id=${_PROJECT_ID}',
'--expiration=0',
'--view=
REGEXP_EXTRACT(FIELD1, r"[\d]*") as F1 ,
REGEXP_REPLACE(FIELD2, r"\'", "") AS F2,
REGEXP_EXTRACT(FIELD3, r"\[(\d{3,12}).*\]") AS F3
FROM `project.mydataset.mytable`"
'${_TARGET_DATASET}.${_TARGET_VIEW}'
]
我收到以下错误
Failed to trigger build: failed unmarshalling build config cloudbuild/build-views.yaml: json: cannot unmarshal number into Go value of type string
我已经尝试使用 Cloud Build 替换参数,以及尽可能多的 SQL and YAML 转义序列组合来找到可行的解决方案。
一般来说,在这种情况下您希望使用 block scalars,因为它们不处理其中的任何特殊字符并通过缩进终止。
我不知道该命令应该看起来如何,但这里有一些至少是有效的 YAML:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bq'
args:
- 'mk'
- '--use_legacy_sql=false'
- '--project_id=${_PROJECT_ID}'
- '--expiration=0'
- >- # folded block scalar; newlines are folded into spaces
--view=
REGEXP_EXTRACT(FIELD1, r"[\d]*") as F1,
REGEXP_REPLACE(FIELD2, r"\'", "") AS F2,
REGEXP_EXTRACT(FIELD3, r"\[(\d{3,12}).*\]") AS F3
FROM `project.mydataset.mytable`"
'${_TARGET_DATASET}.${_TARGET_VIEW}'
- dummy value to show that the scalar ends here
折叠块标量以 >
开头,后面的减号告诉 YAML 不要将最后的换行符附加到它的值。