Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: table clustering/partitioning support. #2077

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
23 changes: 23 additions & 0 deletions products/bigquery/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ objects:
- !ruby/object:Api::Type::String
name: 'tableId'
description: The ID of the the table
- !ruby/object:Api::Type::Array
name: 'clustering'
description: |
One or more fields on which data should be clustered. Only
top-level, non-repeated, simple-type fields are supported. When
you cluster a table using multiple columns, the order of columns
you specify is important. The order of the specified columns
determines the sort order of the data.
item_type: Api::Type::String
- !ruby/object:Api::Type::Integer
name: 'creationTime'
output: true
Expand Down Expand Up @@ -223,6 +232,11 @@ objects:
description: |
The number of rows of data in this table, excluding any data in the
streaming buffer.
- !ruby/object:Api::Type::Boolean
name: 'requirePartitionFilter'
description: |
If set to true, queries over this table require a partition filter
that can be used for partition elimination to be specified.
output: true
- !ruby/object:Api::Type::Enum
name: 'type'
Expand Down Expand Up @@ -269,6 +283,15 @@ objects:
description: |
Number of milliseconds for which to keep the storage for a
partition.
- !ruby/object:Api::Type::String
name: 'field'
description: |
If not set, the table is partitioned by pseudo column,
referenced via either '_PARTITIONTIME' as TIMESTAMP type, or
'_PARTITIONDATE' as DATE type. If field is specified, the table
is instead partitioned by this field. The field must be a
top-level TIMESTAMP or DATE field. Its mode must be NULLABLE or
REQUIRED.
- !ruby/object:Api::Type::Enum
name: 'type'
description: |
Expand Down
21 changes: 21 additions & 0 deletions third_party/terraform/resources/resource_bigquery_table.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ func resourceBigQueryTable() *schema.Resource {
},
},

// Clustering: [Optional] Specifies column names to use for data clustering. Up to four
// top-level columns are allowed, and should be specified in descending priority order.
"clustering": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 4,
Elem: &schema.Schema{Type: schema.TypeString},
},

// CreationTime: [Output-only] The time when this table was created, in
// milliseconds since the epoch.
"creation_time": {
Expand Down Expand Up @@ -435,6 +445,13 @@ func resourceTable(d *schema.ResourceData, meta interface{}) (*bigquery.Table, e
table.TimePartitioning = expandTimePartitioning(v)
}

if v, ok := d.GetOk("clustering"); ok {
table.Clustering = &bigquery.Clustering{
Fields: convertStringArr(v.([]interface{})),
ForceSendFields: []string{"Fields"},
}
}

return table, nil
}

Expand Down Expand Up @@ -514,6 +531,10 @@ func resourceBigQueryTableRead(d *schema.ResourceData, meta interface{}) error {
}
}

if res.Clustering != nil {
d.Set("clustering", res.Clustering.Fields)
}

if res.Schema != nil {
schema, err := flattenSchema(res.Schema)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion third_party/terraform/tests/resource_bigquery_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,21 @@ resource "google_bigquery_table" "test" {
field = "ts"
require_partition_filter = true
}

clustering = ["some_int", "some_string"]
schema = <<EOH
[
{
"name": "ts",
"type": "TIMESTAMP"
},
{
"name": "some_string",
"type": "STRING"
tysen marked this conversation as resolved.
Show resolved Hide resolved
},
{
"name": "some_int",
"type": "INTEGER"
},
{
"name": "city",
"type": "RECORD",
Expand Down