{"id":443,"date":"2017-06-18T10:36:04","date_gmt":"2017-06-18T08:36:04","guid":{"rendered":"http:\/\/dekarlab.de\/wp\/?p=443"},"modified":"2020-05-23T15:36:16","modified_gmt":"2020-05-23T13:36:16","slug":"how-to-implement-kylin-dialect-for-mondrian","status":"publish","type":"post","link":"https:\/\/dekarlab.de\/wp\/?p=443","title":{"rendered":"How to implement Kylin dialect for Mondrian"},"content":{"rendered":"<p>In this post I will explain, how to implement Kylin dialect in Mondrian.<\/p>\n<p><!--more--><\/p>\n<p>First of all you need to download last version of <a href=\"https:\/\/sourceforge.net\/projects\/mondrian\/files\/mondrian\/mondrian-3.14.0\/\">Mondrian <\/a>and source code for it .<\/p>\n<p>Our plan consists of the following steps:<br \/>\nWe will change the following classes for mondrian:<br \/>\n<strong>mondrian.spi.impl.JdbcDialectImpl<\/strong><br \/>\n<strong>mondrian.spi.Dialect<\/strong><\/p>\n<p>And we will implement new dialect as<br \/>\n<strong>mondrian.spi.impl.KylinDialect<\/strong><\/p>\n<p>After changes are done you can compile the classes (with mondrian jar in the class path) and replace them in the mondrian jar.<\/p>\n<p>First of all we need to explain mondrian, that there is new dialect available. For this we will do:<\/p>\n<p>Step 1:\u00a0Add two lines in getProduct method in <strong>mondrian.spi.impl.JdbcDialectImpl<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n} else if (productName.equals(&quot;Interbase&quot;)) {\r\nreturn DatabaseProduct.INTERBASE;\r\n} else if (upperProductName.equals(&quot;KYLIN&quot;)) {  \/\/LINE 1\r\nreturn DatabaseProduct.KYLIN;                   \/\/LINE 2\r\n} else if (upperProductName.equals(&quot;LUCIDDB&quot;) || upperProductName.equals(&quot;OPTIQ&quot;)) {\r\nreturn DatabaseProduct.LUCIDDB;\r\n<\/pre>\n<p>Step 2: Add constant in mondrian.spi.Dialect<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n    enum DatabaseProduct {\r\n        ACCESS,\r\n        UNKNOWN,\r\n        DERBY,\r\n        DB2_OLD_AS400,\r\n        DB2_AS400,\r\n        DB2,\r\n        FIREBIRD,\r\n        GREENPLUM,\r\n        HIVE,\r\n        HSQLDB,\r\n        IMPALA,\r\n        INFORMIX,\r\n        INFOBRIGHT,\r\n        INGRES,\r\n        INTERBASE,\r\n        KYLIN,                             \/\/KYLIN Constant\r\n        LUCIDDB,\r\n<\/pre>\n<p>The last step is to implement Kylin Dialect. We need to extend JdbcDialectImpl class and says mondrian, which options are supported and not supported by Kylin JDBC implementation:<\/p>\n<ul>\n<li>Kylin does not support allowsCountDistinct =&gt; false<\/li>\n<li>Kylin supports allowsJoinOn =&gt; true<\/li>\n<li>Mondrian should use Ansi Syntax by generating order by nulls SQL requests (generateOrderByNulls)<\/li>\n<li>We should turn off the quoting of numbers. Sometimes mondrian does not recorgnize them correctly. (quoteStringLiteral)<\/li>\n<li>We should turn off to Upper function for numbers. Sometimes mondrian does not recorgnize them correctly (toUpper)<\/li>\n<\/ul>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\r\npublic class KylinDialect extends JdbcDialectImpl {\r\n    public static final JdbcDialectFactory FACTORY = new JdbcDialectFactory(KylinDialect.class, DatabaseProduct.KYLIN) {\r\n                protected boolean acceptsConnection(Connection connection) {\r\n                    return super.acceptsConnection(connection);\r\n                }\r\n            };\r\n\r\n    public KylinDialect(Connection connection) throws SQLException {\r\n        super(connection);\r\n    }\r\n\r\n    public boolean allowsCountDistinct() {\r\n        return false;\r\n    }\r\n\r\n    public boolean allowsJoinOn() {\r\n        return true;\r\n    }\r\n\t\r\n    protected String generateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast) {\r\n        return generateOrderByNullsAnsi(expr, ascending, collateNullsLast);\r\n    }\r\n\r\n    public void quoteStringLiteral(StringBuilder buf, String s) {\r\n        try {\r\n            Double.parseDouble(s);\r\n            buf.append(s);\r\n        } catch (Exception ex) {\r\n            super.quoteStringLiteral(buf, s);\r\n        }\r\n    }\r\n\r\n    public String toUpper(String expr) {\r\n        try {\r\n            Double.parseDouble(expr);\r\n        } catch (Exception ex) {\r\n            return super.toUpper(expr);\r\n        }\r\n        return expr;\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/dekarlab.de\/wp\/?p=363\">Next you can read how to use Kylin Cubes with Excel Pivot.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will explain, how to implement Kylin dialect in Mondrian.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[25],"tags":[57,48,56],"_links":{"self":[{"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=\/wp\/v2\/posts\/443"}],"collection":[{"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=443"}],"version-history":[{"count":5,"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=\/wp\/v2\/posts\/443\/revisions\/522"}],"wp:attachment":[{"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dekarlab.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}