You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by jinfengni <gi...@git.apache.org> on 2016/02/09 22:59:09 UTC

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

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 <jn...@apache.org>
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.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on the pull request:

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jacques-n <gi...@git.apache.org>.
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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jacques-n <gi...@git.apache.org>.
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<GroupScan, Boolean>  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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by amansinha100 <gi...@git.apache.org>.
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 ?  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by amansinha100 <gi...@git.apache.org>.
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<SchemaPath> 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 ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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.   


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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.
      


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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<GroupScan, Boolean>  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.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by amansinha100 <gi...@git.apache.org>.
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.. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jacques-n <gi...@git.apache.org>.
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<GroupScan, Boolean>  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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jacques-n <gi...@git.apache.org>.
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<GroupScan, Boolean>  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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jacques-n <gi...@git.apache.org>.
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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by amansinha100 <gi...@git.apache.org>.
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. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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<GroupScan, Boolean>  newGroupScanPair = ParquetGroupScan.filterParquetScanByLimit((ParquetGroupScan)(scanRel.getGroupScan()), rowCountRequested);
    --- End diff --
    
    Agreed. We need maintain GroupScan as immutable. Thanks for the suggestion!



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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<GroupScan, Boolean>  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.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jacques-n <gi...@git.apache.org>.
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<GroupScan, Boolean>  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. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] drill pull request: DRILL-4363: Row count based pruning for parque...

Posted by jinfengni <gi...@git.apache.org>.
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<SchemaPath> 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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---