Snowflake 物化视图可以包含半结构化数据的扁平化吗?
Can a Snowflake materialized view contain flatten of semi-structured data?
文末建议物化视图可以包含flatten ... https://www.snowflake.com/blog/snowflake-materialized-views-a-fast-zero-maintenance-accurate-solution/
但是如果我尝试它,我会得到一个错误... "More than one table referenced in the view definition"
任何人有任何关于如何使用扁平化创建 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;
以下对我来说效果很好。您需要 FLATTEN()
用于 ARRAY,但不需要用于 OBJECT。
也许你把两者混在一起了?
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);
文末建议物化视图可以包含flatten ... https://www.snowflake.com/blog/snowflake-materialized-views-a-fast-zero-maintenance-accurate-solution/ 但是如果我尝试它,我会得到一个错误... "More than one table referenced in the view definition" 任何人有任何关于如何使用扁平化创建 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;
以下对我来说效果很好。您需要 FLATTEN()
用于 ARRAY,但不需要用于 OBJECT。
也许你把两者混在一起了?
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);