@Override
  public boolean matches(RelOptRuleCall call) {
    if (Bug.CALCITE_5985_FIXED) {
      throw new IllegalStateException("Class is redundant after fix is merged into Calcite");
    }

    final Filter filterRel = call.rel(0);
    final HiveTableFunctionScan tfs = call.rel(1);

    RexNode condition = filterRel.getCondition();
    if (!HiveCalciteUtil.isDeterministic(condition)) {
      return false;
    }

    // The TableFunctionScan is always created such that all the input RelNode
    // fields are present in its RelNode.  If a Filter has an InputRef that is
    // greater then the number of the RelNode below the TableFunctionScan, that
    // means it was a field created by the TableFunctionScan and thus the Filter
    // cannot be pushed through.
    //
    // We check for each individual conjunction (breaking it up by top level 'and'
    // conditions).
    for (RexNode ce : RelOptUtil.conjunctions(filterRel.getCondition())) {
      if (canBePushed(HiveCalciteUtil.getInputRefs(ce), tfs)) {
        return true;
      }
    }
    return false;
  }
Rule to transpose Filter and TableFunctionScan RelNodes

We cannot use Calcite's FilterTableFunctionTransposeRule because that rule
uses LogicalFilter and LogicalTableFunctionScan.  We should remove this
class when CALCITE-5985 is fixed (and remove the CALCITE_5985_FIXED entry
in Bug.java)
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveFilterTableFunctionTransposeRule.java