clintropolis commented on code in PR #13514: URL: https://github.com/apache/druid/pull/13514#discussion_r1042923453
########## processing/src/main/java/org/apache/druid/query/operator/window/WindowFrame.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.druid.query.operator.window; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +public class WindowFrame +{ + @SuppressWarnings("unused") + public enum PeerType Review Comment: I think this is worth a javadoc, it is described in some other places, such as `FramedOnHeapAggregatable`, but here would be nice too probably, is fine to defer until later when we have more support for this stuff though too ########## processing/src/main/java/org/apache/druid/query/operator/window/WindowFrame.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.druid.query.operator.window; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +public class WindowFrame Review Comment: heh, its a shame that "frame" really is the best name this; hopefully it wont be too confusing since it doesn't really have anything to do with the other one, https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/frame/Frame.java which should maybe be called DataFrame or... idk naming is just the worst 😅 ########## processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/DefaultFramedOnHeapAggregatable.java: ########## @@ -0,0 +1,581 @@ +/* + * 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.druid.query.rowsandcols.semantic; + +import org.apache.druid.java.util.common.UOE; +import org.apache.druid.query.aggregation.Aggregator; +import org.apache.druid.query.aggregation.AggregatorFactory; +import org.apache.druid.query.dimension.DimensionSpec; +import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector; +import org.apache.druid.query.operator.window.WindowFrame; +import org.apache.druid.query.rowsandcols.RowsAndColumns; +import org.apache.druid.query.rowsandcols.column.ConstantObjectColumn; +import org.apache.druid.query.rowsandcols.column.ObjectArrayColumn; +import org.apache.druid.segment.ColumnSelectorFactory; +import org.apache.druid.segment.ColumnValueSelector; +import org.apache.druid.segment.DimensionSelector; +import org.apache.druid.segment.ObjectColumnSelector; +import org.apache.druid.segment.column.ColumnCapabilities; +import org.apache.druid.segment.column.ColumnCapabilitiesImpl; + +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; + +public class DefaultFramedOnHeapAggregatable implements FramedOnHeapAggregatable +{ + private final AppendableRowsAndColumns rac; + + public DefaultFramedOnHeapAggregatable( + AppendableRowsAndColumns rac + ) + { + this.rac = rac; + } + + @Override + public RowsAndColumns aggregateAll( + WindowFrame frame, + AggregatorFactory[] aggFactories + ) + { + if (frame.isLowerUnbounded() && frame.isUpperUnbounded()) { + return computeUnboundedAggregates(aggFactories); + } + + + if (frame.getPeerType() == WindowFrame.PeerType.ROWS) { + if (frame.isLowerUnbounded()) { + return computeCumulativeAggregates(aggFactories, frame.getUpperOffset()); + } else if (frame.isUpperUnbounded()) { + return computeReverseCumulativeAggregates(aggFactories, frame.getLowerOffset()); + } else { + final int numRows = rac.numRows(); + int lowerOffset = frame.getLowerOffset(); + int upperOffset = frame.getUpperOffset(); + + if (numRows < lowerOffset + upperOffset + 1) { + // In this case, there are not enough rows to completely build up the full window aperture before it needs to + // also start contracting the aperture because of the upper offset. So we use a method that specifically + // handles checks for both expanding and reducing the aperture on every iteration. Review Comment: just wanted to say thanks for all the comments in this class, a lot going on here and it helps out :+1: -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
