如何在GCP Dataform中调用BQ存储过程?附代码报错求助
问题:Dataform中调用BigQuery存储过程出现语法错误
问题背景
我计划在Dataform中使用常量值作为参数调用BigQuery存储过程,相关代码及遇到的错误如下:
代码文件
includes/constants_mfg_ccrel.js
const domain_name = 'mf' const transformation_job_grouping = 'ccr_cnf_seq1' const run_id = 'manual__2024-04-19T03:00:22.571539+00:00' const tgt_proj_id = 'ttc-mf' const ssdaa_proj_id = 'ttc-ss' const bq_conf_ds = 'mf_conf' module.exports = {domain_name, transformation_job_grouping, run_id, tgt_proj_id, ssdaa_proj_id, bq_conf_ds};
includes/transformation_table_load_proc_call.js
function Procedure_Call(transformation_job_grouping, run_id) { return `CALL '${constants_mfg_ccrel.tgt_proj_id}.${constants_mfg_ccrel.bq_conf_ds}.transformation_table_load_proc'(${transformation_job_grouping}, ${run_id})`; } module.exports = { Procedure_Call };
definitions/ccr_cnf.sqlx
config { type: "operations", tags: ["ccr_cnf_master", "SW"] } ${transformation_table_load_proc_call.Procedure_Call(`'${constants_mfg_ccrel.transformation_job_grouping}'`, `'${constants_mfg_ccrel.run_id}'`)};
报错信息
语法错误:在位置[2:10]处遇到意外的字符串字面量 'ttc-mf.mf_conf.transformation_table_lo...'
问题原因及修复方案
报错的核心原因是BigQuery的CALL语法中,存储过程的完整名称不能用单引号包裹,当前代码给存储过程全名添加了单引号,导致BigQuery无法识别合法的存储过程引用。
只需修改includes/transformation_table_load_proc_call.js,移除存储过程名称两侧的单引号即可:
function Procedure_Call(transformation_job_grouping, run_id) { return `CALL ${constants_mfg_ccrel.tgt_proj_id}.${constants_mfg_ccrel.bq_conf_ds}.transformation_table_load_proc(${transformation_job_grouping}, ${run_id})`; } module.exports = { Procedure_Call };
修正后生成的SQL语句将符合BigQuery语法规范:
CALL ttc-mf.mf_conf.transformation_table_load_proc('ccr_cnf_seq1', 'manual__2024-04-19T03:00:22.571539+00:00');
内容的提问来源于stack exchange,提问作者Santanu Ghosh
相关产品推荐
相关产品推荐

