繁体   English   中英

BigQuery - 如何在创建视图时更改嵌套列的架构顺序?

[英]BigQuery - how to change the order of the schema with nested columns when creating a view?

我想更改嵌套在我的 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    

表2

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,
 productPrice.taxRate,
 productPrice.taxType,
 productPrice.priceStartDate,
 productPrice.currency,
 productPrice.price,
 productPrice.type,
FROM table2

没有产品价格的请求

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,
 productPrice.taxRate,
 productPrice.taxType,
 productPrice.priceStartDate,
 productPrice.currency,
 productPrice.price,
 productPrice.type,
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.taxType,
    productPrice.priceStartDate,
    productPrice.currency,
    productPrice.price,
    productPrice.type
  )
FROM table2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM