在共享视图中引用导入的数据库

Referencing an Imported Database In a Shared View

我感觉我知道这个问题的答案,但我不喜欢它,所以我希望某个地方可以让我免于大规模重构。开始了。

我的 Snowflake 项目由两个关键数据库组成:

  1. external_sales_data_share - 另一个 Snowflake 帐户提供的导入数据库
  2. client_facing_database - 内部拥有的本地数据库

client_facing_database 包含一个利用来自 external_sales_data_share 的数据的视图。例如:

CREATE OR REPLACE SECURE VIEW client_facing_database.external.data.sales_data AS
SELECT 
col1 field_1,
col3 field_2
FROM external_sales_data_share.data.sales_data
where client_id = xxxx;

视图按预期工作,没有问题。但是,当我尝试与我的客户共享视图时,我无法做到,因为我的视图引用了导入的数据库。

//Create Share    
CREATE OR REPLACE SHARE CLIENT_SHARE;

// Allow share to access the database and schema of the views    
grant usage on database client_facing_database to share CLIENT_SHARE;
grant usage on schema client_facing_database.data to share CLIENT_SHARE;

以上工作正常。当我尝试将特定视图添加到共享时收到错误消息。

// Command to add View to share
grant select on view client_facing_database.data.sales_data to share CLIENT_SHARE;


// Error returned
"A view or function being shared cannot reference objects from other databases."

我知道上述错误是预料之中的,我应该 grant reference_usage 我的共享,以便它可以从我的视图中利用的表中读取。但是下面的命令,我认为是正确的returns一个错误。

 // Command to allow the share access to the reference database (which is share/imported)
 grant reference_usage on database external_sales_data_share to share CLIENT_SHARE;

 // The error message returned
 "Granting individual privileges on imported database is not allowed. Use 'GRANT IMPORTED PRIVILEGES' instead."

深入研究 Snowflake 文档后发现,我尝试做的事情似乎是不可能的,因为他们对 GRANTING IMPORTED PRIVILEGES 的建议是在角色而不是共享级别上完成的。

所以....我的问题是什么?

  1. 我是否确实正确,不能共享引用一个视图的视图 导入数据库?
  2. 在将要共享的视图中使用导入的数据库是否有解决方法?

感谢大家的帮助!

  1. 你说得对,你不能分享。这在下面数据消费者的限制部分中有说明:https://docs.snowflake.com/en/user-guide/data-share-consumers.html#general-limitations-for-shared-databases

  2. 我想您必须创建一个 table 到本地数据库,用您使用的数据填充它并共享 table 而不是