Snowflake的物化视图可以包含半结构化数据的拼合吗?

时间:2019-10-28 09:23:03

标签: flatten materialized-views snowflake-data-warehouse

本文结尾表明,物化视图可以包含扁平化的https://www.snowflake.com/blog/snowflake-materialized-views-a-fast-zero-maintenance-accurate-solution/ 但是,如果尝试尝试,则会出现错误...“视图定义中引用了多个表” 有人知道如何创建带有展平的MV的示例吗?

CREATE OR REPLACE MATERIALIZED VIEW MV_SOMETHING
AS
SELECT
    F.ID,
    A.VALUE:Type::string                    AS ATTRIBUTE_TYPE,
    A.VALUE:Value::string                   AS ATTRIBUTE_VALUE
FROM
    FRAME F
    , lateral flatten(input => F.ENVIRONMENT) A;

1 个答案:

答案 0 :(得分:0)

以下对我来说很好。您需要FLATTEN()用于阵列,但不需要用于对象。
也许您正在混合两者?

CREATE OR REPLACE TABLE T AS
SELECT 1 ID, ARRAY_CONSTRUCT(1, 2, 3) A, OBJECT_CONSTRUCT('X', 2, 'Y', 3) O;

CREATE OR REPLACE MATERIALIZED VIEW T_MV AS
SELECT
    ID,
    O:X::NUMBER O_X,
    O:Y::NUMBER O_Y,
    VALUE A
FROM T, LATERAL FLATTEN(INPUT => A);