godfreyhe commented on a change in pull request #7903: [FLINK-11822][table-planner-blink] Introduce Flink metadata handlers URL: https://github.com/apache/flink/pull/7903#discussion_r278484734
########## File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/metadata/AggCallSelectivityEstimator.scala ########## @@ -0,0 +1,447 @@ +/* + * 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.flink.table.plan.metadata + +import org.apache.flink.table.JDouble +import org.apache.flink.table.plan.nodes.physical.batch.BatchExecGroupAggregateBase +import org.apache.flink.table.plan.stats._ +import org.apache.flink.table.plan.util.AggregateUtil + +import org.apache.calcite.plan.RelOptPredicateList +import org.apache.calcite.rel.RelNode +import org.apache.calcite.rel.core.{Aggregate, AggregateCall} +import org.apache.calcite.rel.metadata.RelMdUtil +import org.apache.calcite.rex._ +import org.apache.calcite.sql.fun.SqlStdOperatorTable._ +import org.apache.calcite.sql.{SqlKind, SqlOperator} + +import scala.collection.JavaConversions._ + +/** + * Estimates selectivity of rows meeting a filter predicate on an Aggregate. + * + * A filter predicate on an Aggregate may contain two parts: + * one is on group by columns, another is on aggregate call's result. + * The first part is handled by [[SelectivityEstimator]], + * the second part is handled by this Estimator. + * + * @param agg aggregate node + * @param mq Metadata query + */ +class AggCallSelectivityEstimator(agg: RelNode, mq: FlinkRelMetadataQuery) Review comment: `SelectivityEstimator` uses general algorithm, and it does not care about the predicate is on an agg-call or not. However, `AggCallSelectivityEstimator` only estimates predicate on an agg-call. So there are many difference in their logic. the comments in `AggCallSelectivityEstimator` could be updated: `Estimates selectivity of rows meeting an agg-call predicate on an Aggregate.` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
