JingsongLi commented on a change in pull request #8109: [FLINK-12017][table-planner-blink] Support translation from Rank/Deduplicate to StreamTransformation URL: https://github.com/apache/flink/pull/8109#discussion_r273778026
########## File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/rank/AbstractRankFunction.java ########## @@ -0,0 +1,309 @@ +/* + * 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.runtime.rank; + +import org.apache.flink.api.common.state.ValueState; +import org.apache.flink.api.common.state.ValueStateDescriptor; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.functions.KeySelector; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.metrics.Counter; +import org.apache.flink.metrics.Gauge; +import org.apache.flink.streaming.api.operators.KeyContext; +import org.apache.flink.table.dataformat.BaseRow; +import org.apache.flink.table.dataformat.GenericRow; +import org.apache.flink.table.dataformat.JoinedRow; +import org.apache.flink.table.dataformat.util.BaseRowUtil; +import org.apache.flink.table.generated.GeneratedRecordComparator; +import org.apache.flink.table.generated.GeneratedRecordEqualiser; +import org.apache.flink.table.generated.RecordEqualiser; +import org.apache.flink.table.runtime.functions.KeyedProcessFunctionWithCleanupState; +import org.apache.flink.table.typeutils.BaseRowTypeInfo; +import org.apache.flink.util.Collector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.Comparator; +import java.util.Map; + +/** + * Base class for Rank Function. + */ +public abstract class AbstractRankFunction extends KeyedProcessFunctionWithCleanupState<BaseRow, BaseRow, BaseRow> { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractRankFunction.class); + + // we set default topN size to 100 + private static final long DEFAULT_TOPN_SIZE = 100; + + private final RankRange rankRange; + + /** + * The util to compare two BaseRow equals to each other. + * As different BaseRow can't be equals directly, we use a code generated util to handle this. + */ + private final GeneratedRecordEqualiser generatedEqualiser; + protected RecordEqualiser equaliser; + + /** + * The util to compare two sortKey equals to each other. + */ + private final GeneratedRecordComparator generatedSortKeyComparator; + protected Comparator<BaseRow> sortKeyComparator; + + private final boolean generateRetraction; + protected final boolean isRowNumberAppend; + protected final BaseRowTypeInfo inputRowType; + protected final KeySelector<BaseRow, BaseRow> sortKeySelector; + + protected KeyContext keyContext; + private boolean isConstantRankEnd; + private long rankStart = -1; + protected long rankEnd = -1; + private int rankEndIndex; + private ValueState<Long> rankEndState; + private Counter invalidCounter; + private JoinedRow outputRow; + + // metrics + protected long hitCount = 0L; + protected long requestCount = 0L; + + AbstractRankFunction(long minRetentionTime, long maxRetentionTime, BaseRowTypeInfo inputRowType, Review comment: use inputArity outputArity instead of inputRowType and outputRowType ---------------------------------------------------------------- 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
