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/dc01e155 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/dc01e155 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/dc01e155 Branch: refs/heads/yang21-hbase1.x Commit: dc01e15508c6ffba16599342385f1622c3494787 Parents: ca2e071 Author: Hongbin Ma <mahong...@apache.org> Authored: Thu Nov 3 16:49:42 2016 +0800 Committer: Hongbin Ma <mahong...@apache.org> Committed: Thu Nov 3 18:32:59 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/dc01e155/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) {