imply-cheddar commented on code in PR #13458:
URL: https://github.com/apache/druid/pull/13458#discussion_r1040156122


##########
processing/src/main/java/org/apache/druid/query/rowsandcols/DefaultOnHeapAggregatable.java:
##########
@@ -0,0 +1,271 @@
+/*
+ * 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;
+
+import org.apache.druid.java.util.common.ISE;
+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.rowsandcols.column.Column;
+import org.apache.druid.query.rowsandcols.column.ColumnAccessor;
+import org.apache.druid.segment.BaseSingleValueDimensionSelector;
+import org.apache.druid.segment.ColumnSelectorFactory;
+import org.apache.druid.segment.ColumnValueSelector;
+import org.apache.druid.segment.DimensionSelector;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ColumnCapabilitiesImpl;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.serde.ComplexMetricSerde;
+import org.apache.druid.segment.serde.ComplexMetrics;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
+
+public class DefaultOnHeapAggregatable implements OnHeapAggregatable, 
OnHeapCumulativeAggregatable
+{
+  private final RowsAndColumns rac;
+
+  public DefaultOnHeapAggregatable(
+      RowsAndColumns rac
+  )
+  {
+    this.rac = rac;
+  }
+
+  @Override
+  public ArrayList<Object> aggregateAll(
+      List<AggregatorFactory> aggFactories
+  )
+  {
+    Aggregator[] aggs = new Aggregator[aggFactories.size()];
+
+    AtomicInteger currRow = new AtomicInteger(0);
+    int index = 0;
+    for (AggregatorFactory aggFactory : aggFactories) {
+      aggs[index++] = aggFactory.factorize(new 
ColumnAccessorBasedColumnSelectorFactory(currRow));
+    }
+
+    int numRows = rac.numRows();
+    int rowId = currRow.get();
+    while (rowId < numRows) {
+      for (Aggregator agg : aggs) {
+        agg.aggregate();
+      }
+      rowId = currRow.incrementAndGet();
+    }
+
+    ArrayList<Object> retVal = new ArrayList<>(aggs.length);
+    for (Aggregator agg : aggs) {
+      retVal.add(agg.get());
+    }
+    return retVal;
+  }
+
+  @Override
+  public ArrayList<Object[]> aggregateCumulative(List<AggregatorFactory> 
aggFactories)
+  {
+    Aggregator[] aggs = new Aggregator[aggFactories.size()];
+    ArrayList<Object[]> retVal = new ArrayList<>(aggFactories.size());
+
+    int numRows = rac.numRows();
+    AtomicInteger currRow = new AtomicInteger(0);
+    int index = 0;
+    for (AggregatorFactory aggFactory : aggFactories) {
+      aggs[index++] = aggFactory.factorize(new 
ColumnAccessorBasedColumnSelectorFactory(currRow));
+      retVal.add(new Object[numRows]);
+    }
+
+    int rowId = currRow.get();
+    while (rowId < numRows) {
+      for (int i = 0; i < aggs.length; ++i) {
+        aggs[i].aggregate();

Review Comment:
   Adding methods to `AggregatorFactory`  must be done with care, that's an 
interface that is the most likely to be implemented externally.
   
   Either way, the aggregate-then-get algorithm implemented here is technically 
incorrect (sketch aggs will update the object that they return from `get()`), 
so I have a follow on PR that does window framing properly and actually 
implements things correctly.



##########
processing/src/main/java/org/apache/druid/query/rowsandcols/DefaultOnHeapAggregatable.java:
##########
@@ -0,0 +1,271 @@
+/*
+ * 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;
+
+import org.apache.druid.java.util.common.ISE;
+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.rowsandcols.column.Column;
+import org.apache.druid.query.rowsandcols.column.ColumnAccessor;
+import org.apache.druid.segment.BaseSingleValueDimensionSelector;
+import org.apache.druid.segment.ColumnSelectorFactory;
+import org.apache.druid.segment.ColumnValueSelector;
+import org.apache.druid.segment.DimensionSelector;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ColumnCapabilitiesImpl;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.serde.ComplexMetricSerde;
+import org.apache.druid.segment.serde.ComplexMetrics;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
+
+public class DefaultOnHeapAggregatable implements OnHeapAggregatable, 
OnHeapCumulativeAggregatable
+{
+  private final RowsAndColumns rac;
+
+  public DefaultOnHeapAggregatable(
+      RowsAndColumns rac
+  )
+  {
+    this.rac = rac;
+  }
+
+  @Override
+  public ArrayList<Object> aggregateAll(
+      List<AggregatorFactory> aggFactories
+  )
+  {
+    Aggregator[] aggs = new Aggregator[aggFactories.size()];
+
+    AtomicInteger currRow = new AtomicInteger(0);
+    int index = 0;
+    for (AggregatorFactory aggFactory : aggFactories) {
+      aggs[index++] = aggFactory.factorize(new 
ColumnAccessorBasedColumnSelectorFactory(currRow));
+    }
+
+    int numRows = rac.numRows();
+    int rowId = currRow.get();
+    while (rowId < numRows) {
+      for (Aggregator agg : aggs) {
+        agg.aggregate();
+      }
+      rowId = currRow.incrementAndGet();
+    }
+
+    ArrayList<Object> retVal = new ArrayList<>(aggs.length);
+    for (Aggregator agg : aggs) {
+      retVal.add(agg.get());
+    }
+    return retVal;
+  }
+
+  @Override
+  public ArrayList<Object[]> aggregateCumulative(List<AggregatorFactory> 
aggFactories)
+  {
+    Aggregator[] aggs = new Aggregator[aggFactories.size()];
+    ArrayList<Object[]> retVal = new ArrayList<>(aggFactories.size());
+
+    int numRows = rac.numRows();
+    AtomicInteger currRow = new AtomicInteger(0);
+    int index = 0;
+    for (AggregatorFactory aggFactory : aggFactories) {
+      aggs[index++] = aggFactory.factorize(new 
ColumnAccessorBasedColumnSelectorFactory(currRow));
+      retVal.add(new Object[numRows]);
+    }
+
+    int rowId = currRow.get();
+    while (rowId < numRows) {
+      for (int i = 0; i < aggs.length; ++i) {
+        aggs[i].aggregate();
+        retVal.get(i)[rowId] = aggs[i].get();
+      }
+      rowId = currRow.incrementAndGet();
+    }
+
+    return retVal;

Review Comment:
   follow-on PR



-- 
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]

Reply via email to