This is an automated email from the ASF dual-hosted git repository.

volodymyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit f258eb54a8181d8a375317f60b8b96d6a356358c
Author: Volodymyr Vysotskyi <[email protected]>
AuthorDate: Wed Dec 18 19:16:08 2019 +0200

    DRILL-7490: LIMIT is not pushed to JDBC storage plugin
    
    closes #1936
---
 .../exec/store/jdbc/TestJdbcPluginWithMySQLIT.java | 36 +++++++++++++---------
 .../exec/planner/cost/DrillRelMdRowCount.java      | 20 +-----------
 2 files changed, 23 insertions(+), 33 deletions(-)

diff --git 
a/contrib/storage-jdbc/src/test/java/org/apache/drill/exec/store/jdbc/TestJdbcPluginWithMySQLIT.java
 
b/contrib/storage-jdbc/src/test/java/org/apache/drill/exec/store/jdbc/TestJdbcPluginWithMySQLIT.java
index bd065ca..6253d11 100644
--- 
a/contrib/storage-jdbc/src/test/java/org/apache/drill/exec/store/jdbc/TestJdbcPluginWithMySQLIT.java
+++ 
b/contrib/storage-jdbc/src/test/java/org/apache/drill/exec/store/jdbc/TestJdbcPluginWithMySQLIT.java
@@ -37,10 +37,7 @@ import org.junit.experimental.categories.Category;
 
 import java.math.BigDecimal;
 
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
 
 /**
  * JDBC storage plugin tests against MySQL.
@@ -195,11 +192,12 @@ public class TestJdbcPluginWithMySQLIT extends 
ClusterTest {
   @Test
   public void pushdownJoin() throws Exception {
     String query = "select x.person_id from (select person_id from 
mysql.`drill_mysql_test`.person) x "
-            + "join (select person_id from mysql.`drill_mysql_test`.person) y 
on x.person_id = y.person_id ";
-    String plan = queryBuilder().sql(query).explainText();
-
-    assertThat("Query plan shouldn't contain Join operator",
-        plan, not(containsString("Join")));
+            + "join (select person_id from mysql.`drill_mysql_test`.person) y 
on x.person_id = y.person_id";
+    queryBuilder()
+        .sql(query)
+        .planMatcher()
+        .exclude("Join")
+        .match();
   }
 
   @Test
@@ -211,12 +209,11 @@ public class TestJdbcPluginWithMySQLIT extends 
ClusterTest {
             "ON e.first_name = s.first_name " +
             "WHERE e.last_name > 'hello'";
 
-    String plan = queryBuilder().sql(query).explainText();
-
-    assertThat("Query plan shouldn't contain Join operator",
-        plan, not(containsString("Join")));
-    assertThat("Query plan shouldn't contain Filter operator",
-        plan, not(containsString("Filter")));
+    queryBuilder()
+        .sql(query)
+        .planMatcher()
+        .exclude("Join", "Filter")
+        .match();
   }
 
   @Test
@@ -341,4 +338,15 @@ public class TestJdbcPluginWithMySQLIT extends ClusterTest 
{
         .baselineValuesForSingleColumn("SYSTEM VIEW", "TABLE", "VIEW")
         .go();
   }
+
+  @Test
+  public void testLimitPushDown() throws Exception {
+    String query = "select person_id from mysql.`drill_mysql_test`.person 
limit 10";
+    queryBuilder()
+        .sql(query)
+        .planMatcher()
+        .include("Jdbc\\(.*LIMIT 10")
+        .exclude("Limit\\(")
+        .match();
+  }
 }
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdRowCount.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdRowCount.java
index a24f5d1..0bfb70a 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdRowCount.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdRowCount.java
@@ -18,12 +18,9 @@
 package org.apache.drill.exec.planner.cost;
 
 import java.io.IOException;
-import org.apache.calcite.rel.SingleRel;
 import org.apache.calcite.rel.core.Aggregate;
 import org.apache.calcite.rel.core.Filter;
 import org.apache.calcite.rel.core.Join;
-import org.apache.calcite.rel.core.Project;
-import org.apache.calcite.rel.core.Sort;
 import org.apache.calcite.rel.core.TableScan;
 import org.apache.calcite.rel.core.Union;
 import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
@@ -59,7 +56,7 @@ public class DrillRelMdRowCount extends RelMdRowCount{
           ((AggPrelBase) rel).getOperatorPhase() == 
AggPrelBase.OperatorPhase.PHASE_1of2) {
       // Phase 1 Aggregate would return rows in the range [NDV, input_rows]. 
Hence, use the
       // existing estimate of 1/10 * input_rows
-        Double rowCount = mq.getRowCount(rel.getInput()) / 10;
+        double rowCount = mq.getRowCount(rel.getInput()) / 10;
         Double ndv = mq.getDistinctRowCount(rel.getInput(), groupKey, null);
         // Use max of NDV and input_rows/10
         if (ndv != null) {
@@ -83,21 +80,6 @@ public class DrillRelMdRowCount extends RelMdRowCount{
   }
 
   @Override
-  public Double getRowCount(Project rel, RelMetadataQuery mq) {
-    return rel.estimateRowCount(mq);
-  }
-
-  @Override
-  public Double getRowCount(Sort rel, RelMetadataQuery mq) {
-    return rel.estimateRowCount(mq);
-  }
-
-  @Override
-  public Double getRowCount(SingleRel rel, RelMetadataQuery mq) {
-    return rel.estimateRowCount(mq);
-  }
-
-  @Override
   public Double getRowCount(Join rel, RelMetadataQuery mq) {
     return rel.estimateRowCount(mq);
   }

Reply via email to