如何解决BigQuery-创建视图时如何更改带有嵌套列的架构的顺序?
我想更改嵌套在VIEW上的架构。
但是BigQuery不会这样做,因为我将记录称为“ productPrice”。
的确,如果我不称呼它,则无法将其嵌套在视图中。
我使用“ productPrice”时出现错误消息
Column xx in UNION ALL has incompatible types: STRUCT<type STRING,price DOUBLE,currency STRING,...>,STRUCT<taxRate DOUBLE,taxType STRING,priceStartDate STRING,...> at [xx:x]
表1
productPrice RECORD NULLABLE
productPrice.type STRING NULLABLE
productPrice.price FLOAT NULLABLE
productPrice.currency STRING NULLABLE
productPrice.priceStartDate STRING NULLABLE
productPrice.taxRate FLOAT NULLABLE
productPrice.taxType STRING NULLABLE
table2
productPrice RECORD NULLABLE
productPrice.taxRate FLOAT NULLABLE
productPrice.taxType STRING NULLABLE
productPrice.priceStartDate STRING NULLABLE
productPrice.currency STRING NULLABLE
productPrice.price FLOAT NULLABLE
productPrice.type STRING NULLABLE
带有productPrice的请求
CREATE VIEW product_view AS
SELECT
productPrice,productPrice.taxRate,productPrice.taxType,productPrice.priceStartDate,productPrice.currency,productPrice.price,productPrice.type,from table1
UNION ALL
SELECT
productPrice,FROM table2
没有productPrice的请求
CREATE VIEW product_view AS
SELECT
--productPrice,from table1
UNION ALL
SELECT
--productPrice,FROM table2
视图中没有“ productPrice”的结果
type STRING NULLABLE
taxRate FLOAT NULLABLE
taxType STRING NULLABLE
priceStartDate STRING NULLABLE
currency STRING NULLABLE
price FLOAT NULLABLE
解决方法
以下是用于BigQuery标准SQL
#standardSQL
SELECT
STRUCT(
productPrice.taxRate,productPrice.taxType,productPrice.priceStartDate,productPrice.currency,productPrice.price,productPrice.type
) AS productPrice
FROM table1
UNION ALL
SELECT
STRUCT(
productPrice.taxRate,productPrice.type
)
FROM table2
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。