From 47fdf7d442f31ce4bfbcd32165fed5a486968f35 Mon Sep 17 00:00:00 2001 From: Karl Southern Date: Thu, 15 Sep 2016 11:06:34 +0100 Subject: [PATCH] Adds bigint/long support to address #61 --- CHANGELOG.md | 5 ++++- lib/logstash/outputs/jdbc.rb | 8 +++++++- logstash-output-jdbc.gemspec | 2 +- spec/jdbc_spec_helper.rb | 4 ++-- spec/outputs/jdbc_derby_spec.rb | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4e3e53..b7eb2b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Change Log All notable changes to this project will be documented in this file, from 0.2.0. -## [0.3.1] = 2016-08-28 +## [0.3.2] - 2016-09-15 + - Adds long/bigint support to address https://github.com/theangryangel/logstash-output-jdbc/issues/61 + +## [0.3.1] - 2016-08-28 - Adds connection_test configuration option, to prevent the connection test from occuring, allowing the error to be suppressed. Useful for cockroachdb deployments. https://github.com/theangryangel/logstash-output-jdbc/issues/53 diff --git a/lib/logstash/outputs/jdbc.rb b/lib/logstash/outputs/jdbc.rb index 49037ae..b728fb3 100644 --- a/lib/logstash/outputs/jdbc.rb +++ b/lib/logstash/outputs/jdbc.rb @@ -280,7 +280,13 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base # strftime appears to be the most reliable across drivers. statement.setString(idx + 1, value.time.strftime(STRFTIME_FMT)) when Fixnum, Integer - statement.setInt(idx + 1, value) + # bit_length doesn't exist in the current version of ruby/jruby logstash targets + # and this seems quicker than doing some Math.log2(value < 0 ? -value : value+1).ceil shit + if value > 2147483647 or value < -2147483648 + statement.setLong(idx + 1, value) + else + statement.setInt(idx + 1, value) + end when Float statement.setFloat(idx + 1, value) when String diff --git a/logstash-output-jdbc.gemspec b/logstash-output-jdbc.gemspec index a4b0638..b2f2e27 100644 --- a/logstash-output-jdbc.gemspec +++ b/logstash-output-jdbc.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'logstash-output-jdbc' - s.version = "0.3.1" + s.version = "0.3.2" s.licenses = [ "Apache License (2.0)" ] s.summary = "This plugin allows you to output to SQL, via JDBC" 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" diff --git a/spec/jdbc_spec_helper.rb b/spec/jdbc_spec_helper.rb index 4d6c288..11abc7a 100644 --- a/spec/jdbc_spec_helper.rb +++ b/spec/jdbc_spec_helper.rb @@ -31,11 +31,11 @@ RSpec.shared_context 'when outputting messages' do end let(:jdbc_create_table) do - "CREATE table #{jdbc_test_table} (created_at datetime not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit bit not null)" + "CREATE table #{jdbc_test_table} (created_at datetime not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit bit not null, static_bigint bigint not null)" end let(:jdbc_statement) do - ["insert into #{jdbc_test_table} (created_at, message, message_sprintf, static_int, static_bit) values(?, ?, ?, ?, ?)", '@timestamp', 'message', 'sprintf-%{message}', 1, true] + ["insert into #{jdbc_test_table} (created_at, message, message_sprintf, static_int, static_bit, static_bigint) values(?, ?, ?, ?, ?, ?)", '@timestamp', 'message', 'sprintf-%{message}', 1, true, 4000881632477184] end let(:systemd_database_service) do diff --git a/spec/outputs/jdbc_derby_spec.rb b/spec/outputs/jdbc_derby_spec.rb index b06980b..ad9ed33 100644 --- a/spec/outputs/jdbc_derby_spec.rb +++ b/spec/outputs/jdbc_derby_spec.rb @@ -10,7 +10,7 @@ describe 'logstash-output-jdbc: derby', if: ENV['JDBC_DERBY_JAR'] do end let(:jdbc_create_table) do - "CREATE table #{jdbc_test_table} (created_at timestamp not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit boolean not null)" + "CREATE table #{jdbc_test_table} (created_at timestamp not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit boolean not null, static_bigint bigint not null)" end let(:jdbc_settings) do