Skip to content

Commit 8408607

Browse files
committed
Fix regression with 4.3.5 that can result in NULL :sql_last_value depending on timestamp format
fixes #274 Fixes #275
1 parent cd75a15 commit 8408607

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.3.6
2+
- [#274](https://github.com/logstash-plugins/logstash-input-jdbc/issues/274) Fix regression with 4.3.5 that can result in NULL :sql_last_value depending on timestamp format
3+
14
## 4.3.5
25
- [#140](https://github.com/logstash-plugins/logstash-input-jdbc/issues/140) Fix long standing bug where setting jdbc_default_timezone loses milliseconds. Force all usage of sql_last_value to be typed according to the settings.
36

lib/logstash/plugin_mixins/value_tracking.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def get_initial
6969
def set_value(value)
7070
if value.respond_to?(:to_datetime)
7171
@value = value.to_datetime
72+
else
73+
@value = DateTime.parse(value)
7274
end
7375
end
7476
end
@@ -81,6 +83,8 @@ def get_initial
8183
def set_value(value)
8284
if value.respond_to?(:to_time)
8385
@value = value.to_time
86+
else
87+
@value = DateTime.parse(value).to_time
8488
end
8589
end
8690
end

logstash-input-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-input-jdbc'
3-
s.version = '4.3.5'
3+
s.version = '4.3.6'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Creates events from JDBC data"
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"

spec/inputs/jdbc_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,65 @@
739739
end
740740
end
741741

742+
context "when previous runs are to be respected upon successful query execution (by time string)" do
743+
744+
let(:settings) do
745+
{ "statement" => "SELECT custom_time FROM test_table WHERE custom_time > :sql_last_value",
746+
"use_column_value" => true,
747+
"tracking_column" => "custom_time",
748+
"tracking_column_type" => "timestamp",
749+
"last_run_metadata_path" => Stud::Temporary.pathname }
750+
end
751+
752+
let(:last_run_time) { '2010-03-19T14:48:40.483Z' }
753+
754+
before do
755+
File.write(settings["last_run_metadata_path"], YAML.dump(last_run_time))
756+
test_table = db[:test_table]
757+
test_table.insert(:num => 0, :custom_time => Time.now.utc)
758+
plugin.register
759+
end
760+
761+
after do
762+
plugin.stop
763+
end
764+
765+
it "should respect last run metadata" do
766+
plugin.run(queue)
767+
expect(plugin.instance_variable_get("@value_tracker").value).to be > DateTime.parse(last_run_time).to_time
768+
end
769+
end
770+
771+
context "when previous runs are to be respected upon successful query execution (by date/time string)" do
772+
773+
let(:settings) do
774+
{ "statement" => "SELECT custom_time FROM test_table WHERE custom_time > :sql_last_value",
775+
"use_column_value" => true,
776+
"tracking_column" => "custom_time",
777+
"tracking_column_type" => "timestamp",
778+
"jdbc_default_timezone" => "UTC", #this triggers the last_run_time to be treated as date/time
779+
"last_run_metadata_path" => Stud::Temporary.pathname }
780+
end
781+
782+
let(:last_run_time) { '2010-03-19T14:48:40.483Z' }
783+
784+
before do
785+
File.write(settings["last_run_metadata_path"], YAML.dump(last_run_time))
786+
test_table = db[:test_table]
787+
test_table.insert(:num => 0, :custom_time => Time.now.utc)
788+
plugin.register
789+
end
790+
791+
after do
792+
plugin.stop
793+
end
794+
795+
it "should respect last run metadata" do
796+
plugin.run(queue)
797+
expect(plugin.instance_variable_get("@value_tracker").value).to be > DateTime.parse(last_run_time)
798+
end
799+
end
800+
742801
context "when previous runs are to be respected upon successful query execution (by column)" do
743802

744803
let(:settings) do

0 commit comments

Comments
 (0)