Skip to content

Commit

Permalink
Fix prepared_statement_bind_values to resolve nested event's fields (#76
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
andsel committed Jun 28, 2021
1 parent e5b5808 commit f1bf6ae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 5.1.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)

## 5.1.1
- [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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.build_bind_value_handler(given_value)
return InterpolatedParameter.new(given_value)
end

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

Expand Down
2 changes: 1 addition & 1 deletion logstash-integration-jdbc.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-integration-jdbc'
s.version = '5.1.1'
s.version = '5.1.2'
s.licenses = ['Apache License (2.0)']
s.summary = "Integration with JDBC - input and filter plugins"
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"
Expand Down
23 changes: 23 additions & 0 deletions spec/plugin_mixins/jdbc_streaming/parameter_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/plugin_mixins/jdbc_streaming/parameter_handler"


describe LogStash::PluginMixins::JdbcStreaming::ParameterHandler do
context "resolve field reference" do
let(:event) { ::LogStash::Event.new("field" => "field_value") }

it "should resolve root field" do
handler = LogStash::PluginMixins::JdbcStreaming::ParameterHandler.build_bind_value_handler "[field]"
handler.extract_from(event)
expect(handler.extract_from(event)).to eq "field_value"
end

it "should resolve nested field" do
event = ::LogStash::Event.from_json("{\"field\": {\"nested\": \"nested_field\"}}").first
handler = LogStash::PluginMixins::JdbcStreaming::ParameterHandler.build_bind_value_handler "[field][nested]"
handler.extract_from(event)
expect(handler.extract_from(event)).to eq "nested_field"
end
end
end

0 comments on commit f1bf6ae

Please sign in to comment.