cheddar commented on code in PR #13458: URL: https://github.com/apache/druid/pull/13458#discussion_r1040518646
########## processing/src/main/java/org/apache/druid/query/operator/window/WindowAggregateProcessor.java: ########## @@ -0,0 +1,131 @@ +/* + * 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 org.apache.druid.query.aggregation.AggregatorFactory; +import org.apache.druid.query.rowsandcols.AppendableRowsAndColumns; +import org.apache.druid.query.rowsandcols.DefaultOnHeapAggregatable; +import org.apache.druid.query.rowsandcols.OnHeapAggregatable; +import org.apache.druid.query.rowsandcols.OnHeapCumulativeAggregatable; +import org.apache.druid.query.rowsandcols.RowsAndColumns; +import org.apache.druid.query.rowsandcols.column.ConstantObjectColumn; +import org.apache.druid.query.rowsandcols.column.ObjectArrayColumn; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class WindowAggregateProcessor implements Processor +{ + @Nullable + private static <T> List<T> emptyToNull(List<T> list) + { + if (list == null || list.isEmpty()) { + return null; + } else { + return list; + } + } + + private final List<AggregatorFactory> aggregations; + private final List<AggregatorFactory> cumulativeAggregations; + + @JsonCreator + public WindowAggregateProcessor( + @JsonProperty("aggregations") List<AggregatorFactory> aggregations, + @JsonProperty("cumulativeAggregations") List<AggregatorFactory> cumulativeAggregations + ) + { + this.aggregations = emptyToNull(aggregations); + this.cumulativeAggregations = emptyToNull(cumulativeAggregations); + } + + @JsonProperty("aggregations") + public List<AggregatorFactory> getAggregations() + { + return aggregations; + } + + @JsonProperty("cumulativeAggregations") + public List<AggregatorFactory> getCumulativeAggregations() + { + return cumulativeAggregations; + } + + @Override + public RowsAndColumns process(RowsAndColumns inputPartition) + { + AppendableRowsAndColumns retVal = RowsAndColumns.expectAppendable(inputPartition); + + if (aggregations != null) { + OnHeapAggregatable aggregatable = inputPartition.as(OnHeapAggregatable.class); Review Comment: This is a common pattern for all of the "semantic interfaces" actually. For all of them, there is a default implementation that can be fallen back to (the default is generally implemented in terms of "find necessary columns, use their ColumnAccessor and do logic), but we always ask the RowsAndColumns first so that it can offer a more optimal implementation if it wants. This PR doesn't yet have more optimal implementations, but I expect that I will have to create some to truly make the SortOperator that I will need work in any sort of meaningful manner. So, until that PR, this will look very barren and then suddenly it will either become super magical or make sense or both. -- 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]
