Skip to content

Commit f1bf6ae

Browse files
authored
Fix prepared_statement_bind_values to resolve nested event's fields (#76)
JDBC streaming filter uses the setting `prepared_statement_bind_values` to bind event's fields or constants to SQL prepared statements. It resolves fields with the notation `[field_name]` but it's not able to match the nested form: `[field][nested]`, this PR changes the match regexp to fix it.
1 parent e5b5808 commit f1bf6ae

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.1.2
2+
- Fix `prepared_statement_bind_values` in streaming filter to resolve nested event's fields[#76](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/76)
3+
14
## 5.1.1
25
- [DOC] Changed docs to indicate that logstash-jdbc-static requires local_table [#56](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/56). Fixes [#55](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/55).
36

lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def self.build_bind_value_handler(given_value)
2626
return InterpolatedParameter.new(given_value)
2727
end
2828

29-
if given_value =~ /\A\s*\[[^\]]+\]\s*\z/
29+
if given_value =~ /\A(\s*\[[^\]]+\]\s*)*\z/
3030
return FieldParameter.new(given_value)
3131
end
3232

logstash-integration-jdbc.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-integration-jdbc'
3-
s.version = '5.1.1'
3+
s.version = '5.1.2'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Integration with JDBC - input and filter plugins"
66
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# encoding: utf-8
2+
require "logstash/devutils/rspec/spec_helper"
3+
require "logstash/plugin_mixins/jdbc_streaming/parameter_handler"
4+
5+
6+
describe LogStash::PluginMixins::JdbcStreaming::ParameterHandler do
7+
context "resolve field reference" do
8+
let(:event) { ::LogStash::Event.new("field" => "field_value") }
9+
10+
it "should resolve root field" do
11+
handler = LogStash::PluginMixins::JdbcStreaming::ParameterHandler.build_bind_value_handler "[field]"
12+
handler.extract_from(event)
13+
expect(handler.extract_from(event)).to eq "field_value"
14+
end
15+
16+
it "should resolve nested field" do
17+
event = ::LogStash::Event.from_json("{\"field\": {\"nested\": \"nested_field\"}}").first
18+
handler = LogStash::PluginMixins::JdbcStreaming::ParameterHandler.build_bind_value_handler "[field][nested]"
19+
handler.extract_from(event)
20+
expect(handler.extract_from(event)).to eq "nested_field"
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)