oleg-zinovev commented on code in PR #12096: URL: https://github.com/apache/ignite/pull/12096#discussion_r3362381708
########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/window/RangeWindowPartitionFrame.java: ########## @@ -0,0 +1,260 @@ +/* + * 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.ignite.internal.processors.query.calcite.exec.exp.window; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.function.Function; +import com.google.common.collect.ImmutableList; +import org.apache.calcite.rel.RelCollation; +import org.apache.calcite.rel.RelFieldCollation; +import org.apache.calcite.rel.core.Window; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.rex.RexWindowBound; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.calcite.sql.type.SqlTypeFamily; +import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; +import org.apache.ignite.internal.processors.query.calcite.exec.exp.IgniteRexBuilder; +import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory; +import org.apache.ignite.internal.processors.query.calcite.util.Commons; + +/** {@link WindowFunctionFrame} for RANGE clause. */ +final class RangeWindowPartitionFrame<Row> extends WindowFunctionFrame<Row> { + + /** Comparator for determining a peer's index within a partition. */ + private final Comparator<Row> peerCmp; + + /** Returns the row that marks the start of the frame. */ + private final Function<Row, Row> lowerBound; + + /** */ + private final boolean cacheableLowerBound; + + /** Returns the row that marks the end of the frame. */ + private final Function<Row, Row> upperBound; + + /** */ + private final boolean cacheableUpperBound; + + /** Total number of peers in the current partition. */ + private int peerCount = -1; + + /** Cached peer idx for which the frame start row has been computed. */ + private int cachedStartPeerIdx = -1; + + /** Cached start row idx of frame. */ + private int cachedStartIdx; + + /** Cached peer idx for which the frame end row has been computed. */ + private int cachedEndPeerIdx = -1; + + /** Cached end row idx of frame. */ + private int cachedEndIdx; + + /** */ + RangeWindowPartitionFrame( + List<Row> buffer, + ExecutionContext<Row> ctx, + Comparator<Row> peerCmp, + Window.Group group, + RelDataType inputRowType + ) { + super(buffer); + this.peerCmp = peerCmp; + lowerBound = rangeBoundToProject(ctx, group.lowerBound, group.collation(), inputRowType); + cacheableLowerBound = isCacheableBound(group.lowerBound); + upperBound = rangeBoundToProject(ctx, group.upperBound, group.collation(), inputRowType); + cacheableUpperBound = isCacheableBound(group.upperBound); + } + + /** {@inheritDoc} */ + @Override protected int getFrameStart(Row row, int rowIdx, int peerIdx) { + if (cacheableLowerBound && cachedStartPeerIdx == peerIdx) Review Comment: @alex-plekhanov Nice catch, done -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
