Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何获取bigquery表';聚类信息_Google Cloud Platform_Google Bigquery - Fatal编程技术网

Google cloud platform 如何获取bigquery表';聚类信息

Google cloud platform 如何获取bigquery表';聚类信息,google-cloud-platform,google-bigquery,Google Cloud Platform,Google Bigquery,我正试图编写一个通用代码来自动加载多个表的作业 在我尝试为其自动加载作业的表中,有一个表是群集的,我得到以下错误:“不兼容的表分区规范。需要分区规范间隔(类型:天)群集(zipcode,address),但输入分区规范是间隔(类型:天)” 下面是我试图加载表的代码: 我的问题是,给定tableId并假设表已经存在,如何获取表的集群信息以将其设置为loadConfig.setClustering(Clustering) BigQuery BigQuery=BigQueryOptions.getDe

我正试图编写一个通用代码来自动加载多个表的作业

在我尝试为其自动加载作业的表中,有一个表是群集的,我得到以下错误:
“不兼容的表分区规范。需要分区规范间隔(类型:天)群集(zipcode,address),但输入分区规范是间隔(类型:天)”

下面是我试图加载表的代码:
我的问题是,给定tableId并假设表已经存在,如何获取表的集群信息以将其设置为
loadConfig.setClustering(Clustering)

BigQuery BigQuery=BigQueryOptions.getDefaultInstance().getService();
表格ID表格ID=
表1(
FLAG_project.get(),
FLAG_dataset_name.get(),
FLAG_table_name.get());
TimePartitioning=TimePartitioning.of(TimePartitioning.Type.DAY);
CsvOptions CsvOptions=CsvOptions.newBuilder().setAllowJaggedRows(true.build();
LoadJobConfiguration loadConfig=
LoadJobConfiguration.newBuilder(tableId、sourceUri、csvOptions)
.setFormatOptions(FormatOptions.csv())
.setTimePartitioning(分区)
.setWriteDisposition(JobInfo.WriteDisposition.WRITE_追加)
.setAutodetect(错误)
.setMaxBadRecords(1000)
.setIgnoreUnknownValues(真)
.build();
Job loadJob=bigquery.create(JobInfo.of(loadConfig));
loadJob=loadJob.waitFor();

这些选项、分区和集群是在创建表时使用的,例如,如果您正在加载数据,并且如果不存在表,则希望创建该表

如果您专门将数据加载到已经存在的表中,那么我的建议是完全避免分区和集群选项的规范,因为这并不是真正需要的

最后,如果您想要表的集群信息,下面是一个如何实现的示例:

//获取tableId
TableId TableId=TableId.of(projectId,datasetName,tableName);
//收拾桌子
Table Table=bigquery.getTable(tableId);
//得到定义
StandardTableDefinition tableDefinition=table.getDefinition();
//获取聚类信息
集群=tableDefinition.getClustering();
现在,您可以使用它在配置中创建

.setClustering(群集)
您可以这样做:

    from google.cloud import bigquery

    client = bigquery.Client(project="PROJECT_ID")
    table = client.get_table("PROJECT_ID.DATASET.TABLE")
    print(table.clustering_fields)

您可以尝试以下方法:

bq show --format=prettyjson projectName:datasetName.tableName | jq '.clustering.fields[]'
示例:

bq show --format=prettyjson fh-bigquery:wikipedia_v3.pageviews_2017 | jq '.clustering.fields[]'
"wiki"
"title"
输出:

bq show --format=prettyjson fh-bigquery:wikipedia_v3.pageviews_2017 | jq '.clustering.fields[]'
"wiki"
"title"