我已经阅读了有关该文档的文档,但是似乎找不到上面明确说明的内容。
有帮助吗?
答案 0 :(得分:1)
您不能修改现有表,但是可以编写覆盖现有表的查询。
请参见part
CREATE TABLE `fh-bigquery.wikipedia_v3.pageviews_2017`
PARTITION BY DATE(datehour)
CLUSTER BY wiki, title
OPTIONS(
description="Wikipedia pageviews - partitioned by day, clustered by (wiki, title). Contact https://twitter.com/felipehoffa"
, require_partition_filter=true
)
AS SELECT * FROM `fh-bigquery.wikipedia_v2.pageviews_2017`
WHERE datehour > '1990-01-01' # nag
答案 1 :(得分:0)
如果表已分区,API 现在允许向现有表添加集群。不幸的是,您只能通过其中一个 API 执行此操作,而通过“bq”似乎无法做到。
以下是 Java 示例:
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Clustering;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.FieldList;
import com.google.cloud.bigquery.LegacySQLTypeName;
import com.google.cloud.bigquery.Schema;
import com.google.cloud.bigquery.StandardTableDefinition;
import com.google.cloud.bigquery.StandardTableDefinition.Builder;
import com.google.cloud.bigquery.Table;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
public class SetClustering {
public static void main(String[] args) {
String datasetName = args[0];
String tableId = args[1];
String columnName = args[2];
setClusterByColumn(columnName, datasetName, tableId);
}
public static void setClusterByColumn(String columnName, String datasetName, String tableId) {
try {
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
Table table = bigquery.getTable(datasetName, tableId);
StandardTableDefinition definition = table.getDefinition();
StandardTableDefinition newDefinition = definition.toBuilder()
.setClustering(Clustering.newBuilder().setFields(ImmutableList.of("event_name")).build())
.build();
// Update the table with the new definition
Table updatedTable =
table.toBuilder().setDefinition(newDefinition).build();
updatedTable.update();
System.out.println("Clustering successfully added to table");
} catch (BigQueryException e) {
System.out.println("Clustering column was not added. \n" + e.toString());
}
}
}