fluent-plugin-sql 2.3.2 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d90c196fbc84a7921ba99ea09cdc7aef2c564b4c19799cc1bcce9973e1f391e
4
- data.tar.gz: 358dbde32a842e26b2ff9e34a11acff25790624dec8ae1e4689aaa8488d179de
3
+ metadata.gz: 197db6803c87ca64448c432656a89d879f8e465258928e697d487ad16fd462b6
4
+ data.tar.gz: 89a4f1866a939aaec3122ba8259f4d9a74d851175743c117984ab2e29cc757bf
5
5
  SHA512:
6
- metadata.gz: 1cbe495ae7aab0133427155b1a136f8a499b9b0924305bf24807c0f2950f2a84b7a3d0657093375e682be37d2d81f96b503e77635c7ddb24f51a5abb40914a51
7
- data.tar.gz: 9b856ce7892a9d9f2fd35d36137eca67508d129194043516e976f5497518da251604c35cba15d483386d0879bb073e2fe9fd1d96a0e027dcbe66fb5fd2a78b7d
6
+ metadata.gz: b22a4fefd2608b511a17247e92ee07ef475a570c9f1b17e713156ced301b69d51ff994d2e2ed39832134241227fa24fd381fe792b97ccf38cf212ccc01d9f9b4
7
+ data.tar.gz: 00eae6b85e603667715d5ddd72f788dd1c8614cd8b0cb5c31d7d515cdba8f2aec3d84b39f12c8c6a6e65951c42c6d13189be54129a8d1022d0b333165c87ee8d
@@ -3,4 +3,4 @@ updates:
3
3
  - package-ecosystem: 'github-actions'
4
4
  directory: '/'
5
5
  schedule:
6
- interval: 'weekly'
6
+ interval: 'monthly'
@@ -11,7 +11,7 @@ jobs:
11
11
  fail-fast: false
12
12
  matrix:
13
13
  ruby: [ 'head' ]
14
- postgres: [ '16', '15', '14', '13', '12' ]
14
+ postgres: [ '18', '17', '16', '15', '14' ]
15
15
  os:
16
16
  - ubuntu-latest
17
17
  services:
@@ -30,8 +30,8 @@ jobs:
30
30
  --health-retries 5
31
31
  name: Ruby ${{ matrix.ruby }} with PostgreSQL ${{ matrix.postgres }} unit testing on ${{ matrix.os }}
32
32
  steps:
33
- - uses: actions/checkout@v6
34
- - uses: ruby/setup-ruby@v1
33
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
34
+ - uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
35
35
  with:
36
36
  ruby-version: ${{ matrix.ruby }}
37
37
  bundler-cache: true
@@ -4,15 +4,24 @@ on:
4
4
  branches: [master]
5
5
  pull_request:
6
6
  branches: [master]
7
-
7
+ schedule:
8
+ - cron: '0 0 1 * *'
8
9
  jobs:
10
+ ruby-versions:
11
+ uses: ruby/actions/.github/workflows/ruby_versions.yml@master
12
+ with:
13
+ engine: cruby
14
+ min_version: 2.7
9
15
  build:
16
+ needs: ruby-versions
10
17
  runs-on: ${{ matrix.os }}
11
18
  strategy:
12
19
  fail-fast: false
13
20
  matrix:
14
- ruby: [ '4.0', '3.4', '3.3', '3.2', '3.1', '3.0', '2.7' ]
15
- postgres: [ '16', '15', '14', '13', '12' ]
21
+ ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
22
+ exclude:
23
+ - ruby: head
24
+ postgres: [ '18', '17', '16', '15', '14' ]
16
25
  os:
17
26
  - ubuntu-latest
18
27
  services:
@@ -31,8 +40,8 @@ jobs:
31
40
  --health-retries 5
32
41
  name: Ruby ${{ matrix.ruby }} with PostgreSQL ${{ matrix.postgres }} unit testing on ${{ matrix.os }}
33
42
  steps:
34
- - uses: actions/checkout@v6
35
- - uses: ruby/setup-ruby@v1
43
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
44
+ - uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
36
45
  with:
37
46
  ruby-version: ${{ matrix.ruby }}
38
47
  bundler-cache: true
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Release 2.3.3 - 2026/05/18
2
+
3
+ * out_sql: fix unmapped columns being explicitly set to NULL on INSERT (#169)
4
+
1
5
  Release 2.3.2 - 2026/01/13
2
6
 
3
7
  * out_sql: Use isolated connection configurations in the output plugin (#152)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.2
1
+ 2.3.3
@@ -90,23 +90,26 @@ module Fluent::Plugin
90
90
 
91
91
  def import(chunk, output)
92
92
  tag = chunk.metadata.tag
93
+ columns = []
93
94
  records = []
94
95
  chunk.msgpack_each { |time, data|
95
96
  begin
96
97
  data = output.inject_values_to_record(tag, time, data)
97
- records << @model.new(@format_proc.call(data))
98
+ new_record = @format_proc.call(data)
99
+ columns |= new_record.keys
100
+ records << @model.new(new_record)
98
101
  rescue => e
99
102
  args = {error: e, table: @table, record: Yajl.dump(data)}
100
103
  @log.warn "Failed to create the model. Ignore a record:", args
101
104
  end
102
105
  }
103
106
  begin
104
- @model.import(records)
107
+ @model.import(columns, records)
105
108
  rescue ActiveRecord::StatementInvalid, ActiveRecord::Import::MissingColumnError => e
106
109
  if @enable_fallback
107
110
  # ignore other exceptions to use Fluentd retry mechanizm
108
111
  @log.warn "Got deterministic error. Fallback to one-by-one import", error: e
109
- one_by_one_import(records)
112
+ one_by_one_import(columns, records)
110
113
  else
111
114
  @log.warn "Got deterministic error. Fallback is disabled", error: e
112
115
  raise e
@@ -114,11 +117,11 @@ module Fluent::Plugin
114
117
  end
115
118
  end
116
119
 
117
- def one_by_one_import(records)
120
+ def one_by_one_import(columns, records)
118
121
  records.each { |record|
119
122
  retries = 0
120
123
  begin
121
- @model.import([record])
124
+ @model.import(columns, [record])
122
125
  rescue ActiveRecord::StatementInvalid, ActiveRecord::Import::MissingColumnError => e
123
126
  @log.error "Got deterministic error again. Dump a record", error: e, record: record
124
127
  rescue => e
@@ -27,5 +27,9 @@ ActiveRecord::Schema.define(version: 20160225030107) do
27
27
  t.datetime "updated_at", null: false
28
28
  t.string "custom_time"
29
29
  end
30
- end
31
30
 
31
+ create_table "messages_unmapped", force: :cascade do |t|
32
+ t.string "message"
33
+ t.string "status", default: 'default_status'
34
+ end
35
+ end
@@ -80,6 +80,41 @@ class SqlOutputTest < Test::Unit::TestCase
80
80
  assert_equal(["message1", "message2"], messages)
81
81
  end
82
82
 
83
+ def test_unmapped_column_uses_db_default
84
+ config = %[
85
+ host localhost
86
+ port 5432
87
+ adapter postgresql
88
+
89
+ database fluentd_test
90
+ username fluentd
91
+ password fluentd
92
+
93
+ schema_search_path public
94
+
95
+ remove_tag_prefix db
96
+
97
+ <table>
98
+ table messages_unmapped
99
+ column_mapping message:message
100
+ </table>
101
+ ]
102
+
103
+ d = create_driver(config)
104
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
105
+
106
+ d.run(default_tag: 'test') do
107
+ d.feed(time, {'message' => 'hello'})
108
+ end
109
+
110
+ records = ActiveRecord::Base.connection.select_all("SELECT * FROM messages_unmapped").to_a
111
+
112
+ assert_equal 1, records.size
113
+ assert_equal 'hello', records.first['message']
114
+ # The 'status' column is not mapped, so it should use the default value defined in the database schema
115
+ assert_equal 'default_status', records.first['status']
116
+ end
117
+
83
118
  class Fallback < self
84
119
  def test_simple
85
120
  d = create_driver
@@ -91,10 +126,10 @@ class SqlOutputTest < Test::Unit::TestCase
91
126
 
92
127
  default_table = d.instance.instance_variable_get(:@default_table)
93
128
  model = default_table.instance_variable_get(:@model)
94
- mock(model).import(anything).at_least(1) do
129
+ mock(model).import(anything, anything).at_least(1) do
95
130
  raise ActiveRecord::Import::MissingColumnError.new("dummy_table", "dummy_column")
96
131
  end
97
- mock(default_table).one_by_one_import(anything)
132
+ mock(default_table).one_by_one_import(anything, anything)
98
133
  end
99
134
  end
100
135
 
@@ -108,10 +143,10 @@ class SqlOutputTest < Test::Unit::TestCase
108
143
 
109
144
  default_table = d.instance.instance_variable_get(:@default_table)
110
145
  model = default_table.instance_variable_get(:@model)
111
- mock(model).import([anything, anything]).once do
146
+ mock(model).import(anything, [anything, anything]).once do
112
147
  raise ActiveRecord::Import::MissingColumnError.new("dummy_table", "dummy_column")
113
148
  end
114
- mock(model).import([anything]).times(12) do
149
+ mock(model).import(anything, [anything]).times(12) do
115
150
  raise StandardError
116
151
  end
117
152
  assert_equal(5, default_table.instance_variable_get(:@num_retries))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.6.9
193
+ rubygems_version: 4.0.10
194
194
  specification_version: 4
195
195
  summary: SQL input/output plugin for Fluentd event collector
196
196
  test_files: