forked from fluent-plugins-nursery/fluent-plugin-bigquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a new table via insert_job in create_load_job
to avoid reaching the retry limit cf. fluent/fluentd#2123
- Loading branch information
Showing
2 changed files
with
79 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,8 @@ def stub_writer(stub_auth: true) | |
writer | ||
end | ||
end | ||
|
||
def test_write | ||
schema_fields = Fluent::BigQuery::Helper.deep_symbolize_keys(MultiJson.load(File.read(SCHEMA_PATH))) | ||
|
||
def test_write | ||
response_stub = stub! | ||
|
||
driver = create_driver | ||
|
@@ -60,9 +58,6 @@ def test_write | |
dataset_id: 'yourdataset_id', | ||
table_id: 'foo', | ||
}, | ||
schema: { | ||
fields: schema_fields, | ||
}, | ||
write_disposition: "WRITE_APPEND", | ||
source_format: "NEWLINE_DELIMITED_JSON", | ||
ignore_unknown_values: false, | ||
|
@@ -99,7 +94,6 @@ def test_write_with_prevent_duplicate_load | |
schema_path #{SCHEMA_PATH} | ||
prevent_duplicate_load true | ||
CONFIG | ||
schema_fields = Fluent::BigQuery::Helper.deep_symbolize_keys(MultiJson.load(File.read(SCHEMA_PATH))) | ||
|
||
response_stub = stub! | ||
stub_writer do |writer| | ||
|
@@ -116,9 +110,6 @@ def test_write_with_prevent_duplicate_load | |
dataset_id: 'yourdataset_id', | ||
table_id: 'foo', | ||
}, | ||
schema: { | ||
fields: schema_fields, | ||
}, | ||
write_disposition: "WRITE_APPEND", | ||
source_format: "NEWLINE_DELIMITED_JSON", | ||
ignore_unknown_values: false, | ||
|
@@ -138,7 +129,6 @@ def test_write_with_prevent_duplicate_load | |
|
||
def test_write_with_retryable_error | ||
driver = create_driver | ||
schema_fields = Fluent::BigQuery::Helper.deep_symbolize_keys(MultiJson.load(File.read(SCHEMA_PATH))) | ||
|
||
driver.instance_start | ||
tag, time, record = "tag", Time.now.to_i, {"a" => "b"} | ||
|
@@ -158,9 +148,6 @@ def test_write_with_retryable_error | |
dataset_id: 'yourdataset_id', | ||
table_id: 'foo', | ||
}, | ||
schema: { | ||
fields: schema_fields, | ||
}, | ||
write_disposition: "WRITE_APPEND", | ||
source_format: "NEWLINE_DELIMITED_JSON", | ||
ignore_unknown_values: false, | ||
|
@@ -225,7 +212,6 @@ def test_write_with_not_retryable_error | |
utc | ||
</secondary> | ||
CONFIG | ||
schema_fields = Fluent::BigQuery::Helper.deep_symbolize_keys(MultiJson.load(File.read(SCHEMA_PATH))) | ||
|
||
driver.instance_start | ||
tag, time, record = "tag", Time.now.to_i, {"a" => "b"} | ||
|
@@ -245,9 +231,6 @@ def test_write_with_not_retryable_error | |
dataset_id: 'yourdataset_id', | ||
table_id: 'foo', | ||
}, | ||
schema: { | ||
fields: schema_fields, | ||
}, | ||
write_disposition: "WRITE_APPEND", | ||
source_format: "NEWLINE_DELIMITED_JSON", | ||
ignore_unknown_values: false, | ||
|
@@ -289,6 +272,61 @@ def test_write_with_not_retryable_error | |
driver.instance_shutdown | ||
end | ||
|
||
def test_write_with_auto_create_table | ||
driver = create_driver(<<-CONFIG) | ||
table foo | ||
email [email protected] | ||
private_key_path /path/to/key | ||
project yourproject_id | ||
dataset yourdataset_id | ||
<buffer> | ||
@type memory | ||
</buffer> | ||
<inject> | ||
time_format %s | ||
time_key time | ||
</inject> | ||
auto_create_table true | ||
schema_path #{SCHEMA_PATH} | ||
CONFIG | ||
|
||
schema_fields = Fluent::BigQuery::Helper.deep_symbolize_keys(MultiJson.load(File.read(SCHEMA_PATH))) | ||
|
||
stub_writer do |writer| | ||
mock(writer.client).get_table('yourproject_id', 'yourdataset_id', 'foo') do | ||
raise Google::Apis::ClientError.new("notFound: Not found: Table yourproject_id:yourdataset_id.foo", status_code: 404) | ||
end | ||
|
||
mock(writer.client).insert_job('yourproject_id', { | ||
configuration: { | ||
load: { | ||
destination_table: { | ||
project_id: 'yourproject_id', | ||
dataset_id: 'yourdataset_id', | ||
table_id: 'foo', | ||
}, | ||
write_disposition: "WRITE_APPEND", | ||
source_format: "NEWLINE_DELIMITED_JSON", | ||
ignore_unknown_values: false, | ||
max_bad_records: 0, | ||
schema: { | ||
fields: schema_fields, | ||
}, | ||
} | ||
} | ||
}, {upload_source: duck_type(:write, :sync, :rewind), content_type: "application/octet-stream"}) do | ||
stub!.job_reference.stub!.job_id { "dummy_job_id" } | ||
end | ||
end | ||
|
||
driver.run do | ||
driver.feed("tag", Time.now.to_i, {"a" => "b"}) | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_response_stub(response) | ||
|