danny0405 commented on a change in pull request #10224: [FLINK-14716][table-planner-blink] Cooperate computed column with push down rules URL: https://github.com/apache/flink/pull/10224#discussion_r347190503
########## File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/schema/FlinkPreparingTableBase.java ########## @@ -0,0 +1,316 @@ +/* + * 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.planner.plan.schema; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.planner.plan.stats.FlinkStatistic; +import org.apache.flink.table.sources.TableSource; + +import org.apache.flink.shaded.guava18.com.google.common.base.Strings; +import org.apache.flink.shaded.guava18.com.google.common.collect.ImmutableList; +import org.apache.flink.shaded.guava18.com.google.common.collect.ImmutableSet; + +import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.plan.RelOptSchema; +import org.apache.calcite.plan.RelOptTable; +import org.apache.calcite.plan.RelOptTable.ToRelContext; +import org.apache.calcite.prepare.Prepare; +import org.apache.calcite.rel.RelCollation; +import org.apache.calcite.rel.RelDistribution; +import org.apache.calcite.rel.RelFieldCollation; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelReferentialConstraint; +import org.apache.calcite.rel.logical.LogicalTableScan; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.schema.Table; +import org.apache.calcite.sql.SqlAccessType; +import org.apache.calcite.sql.validate.SqlModality; +import org.apache.calcite.sql.validate.SqlMonotonicity; +import org.apache.calcite.sql2rel.InitializerContext; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.calcite.util.Util; + +import javax.annotation.Nullable; + +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +/** A Flink {@link org.apache.calcite.prepare.Prepare.AbstractPreparingTable} implementation + * for the purposes of the sql-to-rel conversion and planner. + */ +@Internal +public abstract class FlinkPreparingTableBase extends Prepare.AbstractPreparingTable { + //~ Static fields/initializers --------------------------------------------- + + // Default value of rowCount if there is no available stats. + // Sets a bigger default value to avoid broadcast join. + private static final double DEFAULT_ROWCOUNT = 1E8; + + //~ Instance fields -------------------------------------------------------- + + @Nullable + protected final RelOptSchema relOptSchema; + protected final RelDataType rowType; + protected final List<String> names; + + protected FlinkStatistic statistic; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a {@link org.apache.calcite.prepare.Prepare.AbstractPreparingTable} instance. + * + * @param relOptSchema The RelOptSchema that this table comes from + * @param rowType The table row type + * @param names The table qualified name + * @param statistic The table statistics + */ + public FlinkPreparingTableBase( + @Nullable RelOptSchema relOptSchema, + RelDataType rowType, + Iterable<String> names, + FlinkStatistic statistic) { + this.relOptSchema = relOptSchema; + this.rowType = Objects.requireNonNull(rowType); + this.names = Objects.requireNonNull(ImmutableList.copyOf(names)); + this.statistic = Objects.requireNonNull(statistic); + } + + //~ Methods ---------------------------------------------------------------- + + /** Returns the statistic of this table. */ + public FlinkStatistic getStatistic() { + return this.statistic; + } + + /** Returns a copy of this table with a given {@link FlinkStatistic}. */ + public abstract FlinkPreparingTableBase copy(FlinkStatistic statistic); + + /** + * Returns the table path in the {@link RelOptSchema}. + * Different with {@link #getQualifiedName()}, the latter is mainly used for table digest. + */ + public List<String> getNames() { + return names; + } + + @Override + public List<String> getQualifiedName() { + return names; + } + + @Override + public RelNode toRel(ToRelContext context) { Review comment: We could have a default implementation, except `TableSourceTable`and `QueryOperationCatalogViewTable`, all the other tables can have this default logic. ---------------------------------------------------------------- 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
