Jackie-Jiang commented on code in PR #11822:
URL: https://github.com/apache/pinot/pull/11822#discussion_r1367561418
##########
pinot-core/src/main/java/org/apache/pinot/core/operator/blocks/results/AggregationResultsBlock.java:
##########
@@ -158,6 +161,13 @@ private void setIntermediateResult(DataTableBuilder
dataTableBuilder, ColumnData
dataTableBuilder.setColumn(index, (double) result);
break;
case OBJECT:
+ case BOOLEAN_ARRAY:
Review Comment:
We shouldn't need them. Intermediate result can not be `ARRAY`
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/array/ArrayAggFunction.java:
##########
@@ -0,0 +1,141 @@
+/**
+ * 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.pinot.core.query.aggregation.function.array;
+
+import java.util.Map;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.ObjectAggregationResultHolder;
+import
org.apache.pinot.core.query.aggregation.function.BaseSingleInputAggregationFunction;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import
org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.roaringbitmap.RoaringBitmap;
+
+
+public abstract class ArrayAggFunction<I, F extends Comparable> extends
BaseSingleInputAggregationFunction<I, F> {
Review Comment:
Rename to `BaseArrayAggAggregationFunction`
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/array/ArrayAggBaseDoubleFunction.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.pinot.core.query.aggregation.function.array;
+
+import it.unimi.dsi.fastutil.doubles.AbstractDoubleCollection;
+import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.roaringbitmap.RoaringBitmap;
+
+
+public abstract class ArrayAggBaseDoubleFunction<I extends
AbstractDoubleCollection>
Review Comment:
To keep class name consistent, rename it to
`BaseArrayAggDoubleAggregationFunction`, same for other classes
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/array/ArrayAggFunction.java:
##########
@@ -0,0 +1,141 @@
+/**
+ * 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.pinot.core.query.aggregation.function.array;
+
+import java.util.Map;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.ObjectAggregationResultHolder;
+import
org.apache.pinot.core.query.aggregation.function.BaseSingleInputAggregationFunction;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import
org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.roaringbitmap.RoaringBitmap;
+
+
+public abstract class ArrayAggFunction<I, F extends Comparable> extends
BaseSingleInputAggregationFunction<I, F> {
+
+ protected final boolean _nullHandlingEnabled;
+ private final DataSchema.ColumnDataType _resultColumnType;
+
+ public ArrayAggFunction(ExpressionContext expression, FieldSpec.DataType
dataType, boolean nullHandlingEnabled) {
+ super(expression);
+ _nullHandlingEnabled = nullHandlingEnabled;
+ _resultColumnType = DataSchema.ColumnDataType.fromDataTypeMV(dataType);
+ }
+
+ @Override
+ public AggregationFunctionType getType() {
+ return AggregationFunctionType.ARRAYAGG;
+ }
+
+ @Override
+ public AggregationResultHolder createAggregationResultHolder() {
+ return new ObjectAggregationResultHolder();
+ }
+
+ @Override
+ public GroupByResultHolder createGroupByResultHolder(int initialCapacity,
int maxCapacity) {
+ return new ObjectGroupByResultHolder(initialCapacity, maxCapacity);
+ }
+
+ @Override
+ public DataSchema.ColumnDataType getIntermediateResultColumnType() {
+ return _resultColumnType;
Review Comment:
This should be `OBJECT`
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionFactory.java:
##########
@@ -226,6 +237,58 @@ public static AggregationFunction
getAggregationFunction(FunctionContext functio
throw new IllegalArgumentException("Unsupported data type for
FIRST_WITH_TIME: " + dataType);
}
}
+ case ARRAYAGG: {
+ Preconditions.checkArgument(numArguments >= 2,
+ "ARRAY_AGG expects 2 or 3 arguments, got: %s. The function can
be used as "
+ + "arrayAgg(dataColumn, 'dataType', ['isDistinct'])",
numArguments);
+ ExpressionContext dataTypeExp = arguments.get(1);
+ Preconditions.checkArgument(dataTypeExp.getType() ==
ExpressionContext.Type.LITERAL,
+ "ARRAY_AGG expects the 2nd argument to be literal, got: %s.
The function can be used as "
+ + "arrayAgg(dataColumn, 'dataType', ['isDistinct'])",
dataTypeExp.getType());
+ DataType dataType =
DataType.valueOf(dataTypeExp.getLiteral().getStringValue().toUpperCase());
+ boolean isDistinct = false;
+ if (numArguments == 3) {
+ ExpressionContext isDistinctExp = arguments.get(2);
+ Preconditions.checkArgument(isDistinctExp.getType() ==
ExpressionContext.Type.LITERAL,
+ "ARRAY_AGG expects the 3rd argument to be literal, got: %s.
The function can be used as "
+ + "arrayAgg(dataColumn, 'dataType', ['isDistinct'])",
isDistinctExp.getType());
+ isDistinct =
BooleanUtils.toBoolean(isDistinctExp.getLiteral().getStringValue());
Review Comment:
```suggestion
isDistinct = isDistinctExp.getLiteral().getBooleanValue();
```
##########
pinot-core/src/main/java/org/apache/pinot/core/common/ObjectSerDeUtils.java:
##########
@@ -165,8 +173,25 @@ public static ObjectType getObjectType(Object value) {
return ObjectType.Double;
} else if (value instanceof BigDecimal) {
return ObjectType.BigDecimal;
+ } else if (value instanceof IntArrayList) {
+ return ObjectType.IntArrayList;
+ } else if (value instanceof LongArrayList) {
+ return ObjectType.LongArrayList;
+ } else if (value instanceof FloatArrayList) {
+ return ObjectType.FloatArrayList;
} else if (value instanceof DoubleArrayList) {
return ObjectType.DoubleArrayList;
+ } else if (value instanceof ObjectArrayList) {
+ ObjectArrayList objectArrayList = (ObjectArrayList) value;
+ if (!objectArrayList.isEmpty()) {
+ Object next = objectArrayList.iterator().next();
Review Comment:
```suggestion
Object next = objectArrayList.get(0);
```
##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtils.java:
##########
@@ -144,6 +144,13 @@ public static Object getIntermediateResult(DataTable
dataTable, ColumnDataType c
return dataTable.getLong(rowId, colId);
case DOUBLE:
return dataTable.getDouble(rowId, colId);
+ case BOOLEAN_ARRAY:
Review Comment:
These shouldn't be required.
--
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]