drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From par...@apache.org
Subject [4/5] drill git commit: DRILL-2094: Add SqlOrderBy rule for CompoundIdentifierConverter
Date Tue, 24 Mar 2015 19:41:10 GMT
DRILL-2094: Add SqlOrderBy rule for CompoundIdentifierConverter


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

Branch: refs/heads/master
Commit: 07a981797dd6094ad0706c7e45d6afc0899a5510
Parents: c7cf883
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Wed Mar 18 08:59:04 2015 -0700
Committer: Parth Chandra <pchandra@maprtech.com>
Committed: Tue Mar 24 12:12:19 2015 -0700

----------------------------------------------------------------------
 .../sql/parser/CompoundIdentifierConverter.java | 16 +++++++++++++
 .../org/apache/drill/TestExampleQueries.java    | 20 ++++++++++++++++
 .../store/json/orderByArrayElement.json         | 24 ++++++++++++++++++++
 3 files changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/07a98179/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/CompoundIdentifierConverter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/CompoundIdentifierConverter.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/CompoundIdentifierConverter.java
index 061524d..eb97941 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/CompoundIdentifierConverter.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/CompoundIdentifierConverter.java
@@ -24,6 +24,7 @@ import org.eigenbase.sql.SqlCall;
 import org.eigenbase.sql.SqlIdentifier;
 import org.eigenbase.sql.SqlJoin;
 import org.eigenbase.sql.SqlNode;
+import org.eigenbase.sql.SqlOrderBy;
 import org.eigenbase.sql.SqlSelect;
 import org.eigenbase.sql.util.SqlShuttle;
 import org.eigenbase.sql.util.SqlVisitor;
@@ -125,6 +126,18 @@ public class CompoundIdentifierConverter extends SqlShuttle {
     final RewriteType D =RewriteType.DISABLE;
     final RewriteType U =RewriteType.UNCHANGED;
 
+    /*
+    This map stores the rules that instruct each SqlCall class which data field needs
+    to be rewritten if that data field is a CompoundIdentifier
+
+    Key  : Each rule corresponds to a SqlCall class;
+    value: It is an array of RewriteType, each being associated with a data field
+           in that class.
+
+           For example, there are four data fields (query, orderList, offset, fetch)
+           in org.eigenbase.sql.SqlOrderBy. Since only orderList needs to be written,
+           RewriteType[] should be R(D, E, D, D).
+    */
     Map<Class<? extends SqlCall>, RewriteType[]> rules = Maps.newHashMap();
 
   //SqlNodeList keywordList,
@@ -146,9 +159,12 @@ public class CompoundIdentifierConverter extends SqlShuttle {
     rules.put(SqlShowSchemas.class, R(D, D));
     rules.put(SqlUseSchema.class, R(D));
     rules.put(SqlJoin.class, R(D, D, D, D, D, E));
+    rules.put(SqlOrderBy.class, R(D, E, D, D));
     REWRITE_RULES = ImmutableMap.copyOf(rules);
   }
 
+  // Each type in the input arguments refers to
+  // each data field in the class
   private static RewriteType[] R(RewriteType... types){
     return types;
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/07a98179/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index d2d97f8..1d59a11 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -736,4 +736,24 @@ public class TestExampleQueries extends BaseTestQuery{
         .baselineValues((long) 2, (long) 2)
         .build().run();
   }
+
+  @Test // DRILL-2094
+  public void testOrderbyArrayElement() throws Exception {
+    String root = FileUtils.getResourceAsFile("/store/json/orderByArrayElement.json").toURI().toString();
+
+    String query = String.format("select t.id, t.list[0] as SortingElem " +
+        "from dfs_test.`%s` t " +
+        "order by t.list[0]", root);
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("id", "SortingElem")
+        .baselineValues((long) 1, (long) 1)
+        .baselineValues((long) 5, (long) 2)
+        .baselineValues((long) 4, (long) 3)
+        .baselineValues((long) 2, (long) 5)
+        .baselineValues((long) 3, (long) 6)
+        .build().run();
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/07a98179/exec/java-exec/src/test/resources/store/json/orderByArrayElement.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/store/json/orderByArrayElement.json b/exec/java-exec/src/test/resources/store/json/orderByArrayElement.json
new file mode 100644
index 0000000..d2236c8
--- /dev/null
+++ b/exec/java-exec/src/test/resources/store/json/orderByArrayElement.json
@@ -0,0 +1,24 @@
+{
+  "id" : 1,
+  "list" : [1,2]
+}
+
+{
+  "id" : 2,
+  "list" : [5,4]
+}
+
+{
+  "id" : 3,
+  "list" : [6,6]
+}
+
+{
+  "id" : 4,
+  "list" : [3,8]
+}
+
+{
+  "id" : 5,
+  "list" : [2,10]
+}
\ No newline at end of file


Mime
View raw message