Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created September 18, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaauie/80580027b456849e2e2f36537f95b711 to your computer and use it in GitHub Desktop.
Save yaauie/80580027b456849e2e2f36537f95b711 to your computer and use it in GitHub Desktop.
Logstash JDBC Input Plugin: Informix DB Windowing Support Proof-of-Concept
diff --git a/lib/logstash/plugin_mixins/jdbc.rb b/lib/logstash/plugin_mixins/jdbc.rb
index c9bc547..934a4f1 100644
--- a/lib/logstash/plugin_mixins/jdbc.rb
+++ b/lib/logstash/plugin_mixins/jdbc.rb
@@ -162,6 +162,7 @@ module LogStash::PluginMixins::Jdbc
raise LogStash::ConfigurationError, "#{e}. #{message}"
end
@database = jdbc_connect()
+ @database.extension(:informix_windowing)
@database.extension(:pagination)
if @jdbc_default_timezone
@database.extension(:named_timezones)
@@ -311,3 +312,21 @@ module LogStash::PluginMixins::Jdbc
end
end
end
+
+# In the Informix SQL dialect, windowing functions are sub-clauses on the `SELECT` clause, not stand-alone clauses.
+# This extension _replaces_ the dataset's select-statement limit-clause builder with a no-op implementation, and adds
+# the approrpriate `SKIP X` and `FIRST Y` sub-clauses to the select-statment's select clause.
+module InformixWindowing
+ private
+
+ def select_select_sql(sql)
+ super(sql)
+ sql << " SKIP #{@opts[:offset]}" if @opts[:offset]
+ sql << " FIRST #{@opts[:limit]}" if @opts[:limit]
+ end
+
+ def select_limit_sql(sql)
+ # no-op
+ end
+end
+Sequel::Dataset.register_extension(:informix_windowing, InformixWindowing)
@yaauie
Copy link
Author

yaauie commented Sep 18, 2018

Diff above is Apache2-licensed, following that of the Logstash JDBC Input Plugin it is meant to be applied to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment