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

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_r223659334
 
 

 ##########
 File path: 
contrib/format-maprdb/src/test/java/com/mapr/drill/maprdb/tests/index/LargeTableGen.java
 ##########
 @@ -0,0 +1,176 @@
+/*
+ * 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 com.mapr.drill.maprdb.tests.index;
+
+import static com.mapr.drill.maprdb.tests.MaprDBTestsSuite.INDEX_FLUSH_TIMEOUT;
+
+import java.io.InputStream;
+import java.io.StringBufferInputStream;
+
+import org.apache.hadoop.fs.Path;
+import org.ojai.DocumentStream;
+import org.ojai.json.Json;
+
+import com.mapr.db.Admin;
+import com.mapr.db.Table;
+import com.mapr.db.TableDescriptor;
+import com.mapr.db.impl.MapRDBImpl;
+import com.mapr.db.impl.TableDescriptorImpl;
+import com.mapr.db.tests.utils.DBTests;
+import com.mapr.fs.utils.ssh.TestCluster;
+
+/**
+ * This class is to generate a MapR json table of this schema:
+ * {
+ *   "address" : {
+ *      "city":"wtj",
+ *      "state":"ho"
+ *   }
+ *   "contact" : {
+ *      "email":"vcfahj...@gmail.com",
+ *      "phone":"6500005583"
+ *   }
+ *   "id" : {
+ *      "ssn":"100005461"
+ *   }
+ *   "name" : {
+ *      "fname":"VcFahj",
+ *      "lname":"RfM"
+ *   }
+ * }
+ *
+ */
+public class LargeTableGen extends LargeTableGenBase {
+
+  static final int SPLIT_SIZE = 5000;
+  private Admin admin;
+
+  public LargeTableGen(Admin dbadmin) {
+    admin = dbadmin;
+  }
+
+  Table createOrGetTable(String tableName, int recordNum) {
+    if (admin.tableExists(tableName)) {
+      return MapRDBImpl.getTable(tableName);
+      //admin.deleteTable(tableName);
+    }
+    else {
+      TableDescriptor desc = new TableDescriptorImpl(new Path(tableName));
+
+      int splits = (recordNum / SPLIT_SIZE) - (((recordNum % SPLIT_SIZE) > 1)? 
0 : 1);
+
+      String[] splitsStr = new String[splits];
+      StringBuilder strBuilder = new StringBuilder("Splits:");
+      for(int i=0; i<splits; ++i) {
+        splitsStr[i] = String.format("%d", (i+1)*SPLIT_SIZE);
+        strBuilder.append(splitsStr[i] + ", ");
+      }
+      System.out.print(strBuilder.toString());
+
+      return admin.createTable(desc, splitsStr);
+    }
+  }
+
+  private void createIndex(Table table, String[] indexDef) throws Exception {
+    if(indexDef == null) {
+      //don't create index here. indexes may have been created
+      return;
+    }
+    for(int i=0; i<indexDef.length / 3; ++i) {
+      String indexCmd = String.format("maprcli table index add"
+          + " -path " + table.getPath()
+          + " -index %s"
+          + " -indexedfields '%s'"
+          + ((indexDef[3 * i + 2].length()==0)?"":" -includedfields '%s'")
+          + ((indexDef[3 * i].startsWith("hash"))? " -hashed true" : ""),
+          indexDefInCommand(indexDef[3 * i]), //index name
+          indexDefInCommand(indexDef[3 * i + 1]), //indexedfields
+          indexDefInCommand(indexDef[3 * i + 2])); //includedfields
+      System.out.println(indexCmd);
+
+      TestCluster.runCommand(indexCmd);
+      DBTests.admin().getTableIndexes(table.getPath(), true);
+    }
+  }
+
+  private String indexDefInCommand(String def) {
+    String[] splitted = def.split(",");
+    StringBuffer ret = new StringBuffer();
+    for(String field: splitted) {
+      if(ret.length() == 0) {
+        ret.append(field);
+      }
+      else {
+        ret.append(",").append(field);
+      }
+    }
+    return ret.toString();
+  }
+  public void generateTableWithIndex(String tablePath, int recordNumber, 
String[] indexDef) throws Exception {
+    // create index
+
+    initRandVector(recordNumber);
+    initDictionary();
+    DBTests.setTableStatsSendInterval(1);
+
+    if (admin.tableExists(tablePath)) {
+      //admin.deleteTable(tablePath);
+    }
+
+    //create Json String
+    int batch, i;
+    int BATCH_SIZE=2000;
+    try (Table table = createOrGetTable(tablePath, recordNumber)) {
+      //create index
+      createIndex(table, indexDef);
+      for (batch = 0; batch < recordNumber; batch += BATCH_SIZE) {
+        int batchStop = Math.min(recordNumber, batch + BATCH_SIZE);
+        StringBuffer strBuf = new StringBuffer();
+        for (i = batch; i < batchStop; ++i) {
+
+          strBuf.append(String.format("{\"rowid\": \"%d\", \"reverseid\": 
\"%d\", \"id\": {\"ssn\": \"%s\"}, \"contact\": {\"phone\": \"%s\", \"email\": 
\"%s\"}," +
+                  "\"address\": {\"city\": \"%s\", \"state\": \"%s\"}, 
\"name\": { \"fname\": \"%s\", \"lname\": \"%s\" }," +
+                  "\"personal\": {\"age\" : %s, \"income\": %s, \"birthdate\": 
{\"$dateDay\": \"%s\"} }," +
+                  "\"activity\": {\"irs\" : { \"firstlogin\":  \"%s\" } }," +
+                  "\"driverlicense\":{\"$numberLong\": %s} } \n",
+              i + 1, recordNumber - i , getSSN(i), getPhone(i), getEmail(i),
+              getAddress(i)[2], getAddress(i)[1], getFirstName(i), 
getLastName(i),
+              getAge(i), getIncome(i), getBirthdate(i),
+              getFirstLogin(i),
+              getSSN(i)));
+        }
+        try (InputStream in = new StringBufferInputStream(strBuf.toString());
+             DocumentStream stream = Json.newDocumentStream(in)) {
+          //write by individual document
+          //for (Document document : stream) {
+          //  table.insert(document, "rowid");
+          //}
+          try {
+            table.insert(stream, "rowid"); //insert a batch  of document in 
stream
+          }catch(Exception e) {
 
 Review comment:
   space

----------------------------------------------------------------
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