BigQuery:复制数据集时包含过程

问题描述 投票:0回答:2

我需要将 BigQuery 数据集从一个项目复制到另一个项目。但是,当我按照文档进行操作时 https://cloud.google.com/bigquery/docs/copying-datasets#required_permissions

我只能传输表,而不能传输也存储在同一数据集中的过程。有办法实现吗?

google-bigquery
2个回答
1
投票

为了进一步为社区做出贡献,我将 @MikhalBerlyant 的答案发布为社区 Wiki。

目前有一个开放的功能请求,用于在数据集之间复制过程。虽然没有评估和实施的预计时间,但您可以通过关注此线程来跟踪任何更新,link


0
投票
create config table with all routines name and routine_definition (sql query only)

create or replace table project_id.dataset_id.configtable 
as
SELECT 
  row_number() OVER (order by routine_name) seq_no,
  routine_name,
  routine_definition
FROM 
  `dataset_id.INFORMATION_SCHEMA.ROUTINES`


then loop over the config table 

BEGIN
DECLARE proj_id1 STRING ;
DECLARE proj_id STRING ;
Declare cnt numeric;
declare routine_name string;
declare i numeric;
declare routine_definition string;

SET proj_id1 = (select catalog_name from `region-europe-west2`.INFORMATION_SCHEMA.SCHEMATA 
where catalog_name is not null limit 1) ;

set proj_id=proj_id1;

 
 
EXECUTE IMMEDIATE format(""" select count(routine_name) from `%s.dataset_id.configtable`
""", proj_id) into cnt;

select cnt;
set i=1;
while i<=cnt do
EXECUTE IMMEDIATE format( """ 
(SELECT AS STRUCT table
    FROM
      (SELECT table,
        ROW_NUMBER() OVER() row_number 
      FROM 
      (select routine_name  table
       from `%s.dataset_id.configtable`
        where seq_no="""||i||""" )
      )
)
""",proj_id) into routine_name;
select routine_name;
 
execute immediate format(""" SELECT  routine_definition FROM `%s.dataset_id.configtable` WHERE routine_name = '"""||routine_name||"""' order by 1 ASC limit 1
""",proj_id) into routine_definition;
select routine_definition;
 

execute immediate format("""
 
CREATE OR REPLACE PROCEDURE `%s.dataset_id."""||routine_name||"""`()
 
"""||routine_definition||"""
 
""",proj_id);
 
 

set i=i+1;
end while;
 
end
© www.soinside.com 2019 - 2024. All rights reserved.