Created
September 18, 2018 17:44
-
-
Save yaauie/80580027b456849e2e2f36537f95b711 to your computer and use it in GitHub Desktop.
Logstash JDBC Input Plugin: Informix DB Windowing Support Proof-of-Concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Diff above is Apache2-licensed, following that of the Logstash JDBC Input Plugin it is meant to be applied to.