logstash-input-jdbc 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8c5cc2740af8903f9a22ea46ab992cbee6d8c86
4
- data.tar.gz: 1c2773a7b4d978204b86285e5b4742d7f2804af5
3
+ metadata.gz: 6fcc8b3eaba96543efed3777360fd0af48db6bae
4
+ data.tar.gz: 6c87821ec96f4df83b055f5510b03ec2e5bba48f
5
5
  SHA512:
6
- metadata.gz: a39e30c007c31f3827e15e912cdeb3ab89487ab134edbd2269846892d0d6a6c3f6d3676ca8ea60da72a66e43991c3f06dd5ce57e3ee729f7fc301aa20d7e1766
7
- data.tar.gz: ae1ca16f36749b62223dd9e56a627909eb0cb094d410840a2eec97d73db581eb06a9b7da81ca8779ac42f03d7b717f80ba650e4f76246d17221e32795605a1e9
6
+ metadata.gz: 38f419423f8fe7d82988049061049b6ff1af9c099e6af124da46aa4d1957076382c6fef6b49f461e83ffe9c562fe0f7e3df3ddeda08c9e786cf2057fda2aede2
7
+ data.tar.gz: 1d068d7aa44690298e49fe8ce926bc67c1663970cb10418d8d27f4879a8932dbc7c5027f84a295222906f90a8aa799b4f75838fa76dbed6e79ecc8dc1bca1885
@@ -1,3 +1,6 @@
1
+ ## 2.0.5
2
+ - [#77](https://github.com/logstash-plugins/logstash-input-jdbc/issues/77) Time represented as RubyTime and not as Logstash::Timestamp
3
+
1
4
  ## 2.0.4
2
5
  - [#70](https://github.com/logstash-plugins/logstash-input-jdbc/pull/70) prevents multiple queries from being run at the same time
3
6
  - [#69](https://github.com/logstash-plugins/logstash-input-jdbc/pull/69) pass password as string to Sequel
@@ -23,7 +23,9 @@ module LogStash::PluginMixins::Jdbc
23
23
  # If not provided, Plugin will look for the driver class in the Logstash Java classpath.
24
24
  config :jdbc_driver_library, :validate => :path
25
25
 
26
- # JDBC driver class to load, for example "oracle.jdbc.OracleDriver" or "org.apache.derby.jdbc.ClientDriver"
26
+ # JDBC driver class to load, for exmaple, "org.apache.derby.jdbc.ClientDriver"
27
+ # NB per https://github.com/logstash-plugins/logstash-input-jdbc/issues/43 if you are using
28
+ # the Oracle JDBC driver (ojdbc6.jar) the correct `jdbc_driver_class` is `"Java::oracle.jdbc.driver.OracleDriver"`
27
29
  config :jdbc_driver_class, :validate => :string, :required => true
28
30
 
29
31
  # JDBC connection string
@@ -141,14 +143,12 @@ module LogStash::PluginMixins::Jdbc
141
143
  if @jdbc_paging_enabled
142
144
  query.each_page(@jdbc_page_size) do |paged_dataset|
143
145
  paged_dataset.each do |row|
144
- #Stringify row keys
145
- yield Hash[row.map { |k, v| [k.to_s, v] }]
146
+ yield extract_values_from(row)
146
147
  end
147
148
  end
148
149
  else
149
150
  query.each do |row|
150
- #Stringify row keys
151
- yield Hash[row.map { |k, v| [k.to_s, v] }]
151
+ yield extract_values_from(row)
152
152
  end
153
153
  end
154
154
  success = true
@@ -171,4 +171,20 @@ module LogStash::PluginMixins::Jdbc
171
171
  hash
172
172
  end
173
173
  end
174
+
175
+ private
176
+ #Stringify row keys and decorate values when necessary
177
+ def extract_values_from(row)
178
+ Hash[row.map { |k, v| [k.to_s, decorate_value(v)] }]
179
+ end
180
+
181
+ private
182
+ def decorate_value(value)
183
+ if value.is_a?(Time)
184
+ # transform it to LogStash::Timestamp as required by LS
185
+ LogStash::Timestamp.new(value)
186
+ else
187
+ value # no-op
188
+ end
189
+ end
174
190
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-jdbc'
3
- s.version = '2.0.4'
3
+ s.version = '2.0.5'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "This example input streams a string at a definable interval."
6
6
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -19,7 +19,8 @@ describe LogStash::Inputs::Jdbc do
19
19
  Jdbc::Derby.load_driver
20
20
  db.create_table :test_table do
21
21
  DateTime :created_at
22
- Integer :num
22
+ Integer :num
23
+ DateTime :custom_time
23
24
  end
24
25
  end
25
26
 
@@ -96,7 +97,7 @@ describe LogStash::Inputs::Jdbc do
96
97
  let(:settings) do
97
98
  {
98
99
  "statement" => "SELECT :num_param as num_param FROM SYSIBM.SYSDUMMY1",
99
- "parameters" => {"num_param" => 10}
100
+ "parameters" => { "num_param" => 10}
100
101
  }
101
102
  end
102
103
 
@@ -159,7 +160,7 @@ describe LogStash::Inputs::Jdbc do
159
160
 
160
161
  it "should fetch all rows" do
161
162
  num_rows.times do
162
- db[:test_table].insert(:num => 1, :created_at => Time.now.utc)
163
+ db[:test_table].insert(:num => 1, :custom_time => Time.now.utc, :created_at => Time.now.utc)
163
164
  end
164
165
 
165
166
  plugin.run(queue)
@@ -169,6 +170,35 @@ describe LogStash::Inputs::Jdbc do
169
170
 
170
171
  end
171
172
 
173
+ context "when fetching time data" do
174
+
175
+ let(:settings) do
176
+ {
177
+ "statement" => "SELECT * from test_table",
178
+ }
179
+ end
180
+
181
+ let(:num_rows) { 10 }
182
+
183
+ before do
184
+ num_rows.times do
185
+ db[:test_table].insert(:num => 1, :custom_time => Time.now.utc, :created_at => Time.now.utc)
186
+ end
187
+
188
+ plugin.register
189
+ end
190
+
191
+ after do
192
+ plugin.stop
193
+ end
194
+
195
+ it "should convert it to LogStash::Timestamp " do
196
+ plugin.run(queue)
197
+ event = queue.pop
198
+ expect(event["custom_time"]).to be_a(LogStash::Timestamp)
199
+ end
200
+ end
201
+
172
202
  context "when iteratively running plugin#run" do
173
203
  let(:settings) do
174
204
  {"statement" => "SELECT num, created_at FROM test_table WHERE created_at > :sql_last_start"}
@@ -289,7 +319,7 @@ describe LogStash::Inputs::Jdbc do
289
319
 
290
320
  before do
291
321
  num_rows.times do
292
- db[:test_table].insert(:num => 1, :created_at => Time.now.utc)
322
+ db[:test_table].insert(:num => 1, :custom_time => Time.now.utc, :created_at => Time.now.utc)
293
323
  end
294
324
 
295
325
  plugin.register
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core