如何将数据从查询加载到BigQuery上的表

时间:2018-10-15 07:50:27

标签: google-bigquery

我有以下BigQuery表:

orders

[
    {
        "name": "orders_id",
        "type": "INTEGER",
        "mode": "NULLABLE"
    },
    {
        "name": "customer_id",
        "type": "INTEGER",
        "mode": "NULLABLE"
    }
]

customers

[
    {
        "name": "customer_id",
        "type": "INTEGER",
        "mode": "NULLABLE"
    },
    {
        "name": "customer_name",
        "type": "INTEGER",
        "mode": "NULLABLE"
    }
]

我要创建new_orders,如下所示:

[
    {
        "name": "orders_id",
        "type": "INTEGER",
        "mode": "NULLABLE"
    },
    {
        "name": "customer_name",
        "type": "INTEGER",
        "mode": "NULLABLE"
    }
]

因此,我为new_orders创建了一个空表并编写了此查询:

SELECT o.orders_id,c.customer_name
from `project.orderswh.orders` as o
inner join `project.orderswh.customers` as c  on o.customer_id = c.customer_id

我的问题是如何将查询结果中的数据加载到新表中。 我有1500万行。据我所知,定期插入是昂贵的并且非常慢。作为加载工作,我该如何做?

2 个答案:

答案 0 :(得分:2)

您可以从BigQuery Console

执行此操作

请按照以下步骤操作:

1) Show Options 

2) Destination Table 

3) choose dataset and provide "new_orders" as Table ID 

4) then set "Write Preference" to "Write if empty" as this is one time thing as you said

如果需要,还可以查找本教程:https://cloud.google.com/bigquery/docs/writing-results

答案 1 :(得分:1)

您可以使用bq命令行工具:

 defaultConfig {
        applicationId "yodgobekkomilov.edgar.com.worldnews"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }