Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created July 7, 2017 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugyo/7b51d286b2728e426dfb88e627501e01 to your computer and use it in GitHub Desktop.
Save jugyo/7b51d286b2728e426dfb88e627501e01 to your computer and use it in GitHub Desktop.
A patch to add a method Gogole::Cloud::Bigquery::Dataset#create_time_partitioned_table
module Google
module Cloud
module Bigquery
class Dataset
def create_time_partitioned_table table_id, name: nil, description: nil, type: 'DAY', expiration_ms: nil
ensure_service!
new_tb = Google::Apis::BigqueryV2::Table.new(
table_reference: Google::Apis::BigqueryV2::TableReference.new(
project_id: project_id, dataset_id: dataset_id,
table_id: table_id),
time_partitioning: Google::Apis::BigqueryV2::TimePartitioning.new(
type: 'DAY',
expiration_ms: expiration_ms))
updater = Table::Updater.new(new_tb).tap do |tb|
tb.name = name unless name.nil?
tb.description = description unless description.nil?
end
yield updater if block_given?
gapi = service.insert_table dataset_id, updater.to_gapi
Table.from_gapi gapi, service
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment