You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by qi...@apache.org on 2016/10/19 03:19:10 UTC
[11/28] incubator-eagle git commit: EAGLE-333 Fix hive.ql.Parser cant
parse complex SQL fix hive parser issues
EAGLE-333 Fix hive.ql.Parser cant parse complex SQL
fix hive parser issues
Author: @wangyum <wg...@gmail.com>
Reviewer: @yonzhang <yo...@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/master
Commit: 11d4be769b9cc1decd97f9d18f96236afbf153bf
Parents: 4627eb0
Author: yonzhang <yo...@gmail.com>
Authored: Thu Jun 16 15:17:51 2016 -0700
Committer: yonzhang <yo...@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" +