You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ma...@apache.org on 2016/11/07 09:56:03 UTC

[2/3] kylin git commit: KYLIN-2156: support filters like a != 0

KYLIN-2156: support filters like a != 0


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/a0c4bfba
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/a0c4bfba
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/a0c4bfba

Branch: refs/heads/master
Commit: a0c4bfba39859bca5049326f227f4e6137ab106c
Parents: 04ac1c4
Author: Hongbin Ma <ma...@apache.org>
Authored: Thu Nov 3 16:49:42 2016 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Mon Nov 7 14:51:49 2016 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/kylin/rest/util/QueryUtil.java   | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/a0c4bfba/server-base/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/util/QueryUtil.java b/server-base/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
index eb73e8f..59a4a78 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/util/QueryUtil.java
@@ -95,6 +95,7 @@ public class QueryUtil {
         private static final Pattern PTN_GROUP_BY = Pattern.compile(S1 + "GROUP" + SM + "BY" + S1, Pattern.CASE_INSENSITIVE);
         private static final Pattern PTN_HAVING_COUNT_GREATER_THAN_ZERO = Pattern.compile(S1 + "HAVING" + SM + "[(]?" + S0 + "COUNT" + S0 + "[(]" + S0 + "1" + S0 + "[)]" + S0 + ">" + S0 + "0" + S0 + "[)]?", Pattern.CASE_INSENSITIVE);
         private static final Pattern PTN_SUM_1 = Pattern.compile(S0 + "SUM" + S0 + "[(]" + S0 + "[1]" + S0 + "[)]" + S0, Pattern.CASE_INSENSITIVE);
+        private static final Pattern PTN_NOT_EQ = Pattern.compile(S0 + "!="+ S0, Pattern.CASE_INSENSITIVE);
         private static final Pattern PTN_INTERVAL = Pattern.compile("interval" + SM + "(floor\\()([\\d\\.]+)(\\))" + SM + "(second|minute|hour|day|month|year)", Pattern.CASE_INSENSITIVE);
         private static final Pattern PTN_CONCAT = Pattern.compile("concat\\(.+?\\)");//non-greedy
         private static final Pattern PTN_HAVING_ESCAPE_FUNCTION = Pattern.compile("\\{fn" + "(.*?)" + "\\}", Pattern.CASE_INSENSITIVE);
@@ -129,6 +130,15 @@ public class QueryUtil {
                 sql = sql.substring(0, m.start()) + " COUNT(1) " + sql.substring(m.end());
             }
 
+            // Case: !=
+            // Replace it with <>
+            while (true) {
+                m = PTN_NOT_EQ.matcher(sql);
+                if (!m.find())
+                    break;
+                sql = sql.substring(0, m.start()) + " <> " + sql.substring(m.end());
+            }
+
             // ( date '2001-09-28' + interval floor(1) day ) generated by cognos
             // calcite only recognizes date '2001-09-28' + interval '1' day
             while (true) {