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

    https://github.com/apache/drill/pull/416#discussion_r55455592
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ConvertCountToDirectScan.java
 ---
    @@ -117,6 +117,24 @@ public void onMatch(RelOptRuleCall call) {
           } else if (aggCall.getArgList().size() == 1) {
           // count(columnName) ==> Agg ( Scan )) ==> columnValueCount
             int index = aggCall.getArgList().get(0);
    +
    +        if (proj != null) {
    +          // project in the middle of Agg and Scan : Only when input of 
AggCall is a RexInputRef in Project, we find the index of Scan's field.
    +          // For instance,
    +          // Agg - count($0)
    +          //  \
    +          //  Proj - Exp={$1}
    +          //    \
    +          //   Scan (col1, col2).
    +          // return count of "col2" in Scan's metadata, if found.
    +
    +          if (proj.getProjects().get(index) instanceof RexInputRef) {
    +            index = ((RexInputRef) 
proj.getProjects().get(index)).getIndex();
    --- End diff --
    
    might be good to add a test case for that just in case calcite changes this 
behavior in future.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to