Skip to content

Commit

Permalink
Create spec that uses SQL DDL to by pass Sequel, creates specific DAT…
Browse files Browse the repository at this point in the history
…ATYPES (#173)

* Create spec that uses SQL DDL to by pass Sequel, creates specific DATATYPES
Add a Date convertor in `decorate_value`

* fix silly loop of 1

Fixes #172
  • Loading branch information
Guy Boertje committed Oct 20, 2016
1 parent b4e15f6 commit 717249f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 4.1.3
- Fix part1 of #172, coerce SQL DATE to LS Timestamp

## 4.1.2
- [internal] Removed docker dependencies for testing

Expand Down
2 changes: 2 additions & 0 deletions lib/logstash/plugin_mixins/jdbc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def decorate_value(value)
if value.is_a?(Time)
# transform it to LogStash::Timestamp as required by LS
LogStash::Timestamp.new(value)
elsif value.is_a?(Date)
LogStash::Timestamp.new(value.to_time)
elsif value.is_a?(DateTime)
# Manual timezone conversion detected.
# This is slower, so we put it in as a conditional case.
Expand Down
2 changes: 1 addition & 1 deletion logstash-input-jdbc.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-input-jdbc'
s.version = '4.1.2'
s.version = '4.1.3'
s.licenses = ['Apache License (2.0)']
s.summary = "This example input streams a string at a definable interval."
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
33 changes: 33 additions & 0 deletions spec/inputs/jdbc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
String :string
DateTime :custom_time
end
db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))"
end

after :each do
db.drop_table(:test_table)
db.drop_table(:types_table)
end

context "when registering and tearing down" do
Expand Down Expand Up @@ -1042,4 +1044,35 @@
end
end
end

context "when fetching Various Typed data" do

let(:settings) do
{
"statement" => "SELECT * from types_table"
}
end

before do
db << "INSERT INTO types_table (num, string, started_at, custom_time, ranking) VALUES (1, 'A test', '1999-12-31', '1999-12-31 23:59:59', 95.67)"

plugin.register
end

after do
plugin.stop
end

it "should convert all columns to valid Event acceptable data types" do
plugin.run(queue)
event = queue.pop
expect(event.get("num")).to eq(1)
expect(event.get("string")).to eq("A test")
expect(event.get("started_at")).to be_a(LogStash::Timestamp)
expect(event.get("started_at").to_s).to eq("1999-12-31T00:00:00.000Z")
expect(event.get("custom_time")).to be_a(LogStash::Timestamp)
expect(event.get("custom_time").to_s).to eq("1999-12-31T23:59:59.000Z")
expect(event.get("ranking").to_f).to eq(95.67)
end
end
end

0 comments on commit 717249f

Please sign in to comment.