You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vi...@apache.org on 2018/11/17 01:27:54 UTC

[drill] branch master updated: DRILL-6844: Query with ORDER BY DESC on indexed column does not pick secondary index.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new ead08bd  DRILL-6844: Query with ORDER BY DESC on indexed column does not pick secondary index.
ead08bd is described below

commit ead08bdc2f2982ab4f5fff14e94ee1bec29d27be
Author: Hanumath Rao Maduri <ha...@gmail.com>
AuthorDate: Thu Oct 18 19:35:55 2018 -0700

    DRILL-6844: Query with ORDER BY DESC on indexed column does not pick secondary index.
---
 .../exec/planner/index/MapRDBIndexDiscover.java    |  6 +--
 .../drill/maprdb/tests/index/IndexPlanTest.java    | 60 +++++++++++++++++-----
 .../drill/exec/planner/index/IndexPlanUtils.java   |  3 +-
 3 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/contrib/format-maprdb/src/main/java/org/apache/drill/exec/planner/index/MapRDBIndexDiscover.java b/contrib/format-maprdb/src/main/java/org/apache/drill/exec/planner/index/MapRDBIndexDiscover.java
index f828ba0..d949634 100644
--- a/contrib/format-maprdb/src/main/java/org/apache/drill/exec/planner/index/MapRDBIndexDiscover.java
+++ b/contrib/format-maprdb/src/main/java/org/apache/drill/exec/planner/index/MapRDBIndexDiscover.java
@@ -293,9 +293,9 @@ public class MapRDBIndexDiscover extends IndexDiscoverBase implements IndexDisco
       if (direction != null) {
         // assume null direction of NULLS UNSPECIFIED for now until MapR-DB adds that to the APIs
         RelFieldCollation.NullDirection nulldir =
-            desc.getMissingAndNullOrdering() == MissingAndNullOrdering.MissingAndNullFirst ? NullDirection.FIRST :
-            (desc.getMissingAndNullOrdering() == MissingAndNullOrdering.MissingAndNullLast ?
-                NullDirection.LAST : NullDirection.UNSPECIFIED);
+            direction == RelFieldCollation.Direction.ASCENDING ? NullDirection.LAST :
+            (direction == RelFieldCollation.Direction.DESCENDING ?
+                NullDirection.FIRST : NullDirection.UNSPECIFIED);
         RelFieldCollation c = new RelFieldCollation(i++, direction, nulldir);
         fieldCollations.add(c);
       } else {
diff --git a/contrib/format-maprdb/src/test/java/com/mapr/drill/maprdb/tests/index/IndexPlanTest.java b/contrib/format-maprdb/src/test/java/com/mapr/drill/maprdb/tests/index/IndexPlanTest.java
index 6754220..fd3b5cc 100644
--- a/contrib/format-maprdb/src/test/java/com/mapr/drill/maprdb/tests/index/IndexPlanTest.java
+++ b/contrib/format-maprdb/src/test/java/com/mapr/drill/maprdb/tests/index/IndexPlanTest.java
@@ -106,6 +106,7 @@ public class IndexPlanTest extends BaseJsonTest {
         {"i_ssn", "id.ssn", "contact.phone",
             "i_state_city", "address.state,address.city", "name.fname,name.lname",//mainly for composite key test
             "i_age", "personal.age", "",
+            "i_age_desc", "personal.age:desc", "",
             "i_income", "personal.income", "",
             "i_lic", "driverlicense", "reverseid",
             "i_state_city_dl", "address.state,address.city", "driverlicense",
@@ -1935,27 +1936,58 @@ public class IndexPlanTest extends BaseJsonTest {
   public void testRowkeyJoinPushdown_13() throws Exception {
     // Check option planner.rowkeyjoin_conversion_using_hashjoin works as expected!
     String query = "select t1.id.ssn as ssn from hbase.`index_test_primary` t1 where _id in (select t2._id " +
-        " from hbase.`index_test_primary` t2 where cast(t2.activity.irs.firstlogin as timestamp) = " +
-        " to_timestamp('2013-02-04 22:34:38.0', 'YYYY-MM-dd HH:mm:ss.S'))";
+            " from hbase.`index_test_primary` t2 where cast(t2.activity.irs.firstlogin as timestamp) = " +
+            " to_timestamp('2013-02-04 22:34:38.0', 'YYYY-MM-dd HH:mm:ss.S'))";
     try {
       test(incrRowKeyJoinConvSelThreshold + ";" + lowNonCoveringSelectivityThreshold + ";");
-      PlanTestBase.testPlanMatchingPatterns(query, new String[] {"RowKeyJoin"}, new String[] {});
+      PlanTestBase.testPlanMatchingPatterns(query, new String[]{"RowKeyJoin"}, new String[]{});
       testBuilder()
-          .sqlQuery(query)
-          .ordered()
-          .baselineColumns("ssn").baselineValues("100007423")
-          .go();
+              .sqlQuery(query)
+              .ordered()
+              .baselineColumns("ssn").baselineValues("100007423")
+              .go();
       test(incrRowKeyJoinConvSelThreshold + ";" + lowNonCoveringSelectivityThreshold + ";" +
-          forceRowKeyJoinConversionUsingHashJoin + ";");
-      PlanTestBase.testPlanMatchingPatterns(query, new String[] {"HashJoin"}, new String[] {"RowKeyJoin"});
+              forceRowKeyJoinConversionUsingHashJoin + ";");
+      PlanTestBase.testPlanMatchingPatterns(query, new String[]{"HashJoin"}, new String[]{"RowKeyJoin"});
       testBuilder()
-          .sqlQuery(query)
-          .ordered()
-          .baselineColumns("ssn").baselineValues("100007423")
-          .go();
+              .sqlQuery(query)
+              .ordered()
+              .baselineColumns("ssn").baselineValues("100007423")
+              .go();
     } finally {
       test(defaultRowKeyConvSelThreshold + ";" + defaultnonCoveringSelectivityThreshold + ";" +
-          defaultRowKeyJoinConversionUsingHashJoin);
+              defaultRowKeyJoinConversionUsingHashJoin);
+    }
+  }
+
+  public void TestIndexScanWithDescOrderByNullsFirst() throws Exception {
+
+    String query = "select t.personal.age from hbase.`index_test_primary` t order by t.personal.age desc nulls first limit 1";
+    try {
+      test(defaultHavingIndexPlan + ";" + lowRowKeyJoinBackIOFactor + ";");
+      PlanTestBase.testPlanMatchingPatterns(query,
+              new String[]{".*JsonTableGroupScan.*indexName=i_age_desc.*"},
+              new String[]{}
+      );
+    } finally {
+      test(defaultRowKeyJoinBackIOFactor);
+    }
+    return;
+  }
+
+  @Test
+  public void TestIndexScanWithDescOrderByNullsLast() throws Exception {
+
+    String query = "select t.personal.age from hbase.`index_test_primary` t order by t.personal.age desc nulls last limit 1";
+    try {
+      test(defaultHavingIndexPlan + ";" + lowRowKeyJoinBackIOFactor + ";");
+      PlanTestBase.testPlanMatchingPatterns(query,
+              new String[]{},
+              new String[]{".*indexName=i_age_desc.*"}
+      );
+    } finally {
+      test(defaultRowKeyJoinBackIOFactor);
     }
+    return;
   }
 }
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/index/IndexPlanUtils.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/index/IndexPlanUtils.java
index c0758c7..3242761 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/index/IndexPlanUtils.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/index/IndexPlanUtils.java
@@ -563,7 +563,8 @@ public class IndexPlanUtils {
       }
 
       RelCollation idxCollation = indexDesc.getCollation();
-      RelFieldCollation.NullDirection nullsDir = indexDesc.getNullsOrderingDirection();
+      RelFieldCollation.NullDirection nullsDir = idxCollation == null ? RelFieldCollation.NullDirection.UNSPECIFIED :
+              idxCollation.getFieldCollations().get(idxFieldCount).nullDirection;
       RelFieldCollation.Direction dir = (idxCollation == null)?
           null : idxCollation.getFieldCollations().get(idxFieldCount).direction;
       if (dir == null) {