You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2014/05/04 18:55:25 UTC

[03/21] DRILL-491: project pushdown into scan. Add base test class for testing plan.

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a3d14720/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java b/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java
new file mode 100644
index 0000000..675cddb
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill;
+
+import org.junit.Test;
+
+// Test the optimizer plan in terms of project pushdown.
+// When a query refers to a subset of columns in a table, optimizer should push the list
+// of refereed columns to the SCAN operator, so that SCAN operator would only retrieve
+// the column values in the subset of columns.
+
+public class TestProjectPushDown extends PlanTestBase {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory
+      .getLogger(TestProjectPushDown.class);
+
+  @Test
+  public void testGroupBy() throws Exception {
+    String expectedColNames = " \"columns\" : [ \"`marital_status`\" ]";
+    testPhysicalPlan(
+        "select marital_status, COUNT(1) as cnt from cp.`employee.json` group by marital_status",
+        expectedColNames);
+  }
+
+  @Test
+  public void testOrderBy() throws Exception {
+    String expectedColNames = "\"columns\" : [ \"`employee_id`\", \"`full_name`\", \"`first_name`\", \"`last_name`\" ]";
+    testPhysicalPlan("select employee_id , full_name, first_name , last_name "
+        + "from cp.`employee.json` order by first_name, last_name",
+        expectedColNames);
+  }
+
+  @Test
+  public void testExprInSelect() throws Exception {
+    String expectedColNames = "\"columns\" : [ \"`employee_id`\", \"`full_name`\", \"`first_name`\", \"`last_name`\" ]";
+    testPhysicalPlan(
+        "select employee_id + 100, full_name, first_name , last_name "
+            + "from cp.`employee.json` order by first_name, last_name",
+            expectedColNames);
+  }
+
+  @Test
+  public void testExprInWhere() throws Exception {
+    String expectedColNames = "\"columns\" : [ \"`employee_id`\", \"`full_name`\", \"`first_name`\", \"`last_name`\" ]";
+    testPhysicalPlan(
+        "select employee_id + 100, full_name, first_name , last_name "
+            + "from cp.`employee.json` where employee_id + 500 < 1000 ",
+            expectedColNames);
+  }
+
+  @Test
+  public void testJoin() throws Exception {
+    String expectedColNames1 = "\"columns\" : [ \"`N_REGIONKEY`\", \"`N_NAME`\" ]";
+    String expectedColNames2 = "\"columns\" : [ \"`R_REGIONKEY`\", \"`R_NAME`\" ]";
+
+    testPhysicalPlan("SELECT\n" + "  nations.N_NAME,\n" + "  regions.R_NAME\n"
+        + "FROM\n"
+        + "  dfs.`[WORKING_PATH]/../../sample-data/nation.parquet` nations\n"
+        + "JOIN\n"
+        + "  dfs.`[WORKING_PATH]/../../sample-data/region.parquet` regions\n"
+        + "  on nations.N_REGIONKEY = regions.R_REGIONKEY", expectedColNames1,
+        expectedColNames2);
+  }
+
+  @Test
+  public void testFromInfoSchema() throws Exception {
+    String expectedColNames = " \"columns\" : [ \"`CATALOG_DESCRIPTION`\" ]";
+    testPhysicalPlan(
+        "select count(CATALOG_DESCRIPTION) from INFORMATION_SCHEMA.CATALOGS",
+        expectedColNames);
+  }
+
+  @Test
+  public void testTPCH1() throws Exception {
+    String expectedColNames = " \"columns\" : [ \"`l_returnflag`\", \"`l_linestatus`\", \"`l_shipdate`\", \"`l_quantity`\", \"`l_extendedprice`\", \"`l_discount`\", \"`l_tax`\" ]";
+    testPhysicalPlanFromFile("queries/tpch/01.sql", expectedColNames);
+  }
+
+  @Test
+  public void testTPCH3() throws Exception {
+    String expectedColNames1 = "\"columns\" : [ \"`c_mktsegment`\", \"`c_custkey`\" ]";
+    String expectedColNames2 = " \"columns\" : [ \"`o_orderdate`\", \"`o_shippriority`\", \"`o_custkey`\", \"`o_orderkey`\" ";
+    String expectedColNames3 = "\"columns\" : [ \"`l_orderkey`\", \"`l_shipdate`\", \"`l_extendedprice`\", \"`l_discount`\" ]";
+    testPhysicalPlanFromFile("queries/tpch/03.sql", expectedColNames1, expectedColNames2, expectedColNames3);
+  }
+
+  private void testPhysicalPlanFromFile(String fileName, String... expectedSubstrs)
+      throws Exception {
+    String query = getFile(fileName);
+    String[] queries = query.split(";");
+    for (String q : queries) {
+      if (q.trim().isEmpty())
+        continue;
+      testPhysicalPlan(q, expectedSubstrs);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a3d14720/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index 148c115..6952c56 100644
--- a/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -44,7 +44,7 @@ public class TestJdbcQuery extends JdbcTest{
 
 
   // Set a timeout unless we're debugging.
-  @Rule public TestRule TIMEOUT = TestTools.getTimeoutRule(200000000);
+  @Rule public TestRule TIMEOUT = TestTools.getTimeoutRule(20000);
 
   private static final String WORKING_PATH;
   static{
@@ -78,11 +78,11 @@ public class TestJdbcQuery extends JdbcTest{
 
   @Test
   public void testInfoSchema() throws Exception{
-//    testQuery("select * from INFORMATION_SCHEMA.SCHEMATA");
+    testQuery("select * from INFORMATION_SCHEMA.SCHEMATA");
     testQuery("select * from INFORMATION_SCHEMA.CATALOGS");
-//    testQuery("select * from INFORMATION_SCHEMA.VIEWS");
+    testQuery("select * from INFORMATION_SCHEMA.VIEWS");
 //    testQuery("select * from INFORMATION_SCHEMA.TABLES");
-//    testQuery("select * from INFORMATION_SCHEMA.COLUMNS");
+    testQuery("select * from INFORMATION_SCHEMA.COLUMNS");
   }
 
   @Test