Skip to content

Commit e9cc945

Browse files
committed
fix: time_partitioning and range_partition config error
1 parent 5398f69 commit e9cc945

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ out:
469469
range:
470470
start: 1
471471
end: 99999
472-
range: 1
472+
interval: 1
473473
```
474474

475475
## Development

lib/embulk/output/bigquery.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,20 @@ def self.configure(config, schema, task_count)
228228
task['abort_on_error'] = (task['max_bad_records'] == 0)
229229
end
230230

231+
if task['time_partitioning'] && task['range_partitioning']
232+
raise ConfigError.new "`time_partitioning` and `range_partitioning` cannot be used at the same time"
233+
end
234+
231235
if task['time_partitioning']
232236
unless task['time_partitioning']['type']
233237
raise ConfigError.new "`time_partitioning` must have `type` key"
234238
end
235-
# If user specify range_partitioning, it should be used as is
236-
elsif Helper.has_partition_decorator?(task['table']) && task['range_partitioning'].nil?
239+
end
240+
241+
if Helper.has_partition_decorator?(task['table'])
242+
if task['range_partitioning']
243+
raise ConfigError.new "partition decorator doesn't support with `range_partition`"
244+
end
237245
task['time_partitioning'] = {'type' => 'DAY'}
238246
end
239247

lib/embulk/output/bigquery/bigquery_client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def create_table_if_not_exists(table, dataset: nil, options: nil)
411411
dataset ||= @dataset
412412
options ||= {}
413413
options['time_partitioning'] ||= @task['time_partitioning']
414-
if Helper.has_partition_decorator?(table) && @task['range_partitioning'].nil?
414+
if Helper.has_partition_decorator?(table)
415415
options['time_partitioning'] ||= {'type' => 'DAY'}
416416
table = Helper.chomp_partition_decorator(table)
417417
end

test/test_configure.rb

+8
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ def test_range_partitioning
300300
assert_raise { Bigquery.configure(config, schema, processor_count) }
301301
end
302302

303+
def test_time_and_range_partitioning_error
304+
config = least_config.merge('time_partitioning' => {'type' => 'DAY'}, 'range_partitioning' => {'field' => 'foo', 'range' => { 'start' => 1, 'end' => 2, 'interval' => 1 }})
305+
assert_raise { Bigquery.configure(config, schema, processor_count) }
306+
307+
config = least_config.merge('table' => 'table_name$20160912', 'range_partitioning' => {'field' => 'foo', 'range' => { 'start' => 1, 'end' => 2, 'interval' => 1 }})
308+
assert_raise { Bigquery.configure(config, schema, processor_count) }
309+
end
310+
303311
def test_clustering
304312
config = least_config.merge('clustering' => {'fields' => ['field_a']})
305313
assert_nothing_raised { Bigquery.configure(config, schema, processor_count) }

0 commit comments

Comments
 (0)