[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-11 Thread ASF GitHub Bot (JIRA)

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

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

Github user asfgit closed the pull request at:

https://github.com/apache/drill/pull/371


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Jinfeng Ni
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-11 Thread ASF GitHub Bot (JIRA)

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

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

Github user amansinha100 commented on the pull request:

https://github.com/apache/drill/pull/371#issuecomment-183125598
  
Updated patch looks good to me.  +1


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52565738
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
 ---
@@ -485,12 +486,14 @@ public void populatePruningVector(ValueVector v, int 
index, SchemaPath column, S
 private EndpointByteMap byteMap;
 private int rowGroupIndex;
 private String root;
+private long rowCount;
 
 @JsonCreator
 public RowGroupInfo(@JsonProperty("path") String path, 
@JsonProperty("start") long start,
-@JsonProperty("length") long length, 
@JsonProperty("rowGroupIndex") int rowGroupIndex) {
+@JsonProperty("length") long length, 
@JsonProperty("rowGroupIndex") int rowGroupIndex, long rowCount) {
--- End diff --

Add the comment.

Pass -1 as rowCount in an unused method 
TestAffinityCalculator.buildRowGroups(). That is just to make code compile.   


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52564032
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,108 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
--- End diff --

Sounds good to me. Will add that API to GroupScan. 


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52563951
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractGroupScan.java
 ---
@@ -128,4 +128,12 @@ public int getOperatorType() {
   public List getPartitionColumns() {
 return Lists.newArrayList();
   }
+
+  /**
+   * By default, return null to indicate rowcount based prune is not 
supported. Each groupscan subclass should override, if it supports rowcount 
based prune.
+   */
+  public GroupScan applyLimit(long maxRecords) {
--- End diff --

Will do.


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52563924
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
 ---
@@ -791,6 +799,43 @@ public FileGroupScan clone(FileSelection selection) 
throws IOException {
   }
 
   @Override
+  public GroupScan applyLimit(long maxRecords) {
--- End diff --

I gave some thoughts about this optimization as well. Then, I realized that 
until we have some performance measurement, it's not very clear which way we 
want to have. For example, I'm not clear whether 1000 small parquet files is 
better than 1 large parquet files. 1000 files might have big metadata overhead 
than 1 large file (?). But 1000 small files might be better option, in case we 
do want to parallelize the execution.

I'll add some comment saying further optimization could be done in terms of 
how subset of files are chosen.
  


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user amansinha100 commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52563417
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
 ---
@@ -791,6 +799,43 @@ public FileGroupScan clone(FileSelection selection) 
throws IOException {
   }
 
   @Override
+  public GroupScan applyLimit(long maxRecords) {
--- End diff --

We do see small Parquet files (typically Hive generated via partitioning on 
date), although probably bigger than the typical LIMIT value.  I am ok with not 
doing this optimization for now. 


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jacques-n commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52560352
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
 ---
@@ -791,6 +799,43 @@ public FileGroupScan clone(FileSelection selection) 
throws IOException {
   }
 
   @Override
+  public GroupScan applyLimit(long maxRecords) {
--- End diff --

I was thinking about that as well. Theoretically, it would be best to do a 
sort on record count and then binary search to the row group that has the 
closest number greater than the requested amount (too small means multiple 
files, larger files require more metadata reading/parsing. However, it kind of 
seems like premature optimization to me. Are you seeing lots of people with 
many small Parquet files? That generally seems counter to the Parquet design.


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user amansinha100 commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52558347
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
 ---
@@ -791,6 +799,43 @@ public FileGroupScan clone(FileSelection selection) 
throws IOException {
   }
 
   @Override
+  public GroupScan applyLimit(long maxRecords) {
--- End diff --

Suppose the query has LIMIT 1000 and the first set of row groups considered 
by this rule have a small row count, then in the worst case there could be 1000 
files, whereas a single larger file may be sufficient to meet the limit.  Is 
that something we should consider here ?  


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user amansinha100 commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52557443
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,108 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
--- End diff --

It should not be necessary to check instanceof ParquetGroupScan since the 
rule is not actually casting to ParquetGroupScan.  Better to have another API  
such as GroupScan.supportsLimitPushdown() and override it in ParquetGroupScan.. 


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the over

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user amansinha100 commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52557262
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractGroupScan.java
 ---
@@ -128,4 +128,12 @@ public int getOperatorType() {
   public List getPartitionColumns() {
 return Lists.newArrayList();
   }
+
+  /**
+   * By default, return null to indicate rowcount based prune is not 
supported. Each groupscan subclass should override, if it supports rowcount 
based prune.
+   */
+  public GroupScan applyLimit(long maxRecords) {
--- End diff --

Add Override and JsonIgnore ?


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jacques-n commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52540911
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
 ---
@@ -485,12 +486,14 @@ public void populatePruningVector(ValueVector v, int 
index, SchemaPath column, S
 private EndpointByteMap byteMap;
 private int rowGroupIndex;
 private String root;
+private long rowCount;
 
 @JsonCreator
 public RowGroupInfo(@JsonProperty("path") String path, 
@JsonProperty("start") long start,
-@JsonProperty("length") long length, 
@JsonProperty("rowGroupIndex") int rowGroupIndex) {
+@JsonProperty("length") long length, 
@JsonProperty("rowGroupIndex") int rowGroupIndex, long rowCount) {
--- End diff --

Can you add a comment that rowCount =-1 means to include all rows? 
Otherwise, LGTM +1


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52539112
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

@jacques-n , I made change based on your review comments. Could you please 
take another look? Thanks.



> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", w

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52498045
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

Agreed. We need maintain GroupScan as immutable. Thanks for the suggestion!



> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jacques-n commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52494612
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

If we don't treat GroupScan immutable, we're going to have an issue with 
changing other plan alternatives unintentionally. 


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * f

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jacques-n commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52494516
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

Oh wait, GroupScan should be treated as immutable. I shouldn't have 
suggested that interface.

how about:

GroupScan applyLimit(int maxRecords)

and return new GroupScan in case of limit application. Otherwise, null.


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> 

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jinfengni commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52476961
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

I can change to use applyLimit(int maxRecords).  This method will modify 
the internal state of the groupscan and return true, if the limit is applied. 
Otherwise, leave the groupscan instance unchanged and return false.  


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jacques-n commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52465362
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

How about:

boolean applyLimit(int maxRecords)

Returns whether the limit was applied. Default implementation in 
AbstractGroupScan is return false.


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-10 Thread ASF GitHub Bot (JIRA)

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

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

Github user jacques-n commented on a diff in the pull request:

https://github.com/apache/drill/pull/371#discussion_r52455844
  
--- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillPushLimitToScanRule.java
 ---
@@ -0,0 +1,107 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.planner.logical.partition.PruneScanRule;
+import org.apache.drill.exec.store.parquet.ParquetGroupScan;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DrillPushLimitToScanRule extends RelOptRule {
+  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillPushLimitToScanRule.class);
+
+  private DrillPushLimitToScanRule(RelOptRuleOperand operand, String 
description) {
+super(operand, description);
+  }
+
+  public static DrillPushLimitToScanRule LIMIT_ON_SCAN = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.any(DrillScanRel.class)), "DrillPushLimitToScanRule_LimitOnScan") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(1);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+DrillLimitRel limitRel = call.rel(0);
+DrillScanRel scanRel = call.rel(1);
+doOnMatch(call, limitRel, scanRel, null);
+}
+  };
+
+  public static DrillPushLimitToScanRule LIMIT_ON_PROJECT = new 
DrillPushLimitToScanRule(
+  RelOptHelper.some(DrillLimitRel.class, 
RelOptHelper.some(DrillProjectRel.class, 
RelOptHelper.any(DrillScanRel.class))), 
"DrillPushLimitToScanRule_LimitOnProject") {
+@Override
+public boolean matches(RelOptRuleCall call) {
+  DrillScanRel scanRel = call.rel(2);
+  return scanRel.getGroupScan() instanceof ParquetGroupScan; // It 
only applies to Parquet.
+}
+
+@Override
+public void onMatch(RelOptRuleCall call) {
+  DrillLimitRel limitRel = call.rel(0);
+  DrillProjectRel projectRel = call.rel(1);
+  DrillScanRel scanRel = call.rel(2);
+  doOnMatch(call, limitRel, scanRel, projectRel);
+}
+  };
+
+
+  protected void doOnMatch(RelOptRuleCall call, DrillLimitRel limitRel, 
DrillScanRel scanRel, DrillProjectRel projectRel){
+try {
+  final int rowCountRequested = (int) limitRel.getRows();
+
+  final Pair  newGroupScanPair = 
ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()),
 rowCountRequested);
--- End diff --

It seems like we can move this functionality into a method on groupscan and 
then make it generic with only parquet group scan implementing it


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would u

[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-09 Thread Jinfeng Ni (JIRA)

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

Jinfeng Ni commented on DRILL-4363:
---

[~amansinha100], could you please review the PR for DRILL-4363? 

Thanks!



> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Aman Sinha
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-09 Thread Jinfeng Ni (JIRA)

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

Jinfeng Ni commented on DRILL-4363:
---

Did some performance comparison with two datasets:

1. Dataset containing 300 parquet files, with total 46M rows.  Each parquet 
file has about 2000 columns. That's for wide table use case.
Without the patch,  the query will crash drillbits in the cluster, since the 
query is executed in multi minor fragments for Scan operator, and each minor 
scan fragment will use around 500M ~ 1GB memory. 

With the patch, the query completed in under 30 seconds, with warm cache.

2. Dataset containing 115 small parquet files. The file was created from TPCH 
lineitem table.

Without patch,  
{code}
select * from dfs.`/Users/jni/work/data/tpch-sf10/lineitem115k` limit 1;
1 row selected (34.165 seconds)
{code}

With patch
{code}
select * from dfs.`/Users/jni/work/data/tpch-sf10/lineitem115k` limit 1;

1 row selected (14.021 seconds)
{code}

Basically, it reduce from 34 seconds to 14 seconds with warm cache. 


> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Jinfeng Ni
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-4363) Apply row count based pruning for parquet table in LIMIT n query

2016-02-09 Thread ASF GitHub Bot (JIRA)

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

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

GitHub user jinfengni opened a pull request:

https://github.com/apache/drill/pull/371

DRILL-4363: Row count based pruning for parquet table used in Limit n…

… query.

Modify two existint unit testcase:
1) TestPartitionFilter.testMainQueryFalseCondition(): rowCount pruning 
applied after false condition is transformed into LIMIT 0
2) TestLimitWithExchanges.testPushLimitPastUnionExchange(): modify the 
testcase to use Json source, so that it does not mix with PushLimitIntoScanRule.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/jinfengni/incubator-drill DRILL-4363

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/drill/pull/371.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #371


commit a84d61fe2b820fe8395e73347dfb0e2986ed9dd0
Author: Jinfeng Ni 
Date:   2016-02-02T23:31:47Z

DRILL-4363: Row count based pruning for parquet table used in Limit n query.

Modify two existint unit testcase:
1) TestPartitionFilter.testMainQueryFalseCondition(): rowCount pruning 
applied after false condition is transformed into LIMIT 0
2) TestLimitWithExchanges.testPushLimitPastUnionExchange(): modify the 
testcase to use Json source, so that it does not mix with PushLimitIntoScanRule.




> Apply row count based pruning for parquet table in LIMIT n query
> 
>
> Key: DRILL-4363
> URL: https://issues.apache.org/jira/browse/DRILL-4363
> Project: Apache Drill
>  Issue Type: Improvement
>Reporter: Jinfeng Ni
>Assignee: Jinfeng Ni
> Fix For: 1.6.0
>
>
> In interactive data exploration use case, one common and probably first query 
> that users would use is " SELECT * from table LIMIT n", where n is a small 
> number. Such query will give user idea about the columns in the table.
> Normally, user would expect such query should be completed in very short 
> time, since it's just asking for small amount of rows, without any 
> sort/aggregation.
> When table is small, there is no big problem for Drill. However, when the 
> table is extremely large,  Drill's response time is not as fast as what user 
> would expect.
> In case of parquet table, it seems that query planner could do a bit better 
> job : by applying row count based pruning for such LIMIT n query.  The 
> pruning is kind of similar to what partition pruning will do, except that it 
> uses row count, in stead of partition column values. Since row count is 
> available in parquet table, it's possible to do such pruning.
> The benefit of doing such pruning is clear: 1) for small "n",  such pruning 
> would end up with a few parquet files, in stead of thousands, or millions of 
> files to scan. 2) execution probably does not have to put scan into multiple 
> minor fragments and start reading the files concurrently, which will cause 
> big IO overhead. 3) the physical plan itself is much smaller, since it does 
> not include the long list of parquet files, reduce rpc cost of sending the 
> fragment plans to multiple drillbits, and the overhead to 
> serialize/deserialize the fragment plans.
>  
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)