[ https://issues.apache.org/jira/browse/CALCITE-7687 ]


    Etienne Pelissier deleted comment on CALCITE-7687:
    --------------------------------------------

was (Author: JIRAUSER313108):
Test, for {{getDistinctRowCount}}:
{code:java}
  // Same fixture as above. Selectivity.Handler and DistinctRowCount.Handler 
both
  // declare getDef(), so one class cannot implement both.
  private static class DistinctRowCountByColumnTable extends AbstractTable
      implements BuiltInMetadata.DistinctRowCount.Handler {
    @Nullable RexNode receivedPredicate;
    @Nullable ImmutableBitSet receivedGroupKey;

    @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      return abcRowType(typeFactory);
    }

    @Override public @Nullable Double getDistinctRowCount(RelNode r,
        RelMetadataQuery mq, ImmutableBitSet groupKey,
        @Nullable RexNode predicate) {
      receivedGroupKey = groupKey;
      receivedPredicate = predicate;
      return 1000.0;
    }
  }

  // The group key is converted into input space by RelMdUtil#setAggChildKeys 
and
  // arrives as {1}; the predicate beside it is not converted. This handler's
  // pushability bitmap is already range(getGroupCount()), so it isolates the
  // missing conversion on its own.
  @Test void testDistinctRowCountAggregateConvertsPredicateToInputFields() {
    final DistinctRowCountByColumnTable table = new 
DistinctRowCountByColumnTable();
    final RelNode agg = aggregateGroupingOnFields1And2(table);
    final RelMetadataQuery mq = agg.getCluster().getMetadataQuery();

    // Group key is output $0 ("b", input $1); predicate is on output $1 ("c", 
input $2).
    mq.getDistinctRowCount(agg, ImmutableBitSet.of(0), isNullOn(agg, 1));
    assertThat(table.receivedGroupKey, hasToString("{1}"));
    assertThat(table.receivedPredicate, hasToString("IS NULL($2)"));
  }
{code}

Fails with:
{noformat}
java.lang.AssertionError:
Expected: with toString() "IS NULL($2)"
     but: toString() was "IS NULL($1)"
        at 
org.apache.calcite.test.RelMetadataTest.testDistinctRowCountAggregateConvertsPredicateToInputFields(RelMetadataTest.java:1899)
{noformat}


> RelMdSelectivity and RelMdDistinctRowCount for Aggregate can propagate a 
> predicate with wrong references
> --------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7687
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7687
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Etienne Pelissier
>            Assignee: Etienne Pelissier
>            Priority: Minor
>              Labels: in-progress
>
> Predicate pushability is assessed without taking into account column 
> remapping from the aggregate.
> Additionally, predicates are pushed without being rewritten as need be.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to