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

Added time_partitioning.field parameter to action migrate_partitioned_table #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions example/migrate_partitioned_table.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ actions:
- action: migrate_partitioned_table
<<: *bigquery
schema_file: example/schema.json
options:
time_partitioning:
field: timestamp
- action: delete_table
<<: *bigquery
4 changes: 3 additions & 1 deletion lib/bigquery_migration/bigquery_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def insert_table(dataset: nil, table: nil, columns:, options: {})
body[:time_partitioning] = {
type: options['time_partitioning']['type'],
expiration_ms: options['time_partitioning']['expiration_ms'],
field: options['time_partitioning']['field'],
}
end

Expand Down Expand Up @@ -217,7 +218,8 @@ def insert_table(dataset: nil, table: nil, columns:, options: {})
alias :create_table :insert_table

def insert_partitioned_table(dataset: nil, table: nil, columns:, options: {})
options['time_partitioning'] = {'type'=>'DAY'}
options['time_partitioning'] ||= {}
options['time_partitioning']['type'] = 'DAY'
insert_table(dataset: dataset, table: table, columns: columns, options: options)
end
alias :create_partitioned_table :insert_partitioned_table
Expand Down
9 changes: 8 additions & 1 deletion test/test_bigquery_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,26 @@ def teardown

def test_create_partitioned_table
columns = [
{ name: 'partition_column', type: 'TIMESTAMP' },
{ name: 'remained_column', type: 'INTEGER' },
{ name: 'record', type: 'RECORD', fields: [
{ name: 'record', type: 'RECORD', fields: [
{ name: 'remained_column', type: 'STRING' },
] }
] }
]
options = {
'time_partitioning' => { 'expiration_ms' => 86400000, 'field' => 'partition_column' },
}

expected = columns.dup

result = instance.migrate_partitioned_table(columns: columns)
result = instance.migrate_partitioned_table(columns: columns, options: options)
after_columns = result[:after_columns]

assert { result[:responses][:insert_table].time_partitioning.type == 'DAY' }
assert { result[:responses][:insert_table].time_partitioning.expiration_ms == 86400000 }
assert { result[:responses][:insert_table].time_partitioning.field == 'partition_column' }
assert { Schema.diff_columns(expected, after_columns) == [] }
assert { Schema.diff_columns(after_columns, expected) == [] }
end
Expand Down