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

Support description of columns and tables #142

Merged
merged 8 commits into from
Mar 4, 2024
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ OAuth flow for installed applications.
| gcs_bucket | string | optional | nil | See [GCS Bucket](#gcs-bucket) |
| auto_create_gcs_bucket | boolean | optional | false | See [GCS Bucket](#gcs-bucket) |
| progress_log_interval | float | optional | nil (Disabled) | Progress log interval. The progress log is disabled by nil (default). NOTE: This option may be removed in a future because a filter plugin can achieve the same goal |
| description | string | optional | nil | description of table |

Client or request options

Expand Down Expand Up @@ -329,6 +330,7 @@ Column options are used to aid guessing BigQuery schema, or to define conversion
- json: `STRING`, `RECORD` (default: `STRING`)
- **mode**: BigQuery mode such as `NULLABLE`, `REQUIRED`, and `REPEATED` (string, default: `NULLABLE`)
- **fields**: Describes the nested schema fields if the type property is set to RECORD. Please note that this is **required** for `RECORD` column.
- **description**: description (string, default is `None`).
- **timestamp_format**: timestamp format to convert into/from `timestamp` (string, default is `default_timestamp_format`)
- **timezone**: timezone to convert into/from `timestamp`, `date` (string, default is `default_timezone`).
- **default_timestamp_format**: default timestamp format for column_options (string, default is "%Y-%m-%d %H:%M:%S.%6N")
Expand Down
2 changes: 2 additions & 0 deletions lib/embulk/output/bigquery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def self.configure(config, schema, task_count)
'payload_column' => config.param('payload_column', :string, :default => nil),
'payload_column_index' => config.param('payload_column_index', :integer, :default => nil),

'description' => config.param('description', :string, :default => nil),

'open_timeout_sec' => config.param('open_timeout_sec', :integer, :default => nil),
'timeout_sec' => config.param('timeout_sec', :integer, :default => nil), # google-api-ruby-client < v0.11.0
'send_timeout_sec' => config.param('send_timeout_sec', :integer, :default => nil), # google-api-ruby-client >= v0.11.0
Expand Down
1 change: 1 addition & 0 deletions lib/embulk/output/bigquery/bigquery_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def create_table_if_not_exists(table, dataset: nil, options: nil)
table_reference: {
table_id: table,
},
description: @task['description'],
schema: {
fields: fields,
}
Expand Down
9 changes: 5 additions & 4 deletions lib/embulk/output/bigquery/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ def self.fields_from_embulk_schema(task, schema)
embulk_type = column[:type]
column_option = column_options_map[column_name] || {}
{}.tap do |field|
field[:name] = column_name
field[:type] = (column_option['type'] || bq_type_from_embulk_type(embulk_type)).upcase
field[:mode] = column_option['mode'] if column_option['mode']
field[:fields] = deep_symbolize_keys(column_option['fields']) if column_option['fields']
field[:name] = column_name
field[:type] = (column_option['type'] || bq_type_from_embulk_type(embulk_type)).upcase
field[:mode] = column_option['mode'] if column_option['mode']
field[:fields] = deep_symbolize_keys(column_option['fields']) if column_option['fields']
field[:description] = column_option['description'] if column_option['description']
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_fields_from_embulk_schema_with_column_options
])
task = {
'column_options' => [
{'name' => 'boolean', 'type' => 'STRING', 'mode' => 'REQUIRED'},
{'name' => 'boolean', 'type' => 'STRING', 'mode' => 'REQUIRED', 'description' => 'hoge'},
{'name' => 'long', 'type' => 'STRING'},
{'name' => 'double', 'type' => 'STRING'},
{'name' => 'string', 'type' => 'INTEGER'},
Expand All @@ -81,7 +81,7 @@ def test_fields_from_embulk_schema_with_column_options
],
}
expected = [
{name: 'boolean', type: 'STRING', mode: 'REQUIRED'},
{name: 'boolean', type: 'STRING', mode: 'REQUIRED', description: 'hoge'},
{name: 'long', type: 'STRING'},
{name: 'double', type: 'STRING'},
{name: 'string', type: 'INTEGER'},
Expand Down