Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
BigQuery: table clustering/partitioning support. (#179)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and Stuart Paterson committed Aug 23, 2019
1 parent 762f589 commit f2233f3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/resources/google_bigquery_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Properties that can be accessed from the `google_bigquery_table` resource:

* `table_id`: The ID of the the table

* `clustering`: 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.

* `creation_time`: The time when this dataset was created, in milliseconds since the epoch.

* `description`: A user-friendly description of the dataset
Expand All @@ -54,6 +56,8 @@ Properties that can be accessed from the `google_bigquery_table` resource:

* `num_rows`: The number of rows of data in this table, excluding any data in the streaming buffer.

* `require_partition_filter`: If set to true, queries over this table require a partition filter that can be used for partition elimination to be specified.

* `type`: Describes the table type

* `view`: The view definition.
Expand All @@ -66,6 +70,8 @@ Properties that can be accessed from the `google_bigquery_table` resource:

* `expiration_ms`: Number of milliseconds for which to keep the storage for a partition.

* `field`: 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.

* `type`: The only type supported is DAY, which will generate one partition per day.

* `streaming_buffer`: Contains information regarding this table's streaming buffer, if one is present. This field will be absent if the table is not being streamed to or if there is no data in the streaming buffer.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/google_bigquery_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Properties that can be accessed from the `google_bigquery_tables` resource:

See [google_bigquery_table.md](google_bigquery_table.md) for more detailed information
* `table_references`: an array of `google_bigquery_table` table_reference
* `clusterings`: an array of `google_bigquery_table` clustering
* `creation_times`: an array of `google_bigquery_table` creation_time
* `friendly_names`: an array of `google_bigquery_table` friendly_name
* `ids`: an array of `google_bigquery_table` id
Expand All @@ -32,6 +33,7 @@ See [google_bigquery_table.md](google_bigquery_table.md) for more detailed infor
* `num_bytes`: an array of `google_bigquery_table` num_bytes
* `num_long_term_bytes`: an array of `google_bigquery_table` num_long_term_bytes
* `num_rows`: an array of `google_bigquery_table` num_rows
* `require_partition_filters`: an array of `google_bigquery_table` require_partition_filter
* `types`: an array of `google_bigquery_table` type
* `views`: an array of `google_bigquery_table` view
* `time_partitionings`: an array of `google_bigquery_table` time_partitioning
Expand Down
3 changes: 3 additions & 0 deletions libraries/google/bigquery/property/table_time_partitioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ module Property
class TableTimePartitioning
attr_reader :expiration_ms

attr_reader :field

attr_reader :type

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@expiration_ms = args['expirationMs']
@field = args['field']
@type = args['type']
end

Expand Down
4 changes: 4 additions & 0 deletions libraries/google_bigquery_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Table < GcpResourceBase

attr_reader :params
attr_reader :table_reference
attr_reader :clustering
attr_reader :creation_time
attr_reader :description
attr_reader :friendly_name
Expand All @@ -49,6 +50,7 @@ class Table < GcpResourceBase
attr_reader :num_bytes
attr_reader :num_long_term_bytes
attr_reader :num_rows
attr_reader :require_partition_filter
attr_reader :type
attr_reader :view
attr_reader :time_partitioning
Expand All @@ -68,6 +70,7 @@ def initialize(params)

def parse
@table_reference = GoogleInSpec::BigQuery::Property::TableTableReference.new(@fetched['tableReference'], to_s)
@clustering = @fetched['clustering']
@creation_time = @fetched['creationTime']
@description = @fetched['description']
@friendly_name = @fetched['friendlyName']
Expand All @@ -79,6 +82,7 @@ def parse
@num_bytes = @fetched['numBytes']
@num_long_term_bytes = @fetched['numLongTermBytes']
@num_rows = @fetched['numRows']
@require_partition_filter = @fetched['requirePartitionFilter']
@type = @fetched['type']
@view = GoogleInSpec::BigQuery::Property::TableView.new(@fetched['view'], to_s)
@time_partitioning = GoogleInSpec::BigQuery::Property::TableTimePartitioning.new(@fetched['timePartitioning'], to_s)
Expand Down
4 changes: 4 additions & 0 deletions libraries/google_bigquery_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Tables < GcpResourceBase
filter_table_config = FilterTable.create

filter_table_config.add(:table_references, field: :table_reference)
filter_table_config.add(:clusterings, field: :clustering)
filter_table_config.add(:creation_times, field: :creation_time)
filter_table_config.add(:friendly_names, field: :friendly_name)
filter_table_config.add(:ids, field: :id)
Expand All @@ -33,6 +34,7 @@ class Tables < GcpResourceBase
filter_table_config.add(:num_bytes, field: :num_bytes)
filter_table_config.add(:num_long_term_bytes, field: :num_long_term_bytes)
filter_table_config.add(:num_rows, field: :num_rows)
filter_table_config.add(:require_partition_filters, field: :require_partition_filter)
filter_table_config.add(:types, field: :type)
filter_table_config.add(:views, field: :view)
filter_table_config.add(:time_partitionings, field: :time_partitioning)
Expand Down Expand Up @@ -82,6 +84,7 @@ def transform(key, value)
def transformers
{
'tableReference' => ->(obj) { return :table_reference, GoogleInSpec::BigQuery::Property::TableTableReference.new(obj['tableReference'], to_s) },
'clustering' => ->(obj) { return :clustering, obj['clustering'] },
'creationTime' => ->(obj) { return :creation_time, obj['creationTime'] },
'friendlyName' => ->(obj) { return :friendly_name, obj['friendlyName'] },
'id' => ->(obj) { return :id, obj['id'] },
Expand All @@ -91,6 +94,7 @@ def transformers
'numBytes' => ->(obj) { return :num_bytes, obj['numBytes'] },
'numLongTermBytes' => ->(obj) { return :num_long_term_bytes, obj['numLongTermBytes'] },
'numRows' => ->(obj) { return :num_rows, obj['numRows'] },
'requirePartitionFilter' => ->(obj) { return :require_partition_filter, obj['requirePartitionFilter'] },
'type' => ->(obj) { return :type, obj['type'] },
'view' => ->(obj) { return :view, GoogleInSpec::BigQuery::Property::TableView.new(obj['view'], to_s) },
'timePartitioning' => ->(obj) { return :time_partitioning, GoogleInSpec::BigQuery::Property::TableTimePartitioning.new(obj['timePartitioning'], to_s) },
Expand Down

0 comments on commit f2233f3

Please sign in to comment.