Skip to content

Commit 49d2c36

Browse files
committed
fix: unnest range_partitioning.range
1 parent adf5210 commit 49d2c36

File tree

5 files changed

+26
-38
lines changed

5 files changed

+26
-38
lines changed

README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ Following options are same as [bq command-line tools](https://cloud.google.com/b
112112
| time_partitioning.field | string | optional | nil | `DATE` or `TIMESTAMP` column used for partitioning |
113113
| range_partitioning | hash | optional | nil | See [Range Partitioning](#range-partitioning) |
114114
| range_partitioning.field | string | required | nil | `INT64` column used for partitioning |
115-
| range-partitioning.range | hash | required | nil | Defines the ranges for range paritioning |
116-
| range-partitioning.range.start | string | required | nil | The start of range partitioning, inclusive. This field is an INT64 value represented as a string. |
117-
| range-partitioning.range.end | string | required | nil | The end of range partitioning, exclusive. This field is an INT64 value represented as a string. |
118-
| range-partitioning.range.interval| string | required | nil | The width of each interval. This field is an INT64 value represented as a string. |
115+
| range_partitioning.start | string | required | nil | The start of range partitioning, inclusive. This field is an INT64 value represented as a string. |
116+
| range_partitioning.end | string | required | nil | The end of range partitioning, exclusive. This field is an INT64 value represented as a string. |
117+
| range_partitioning.interval | string | required | nil | The width of each interval. This field is an INT64 value represented as a string. |
119118
| clustering | hash | optional | nil | Currently, clustering is supported for partitioned tables, so must be used with `time_partitioning` option. See [clustered tables](https://cloud.google.com/bigquery/docs/clustered-tables) |
120119
| clustering.fields | array | required | nil | One or more fields on which data should be clustered. The order of the specified columns determines the sort order of the data. |
121120
| schema_update_options | array | optional | nil | (Experimental) List of `ALLOW_FIELD_ADDITION` or `ALLOW_FIELD_RELAXATION` or both. See [jobs#configuration.load.schemaUpdateOptions](https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load.schemaUpdateOptions). NOTE for the current status: `schema_update_options` does not work for `copy` job, that is, is not effective for most of modes such as `append`, `replace` and `replace_backup`. `delete_in_advance` deletes origin table so does not need to update schema. Only `append_direct` can utilize schema update. |
@@ -466,10 +465,9 @@ out:
466465
table: table_name$1
467466
range_partitioning:
468467
field: customer_id
469-
range:
470-
start: '1'
471-
end: '99999'
472-
range: '1'
468+
start: '1'
469+
end: '99999'
470+
range: '1'
473471
```
474472

475473
## Development

example/config_replace_field_range_partitioned_table.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ out:
3030
schema_file: example/schema.json
3131
range_partitioning:
3232
field: 'long'
33-
range:
34-
start: '90'
35-
end: '100'
36-
interval: '1'
33+
start: '90'
34+
end: '100'
35+
interval: '1'

lib/embulk/output/bigquery.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,14 @@ def self.configure(config, schema, task_count)
241241
unless task['range_partitioning']['field']
242242
raise ConfigError.new "`range_partitioning` must have `field` key"
243243
end
244-
unless task['range_partitioning']['range']
245-
raise ConfigError.new "`range_partitioning` must have `range` key"
244+
unless task['range_partitioning']['start']
245+
raise ConfigError.new "`range_partitioning` must have `start` key"
246246
end
247-
248-
unless task['range_partitioning']['range']['start']
249-
raise ConfigError.new "`range_partitioning` must have `range.start` key"
250-
end
251-
unless task['range_partitioning']['range']['end']
252-
raise ConfigError.new "`range_partitioning` must have `range.end` key"
247+
unless task['range_partitioning']['end']
248+
raise ConfigError.new "`range_partitioning` must have `end` key"
253249
end
254-
unless task['range_partitioning']['range']['interval']
255-
raise ConfigError.new "`range_partitioning` must have `range.interval` key"
250+
unless task['range_partitioning']['interval']
251+
raise ConfigError.new "`range_partitioning` must have `interval` key"
256252
end
257253
end
258254

lib/embulk/output/bigquery/bigquery_client.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ def create_table_if_not_exists(table, dataset: nil, options: nil)
440440
body[:range_partitioning] = {
441441
field: options['range_partitioning']['field'],
442442
range: {
443-
start: options['range_partitioning']['range']['start'],
444-
end: options['range_partitioning']['range']['end'],
445-
interval: options['range_partitioning']['range']['interval'],
443+
start: options['range_partitioning']['start'],
444+
end: options['range_partitioning']['end'],
445+
interval: options['range_partitioning']['interval'],
446446
},
447447
}
448448
end

test/test_configure.rb

+8-13
Original file line numberDiff line numberDiff line change
@@ -271,28 +271,23 @@ def test_time_partitioning
271271
end
272272

273273
def test_range_partitioning
274-
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'range' => { 'start' => '1', 'end' => '2', 'interval' => '1' }})
274+
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'start' => '1', 'end' => '2', 'interval' => '1'})
275275
assert_nothing_raised { Bigquery.configure(config, schema, processor_count) }
276276

277277
# field is required
278-
config = least_config.merge('range_partitioning' => {'range' => { 'start' => '1', 'end' => '2', 'interval' => '1' }})
278+
config = least_config.merge('range_partitioning' => {'start' => '1', 'end' => '2', 'interval' => '1'})
279279
assert_raise { Bigquery.configure(config, schema, processor_count) }
280280

281-
282-
# range is required
283-
config = least_config.merge('range_partitioning' => {'field' => 'foo'})
284-
assert_raise { Bigquery.configure(config, schema, processor_count) }
285-
286-
# range.start is required
287-
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'range' => { 'end' => '2', 'interval' => '1' }})
281+
# start is required
282+
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'end' => '2', 'interval' => '1'})
288283
assert_raise { Bigquery.configure(config, schema, processor_count) }
289284

290-
# range.end is required
291-
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'range' => { 'start' => '1', 'interval' => '1' }})
285+
# end is required
286+
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'start' => '1', 'interval' => '1'})
292287
assert_raise { Bigquery.configure(config, schema, processor_count) }
293288

294-
# range.interval is required
295-
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'range' => { 'start' => '1', 'end' => '2' }})
289+
# interval is required
290+
config = least_config.merge('range_partitioning' => {'field' => 'foo', 'start' => '1', 'end' => '2'})
296291
assert_raise { Bigquery.configure(config, schema, processor_count) }
297292
end
298293

0 commit comments

Comments
 (0)