vldpyatkov commented on code in PR #12096: URL: https://github.com/apache/ignite/pull/12096#discussion_r3000488174
########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/WindowNode.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.rel; + +import java.util.ArrayDeque; +import java.util.Comparator; +import java.util.Deque; +import java.util.function.Supplier; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; +import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler; +import org.apache.ignite.internal.processors.query.calcite.exec.exp.window.WindowPartition; +import org.apache.ignite.internal.util.typedef.F; + +/** Window support node */ +public class WindowNode<Row> extends MemoryTrackingNode<Row> implements SingleNode<Row>, Downstream<Row> { + /** */ + private final Comparator<Row> partCmp; + + /** */ + private final Supplier<WindowPartition<Row>> partitionFactory; + + /** */ + private final RowHandler.RowFactory<Row> rowFactory; + + /** */ + private WindowPartition<Row> partition; + + /** */ + private int requested; + + /** */ + private int waiting; + + /** */ + private Row prevRow; + + /** */ + private final Deque<Row> outBuf = new ArrayDeque<>(IN_BUFFER_SIZE); + + /** */ + public WindowNode( + ExecutionContext<Row> ctx, + RelDataType rowType, + Comparator<Row> partCmp, + Supplier<WindowPartition<Row>> partitionFactory, + RowHandler.RowFactory<Row> rowFactory + ) { + super(ctx, rowType, DFLT_ROW_OVERHEAD); + this.partCmp = partCmp; + this.partitionFactory = partitionFactory; + this.rowFactory = rowFactory; + } + + /** {@inheritDoc} */ + @Override public void request(int rowsCnt) throws Exception { + assert !F.isEmpty(sources()) && sources().size() == 1; + assert rowsCnt > 0; + + checkState(); + + requested = rowsCnt; + + doPush(); + + if (waiting == 0) { + waiting = IN_BUFFER_SIZE; + source().request(IN_BUFFER_SIZE); + } + else if (waiting < 0) + downstream().end(); Review Comment: Window node may end before all buffered rows are emitted ``` query III SELECT COUNT(*), MIN(cnt), MAX(cnt) FROM ( SELECT *, COUNT(*) OVER () AS cnt FROM TABLE(SYSTEM_RANGE(1, 2000)) ); ---- 2000 2000 2000 ``` -- 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]
