bq命令行工具 - 如何插入具有嵌套字段的大查询表?

时间:2016-12-17 06:36:53

标签: google-bigquery

我有三个BigQuery表,如下所示

员工

Employee_id | Department_id | Location_id | Name | Age

Department_id | Department_Name | Department_Code

位置

Location_id | Country | State | City

以下查询用于连接所有三个表,

SELECT
  e.Employee_id,
  e.Name,
  e.Age,
  e.Department_id,
  d.Department_Name,
  d.Department_Code,
  l.Location_id,
  l.Country , 
  l.State,
  l.City
FROM Employee e
JOIN Department d
  ON e.Department_id = d. Department_id
JOIN Location l
  ON e.Location_id = l.Location_id

如何使用bq命令行实用程序(bq查询命令)将此结果集插入到具有嵌套字段的模式下的BigQuery表中?

enter image description here

1 个答案:

答案 0 :(得分:1)

  

如何将此结果集插入到具有嵌套字段的架构下方的BigQuery表中?

以下是BigQuery Standard SQL

SELECT
    e.Employee_id,
    e.Name,
    e.Age,
    STRUCT<Department_id STRING, Department_Name STRING, Department_Code STRING>(
                  e.Department_id, d.Department_Name, d.Department_Code) AS Department,
    STRUCT<Location_id STRING, Country STRING, State STRING, City STRING>(
                                l.Location_id, l.Country, l.State, l.City) AS Location
FROM Employee e
JOIN Department d
    ON e.Department_id = d. Department_id
JOIN Location l
    ON e.Location_id = l.Location_id
  

...使用bq命令行实用程序(bq查询命令)?

bq query --use_legacy_sql=false --append_table --destination_table 'dataset.table' '**`above query`**'

有关详细信息,请参阅herebq-command-line-tool