[ 
https://issues.apache.org/jira/browse/DRILL-6381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16647426#comment-16647426
 ] 

ASF GitHub Bot commented on DRILL-6381:
---------------------------------------

vdiravka commented on a change in pull request #1466: DRILL-6381: Add support 
for index based planning and execution
URL: https://github.com/apache/drill/pull/1466#discussion_r223651862
 
 

 ##########
 File path: 
contrib/format-maprdb/src/main/java/org/apache/drill/exec/store/mapr/db/json/JsonTableRangePartitionFunction.java
 ##########
 @@ -0,0 +1,237 @@
+/*
+ * 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.exec.store.mapr.db.json;
+
+import java.util.List;
+
+import org.apache.drill.common.expression.FieldReference;
+import org.apache.drill.exec.planner.physical.AbstractRangePartitionFunction;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.store.mapr.db.MapRDBFormatPlugin;
+import org.apache.drill.exec.vector.ValueVector;
+import org.ojai.store.QueryCondition;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.mapr.db.Table;
+import com.mapr.db.impl.ConditionImpl;
+import com.mapr.db.impl.IdCodec;
+import com.mapr.db.impl.ConditionNode.RowkeyRange;
+import com.mapr.db.scan.ScanRange;
+import com.mapr.fs.jni.MapRConstants;
+import com.mapr.org.apache.hadoop.hbase.util.Bytes;
+
+@JsonTypeName("jsontable-range-partition-function")
+public class JsonTableRangePartitionFunction extends 
AbstractRangePartitionFunction {
+
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(JsonTableRangePartitionFunction.class);
+
+  @JsonProperty("refList")
+  protected List<FieldReference> refList;
+
+  @JsonProperty("tableName")
+  protected String tableName;
+
+  @JsonIgnore
+  protected String userName;
+
+  @JsonIgnore
+  protected ValueVector partitionKeyVector = null;
+
+  // List of start keys of the scan ranges for the table.
+  @JsonProperty
+  protected List<byte[]> startKeys = null;
+
+  // List of stop keys of the scan ranges for the table.
+  @JsonProperty
+  protected List<byte[]> stopKeys = null;
+
+  @JsonCreator
+  public JsonTableRangePartitionFunction(
+      @JsonProperty("refList") List<FieldReference> refList,
+      @JsonProperty("tableName") String tableName,
+      @JsonProperty("startKeys") List<byte[]> startKeys,
+      @JsonProperty("stopKeys") List<byte[]> stopKeys) {
+    this.refList = refList;
+    this.tableName = tableName;
+    this.startKeys = startKeys;
+    this.stopKeys = stopKeys;
+  }
+
+  public JsonTableRangePartitionFunction(List<FieldReference> refList,
+      String tableName, String userName, MapRDBFormatPlugin formatPlugin) {
+    this.refList = refList;
+    this.tableName = tableName;
+    this.userName = userName;
+    initialize(formatPlugin);
+  }
+
+  @JsonProperty("refList")
+  @Override
+  public List<FieldReference> getPartitionRefList() {
+    return refList;
+  }
+
+  @Override
+  public void setup(List<VectorWrapper<?>> partitionKeys) {
+    if (partitionKeys.size() != 1) {
+      throw new UnsupportedOperationException(
+          "Range partitioning function supports exactly one partition column; 
encountered " + partitionKeys.size());
+    }
+
+    VectorWrapper<?> v = partitionKeys.get(0);
+
+    partitionKeyVector = v.getValueVector();
+
+    Preconditions.checkArgument(partitionKeyVector != null, "Found null 
partitionKeVector.") ;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    }
+    if (obj instanceof JsonTableRangePartitionFunction) {
+      JsonTableRangePartitionFunction rpf = (JsonTableRangePartitionFunction) 
obj;
+      List<FieldReference> thisPartRefList = this.getPartitionRefList();
+      List<FieldReference> otherPartRefList = rpf.getPartitionRefList();
+      if (thisPartRefList.size() != otherPartRefList.size()) {
+        return false;
+      }
+      for (int refIdx=0; refIdx<thisPartRefList.size(); refIdx++) {
+        if (!thisPartRefList.get(refIdx).equals(otherPartRefList.get(refIdx))) 
{
+          return false;
+        }
+      }
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  public int eval(int index, int numPartitions) {
+
+         String key = 
partitionKeyVector.getAccessor().getObject(index).toString();
+         byte[] encodedKey = IdCodec.encodeAsBytes(key);
+
+    int tabletId = -1;
+
+    // Do a 'range' binary search through the list of start-stop keys to find 
nearest range.  Assumption is
+    // that the list of start keys is ordered (this is ensured by 
MetaTable.getScanRanges())
+    // TODO: This search should ideally be delegated to MapR-DB once an 
appropriate API is available
+    // to optimize this
+    int low = 0, high = startKeys.size() - 1;
+    while (low <= high) {
+      int mid = low + (high-low)/2;
+
+      byte[] start = startKeys.get(mid);
+      byte[] stop  = stopKeys.get(mid);
+
+      // Check if key is present in the mid interval of [start, stop].
+      // Account for empty byte array start/stop
+      if ( (Bytes.compareTo(encodedKey, start) >= 0 ||
 
 Review comment:
   formatting

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add capability to do index based planning and execution
> -------------------------------------------------------
>
>                 Key: DRILL-6381
>                 URL: https://issues.apache.org/jira/browse/DRILL-6381
>             Project: Apache Drill
>          Issue Type: New Feature
>          Components: Execution - Relational Operators, Query Planning &amp; 
> Optimization
>            Reporter: Aman Sinha
>            Assignee: Aman Sinha
>            Priority: Major
>             Fix For: 1.15.0
>
>
> If the underlying data source supports indexes (primary and secondary 
> indexes), Drill should leverage those during planning and execution in order 
> to improve query performance.  
> On the planning side, Drill planner should be enhanced to provide an 
> abstraction layer which express the index metadata and statistics.  Further, 
> a cost-based index selection is needed to decide which index(es) are 
> suitable.  
> On the execution side, appropriate operator enhancements would be needed to 
> handle different categories of indexes such as covering, non-covering 
> indexes, taking into consideration the index data may not be co-located with 
> the primary table, i.e a global index.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to