fluent-plugin-bigquery icon indicating copy to clipboard operation
fluent-plugin-bigquery copied to clipboard

Support Ruby >= 3.0

Open hirose31 opened this issue 2 years ago • 1 comments

This pull request fixes raising ArgumentError exception when run on Ruby >= 3.0 due to incompatible changes of keyword arguments.

I have confirmed that it works with the td-agent package for Ubuntu 22.04, which ships with ruby 3.1.


I am making this pull request for to draft because I need advice on modifying the test code.

I modified the test code in the same way:

--- a/test/plugin/test_out_bigquery_insert.rb
+++ b/test/plugin/test_out_bigquery_insert.rb
@@ -296,7 +296,7 @@ def test_write_with_row_based_table_id_formatting
           rows: [entry[0]],
           skip_invalid_rows: false,
           ignore_unknown_values: false
-        }, {}) { stub!.insert_errors { nil } }
+        }, **{}) { stub!.insert_errors { nil } }
     end

     driver.run do

I am getting the following error with ruby 2.7.

Failure: test_write_with_row_based_table_id_formatting(BigQueryInsertOutputTest):
  On subject #<Google::Apis::BigqueryV2::BigqueryService:0x000055f6fdcb8500>,
  unexpected method invocation:
    insert_all_table_data("yourproject_id", "yourdataset_id", "foo_2014_08_20", {:rows=>[{:json=>{:a=>"b", :created_at=>"2014_08_20"}}], :skip_invalid_rows=>false, :ignore_unknown_values=>false}, {})
  expected invocations:
  - insert_all_table_data("yourproject_id", "yourdataset_id", "foo_2014_08_20", {:rows=>[{:json=>{:a=>"b", :created_at=>"2014_08_20"}}], :skip_invalid_rows=>false, :ignore_unknown_values=>false})

However, if I use {} as it was before the modification, I am getting the following error with ruby 3.1.

Failure: test_write_with_row_based_table_id_formatting(BigQueryInsertOutputTest):
  On subject #<Google::Apis::BigqueryV2::BigqueryService:0x00007feebae30188>,
  unexpected method invocation:
    insert_all_table_data("yourproject_id", "yourdataset_id", "foo_2014_08_20", {:rows=>[{:json=>{:a=>"b", :created_at=>"2014_08_20"}}], :skip_invalid_rows=>false, :ignore_unknown_values=>false})
  expected invocations:
  - insert_all_table_data("yourproject_id", "yourdataset_id", "foo_2014_08_20", {:rows=>[{:json=>{:a=>"b", :created_at=>"2014_08_20"}}], :skip_invalid_rows=>false, :ignore_unknown_values=>false}, {})

I am not very familiar with ruby, so any advice on what modifications I should make would be appreciated.

hirose31 avatar Jun 10 '22 12:06 hirose31

@joker1007 (I forgot to menshion ☺️ )

hirose31 avatar Jun 10 '22 12:06 hirose31

@hirose31 Excuse me for cutting in. I'm having the same issue and hope this fix applies.

The following processing is not supported, so I would appreciate it if you could fix it.

--- a/lib/fluent/plugin/bigquery/writer.rb
+++ b/lib/fluent/plugin/bigquery/writer.rb
@@ -158,7 +158,7 @@ module Fluent
         res = client.insert_job(
           project,
           configuration,
-          {
+          **{
             upload_source: upload_source,
             content_type: "application/octet-stream",
           }

Regarding the test failure for each ruby ​​version, It's a workaround, but if the argument is empty, how about fixing the product code like this:

--- a/lib/fluent/plugin/bigquery/writer.rb
+++ b/lib/fluent/plugin/bigquery/writer.rb
@@ -37,7 +37,7 @@ module Fluent
           definition.merge!(time_partitioning: time_partitioning) if time_partitioning
           definition.merge!(require_partition_filter: require_partition_filter) if require_partition_filter
           definition.merge!(clustering: clustering) if clustering
-          client.insert_table(project, dataset, definition, **{})
+          client.insert_table(project, dataset, definition)
           log.debug "create table", project_id: project, dataset: dataset, table: table_id
         rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
           message = e.message

murakami-ta avatar Oct 03 '22 02:10 murakami-ta

I'm very sorry for the late response. I picked the commit and fixed other keyword arguments codes and test codes.

https://github.com/fluent-plugins-nursery/fluent-plugin-bigquery/pull/199

joker1007 avatar Oct 03 '22 13:10 joker1007