eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yonzhang2...@apache.org
Subject incubator-eagle git commit: EAGLE-333 Fix hive.ql.Parser cant parse complex SQL fix hive parser issues
Date Thu, 16 Jun 2016 22:15:19 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/branch-0.4 4627eb0b5 -> 11d4be769


EAGLE-333 Fix hive.ql.Parser cant parse complex SQL
fix hive parser issues

Author: @wangyum <wgyumg@gmail.com>
Reviewer: @yonzhang <yonzhang2012@gmail.com>

Closes: #230


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/11d4be76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/11d4be76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/11d4be76

Branch: refs/heads/branch-0.4
Commit: 11d4be769b9cc1decd97f9d18f96236afbf153bf
Parents: 4627eb0
Author: yonzhang <yonzhang2012@gmail.com>
Authored: Thu Jun 16 15:17:51 2016 -0700
Committer: yonzhang <yonzhang2012@gmail.com>
Committed: Thu Jun 16 15:17:51 2016 -0700

----------------------------------------------------------------------
 .../apache/eagle/security/hive/ql/Parser.java   |  6 ++--
 .../eagle/security/hive/ql/TestParser.java      | 34 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/11d4be76/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/ql/Parser.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/ql/Parser.java
b/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/ql/Parser.java
index 19ce003..f812d1e 100644
--- a/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/ql/Parser.java
+++ b/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/ql/Parser.java
@@ -303,7 +303,7 @@ public class Parser {
         }
         break;
 
-      case HiveParser.TOK_FUNCTION:
+      case HiveParser.TOK_FUNCTION: case HiveParser.TOK_FUNCTIONDI:
         // Traverse children to get TOK_TABLE_OR_COL
         Set<String> tempSet = new HashSet<>();
         parseTokFunction(asn, tempSet);
@@ -337,14 +337,14 @@ public class Parser {
         String colRealName = convAliasToReal(columnAliasMap, ast.getChild(0).getText());
         set.add(colRealName);
         break;
-      case HiveParser.TOK_FUNCTION:
+      // Not only HiveParser.TOK_FUNCTION, but also HiveParser.KW_ADD, HiveParser.KW_WHEN
...
+      default:
         for (int i = 0; i < ast.getChildCount(); i++) {
           ASTNode n = (ASTNode)ast.getChild(i);
           if (n != null) {
             parseTokFunction(n, set);
           }
         }
-        break;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/11d4be76/eagle-security/eagle-security-hive/src/test/java/org/apache/eagle/security/hive/ql/TestParser.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hive/src/test/java/org/apache/eagle/security/hive/ql/TestParser.java
b/eagle-security/eagle-security-hive/src/test/java/org/apache/eagle/security/hive/ql/TestParser.java
index 0bd994f..fd2296d 100644
--- a/eagle-security/eagle-security-hive/src/test/java/org/apache/eagle/security/hive/ql/TestParser.java
+++ b/eagle-security/eagle-security-hive/src/test/java/org/apache/eagle/security/hive/ql/TestParser.java
@@ -235,6 +235,40 @@ public class TestParser {
     }
 
     @Test
+    public void testCountDistinct() throws Exception {
+        String query =  "SELECT count(distinct id) FROM db.table1";
+        String expectedOperation = "SELECT";
+        Map<String, Set<String>> expectedTableColumn = new HashMap<String,
Set<String>>();
+        Set<String> set = new HashSet<String>();
+        set.add("id");
+        expectedTableColumn.put("db.table1", set);
+        _testParsingQuery(query, expectedOperation, null, expectedTableColumn);
+    }
+
+    @Test
+    public void testComplextQuery() throws Exception {
+        String query =  "SELECT id, \n" +
+                "  SUM(CASE WHEN(type=1 AND ds < '2016-05-12' AND category IN ('1', '2'))
" +
+                "    THEN 1 ELSE 0 end) / COUNT(DISTINCT id) AS col1, \n" +
+                "  CASE WHEN SUM(CASE WHEN type=1 THEN 1 ELSE 0 END)=0 THEN 0 " +
+                "    ELSE SUM(CASE WHEN type=1 AND DATEDIFF('2016-05-21', ds)=1 " +
+                "    THEN 1 ELSE 0 END) * DATEDIFF('2016-05-21', '2016-04-21') / " +
+                "    SUM(CASE WHEN type=1 THEN 1 ELSE 0 END) END AS col2 \n" +
+                "FROM db.table1 \n" +
+                "WHERE ds < '2016-05-21' \n" +
+                "GROUP BY id";
+        String expectedOperation = "SELECT";
+        Map<String, Set<String>> expectedTableColumn = new HashMap<String,
Set<String>>();
+        Set<String> set = new HashSet<String>();
+        set.add("id");
+        set.add("ds");
+        set.add("type");
+        set.add("category");
+        expectedTableColumn.put("db.table1", set);
+        _testParsingQuery(query, expectedOperation, null, expectedTableColumn);
+    }
+
+    @Test
     public void testCreateTable() throws Exception {
         String query = "CREATE TABLE page_view(viewTime INT, userid BIGINT,\n" +
                 "                page_url STRING, referrer_url STRING,\n" +


Mime
View raw message