Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.