如何在BigQuqery Ruby API中为查询设置目标表?

时间:2017-02-02 22:43:58

标签: google-bigquery

是否有BigQuery API的方法允许您为查询设置目标表?我在REST API中找到了一个,但没有找到像ruby这样的编程语言。

如果有其他语言的例子..也许我可以尝试在ruby中做同样的事情

4 个答案:

答案 0 :(得分:1)

您需要通过API设置destination table。这些示例代码段中的任何一个都应该很容易移植到Ruby客户端,并且足以让您前进:

<强>爪哇

JobConfiguration jobConfiguration = newBuilder("select * from..)
                    .setAllowLargeResults(true)
                    .setUseLegacySql(false)
                    .setDryRun(dryRun)
                    .setDestinationTable(TableId.of("projectId", "dataset", "table"))
                    .setCreateDisposition(CREATE_IF_NEEDED)
                    .setWriteDisposition(WRITE_TRUNCATE)
                    .setPriority(BATCH)
                    .build();

<强>的Python

from google.cloud import bigquery
client = bigquery.Client()
query = """\
SELECT firstname + ' ' + last_name AS full_name,
       FLOOR(DATEDIFF(CURRENT_DATE(), birth_date) / 365) AS age
 FROM dataset_name.persons
"""
dataset = client.dataset('dataset_name')
table = dataset.table(name='person_ages')
job = client.run_async_query('fullname-age-query-job', query)
job.destination = table
job.write_disposition= 'truncate'
job.begin()

答案 1 :(得分:1)

不知道这是否正是你所要求的 - 但看起来像是:o)

Ruby API Reference Documentation用于Google BigQuery API客户端库。

您可以在BigQuery Client Libraries

中查看所有受支持客户的详情

答案 2 :(得分:0)

您可以使用单个命令查询目标表:

bigquery = Google::Cloud::Bigquery.new(...)
dataset = bigquery.dataset('my_dataset')
job = bigquery.query_job("SELECT * FROM source_table", table: dataset.table('destination_table'), write: 'truncate', create: 'needed')
job.wait_until_done!

来自http://www.rubydoc.info/github/GoogleCloudPlatform/gcloud-ruby/Gcloud%2FBigquery%2FProject%3Aquery_job

答案 3 :(得分:-1)

@mikhailberlyant找到了它。

Bigquery documentation