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        

请求产品价格

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