jt2594838 commented on code in PR #18606:
URL: https://github.com/apache/iotdb/pull/18606#discussion_r4023234546


##########
pom.xml:
##########
@@ -146,7 +147,7 @@
         <thrift.version>0.24.0</thrift.version>
         <xz.version>1.9</xz.version>
         <zstd-jni.version>1.5.6-3</zstd-jni.version>
-        <tsfile.version>2.4.1-260909-SNAPSHOT</tsfile.version>
+        <tsfile.version>2.4.1-260915-SNAPSHOT</tsfile.version>

Review Comment:
   Upgrade to the published TsFile snapshot containing apache/tsfile#961 so the 
generic Column access used by this refactor supports TimeColumn and dictionary 
logical positions. Both P1 threads contain the old/new artifact verification 
and its class-level scope.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/AvgAccumulator.java:
##########
@@ -62,65 +66,15 @@ public void addInput(Column[] arguments, AggregationMask 
mask) {
     checkArgument(
         arguments.length == 1,
         CalcMessages.EXCEPTION_ARGUMENT_OF_AVG_SHOULD_BE_ONE_COLUMN_82162B82);
-    switch (argumentDataType) {
-      case INT32:
-        addIntInput(arguments[0], mask);
-        return;
-      case INT64:
-        addLongInput(arguments[0], mask);
-        return;
-      case FLOAT:
-        addFloatInput(arguments[0], mask);
-        return;
-      case DOUBLE:
-        addDoubleInput(arguments[0], mask);
-        return;
-      case TEXT:
-      case BLOB:
-      case OBJECT:
-      case STRING:
-      case BOOLEAN:
-      case DATE:
-      case TIMESTAMP:
-      default:
-        throw new UnSupportedDataTypeException(
-            String.format(
-                
CalcMessages.EXCEPTION_UNSUPPORTED_DATA_TYPE_AGGREGATION_AVG_ARG_4E63A3C3,
-                argumentDataType));
-    }
+    inputStrategy.addInput(this, arguments[0], mask);

Review Comment:
   Move AVG add/remove scans into native TypeService strategies and write 
sum/count back once per batch. Starting from the existing sum preserves 
floating-point order. NumericBatchAggregationTest covers masks, nulls, removal 
and ordering. Local mixed-type kernels improved 6.13–8.78x; fixed DOUBLE was 
approximately flat for full selection and improved with masks.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/grouped/GroupedSumAccumulator.java:
##########
@@ -22,24 +22,28 @@
 import 
org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.BooleanBigArray;
 import 
org.apache.iotdb.calc.execution.operator.source.relational.aggregation.grouped.array.DoubleBigArray;
 import org.apache.iotdb.calc.i18n.CalcMessages;
+import org.apache.iotdb.calc.utils.TypeServices;
 
 import org.apache.tsfile.block.column.Column;
 import org.apache.tsfile.block.column.ColumnBuilder;
 import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
 import org.apache.tsfile.utils.RamUsageEstimator;
-import org.apache.tsfile.write.UnSupportedDataTypeException;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
 public class GroupedSumAccumulator implements GroupedAccumulator {
   private static final long INSTANCE_SIZE =
       RamUsageEstimator.shallowSizeOfInstance(GroupedSumAccumulator.class);
   private final TSDataType argumentDataType;
+  private final TypeServices.GroupedSumInput inputStrategy;
   private final BooleanBigArray initResult = new BooleanBigArray();
   private final DoubleBigArray sumValues = new DoubleBigArray();
 
   public GroupedSumAccumulator(TSDataType argumentDataType) {
     this.argumentDataType = argumentDataType;
+    Type type = Type.fromTsDataType(argumentDataType);
+    this.inputStrategy = TypeServices.GROUPED_SUM_INPUT_SERVICE.call(type);

Review Comment:
   Use a typed batch loop for grouped SUM, indexing groupIds by the logical 
selected position and preserving null/initialization behavior. 
NumericBatchAggregationTest covers masks and group placement. Local mixed-type 
kernels improved 3.11–3.56x, with a tradeoff: fixed-DOUBLE full/masked runs 
were about 3.5%/7.4% slower. These are warmed local microbenchmarks, not SQL 
throughput.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/grouped/GroupedAvgAccumulator.java:
##########
@@ -42,11 +43,14 @@ public class GroupedAvgAccumulator implements 
GroupedAccumulator {
   private static final long INSTANCE_SIZE =
       RamUsageEstimator.shallowSizeOfInstance(GroupedAvgAccumulator.class);
   private final TSDataType argumentDataType;
+  private final TypeServices.GroupedAvgInput inputStrategy;
   private final LongBigArray countValues = new LongBigArray();
   private final DoubleBigArray sumValues = new DoubleBigArray();
 
   public GroupedAvgAccumulator(TSDataType argumentDataType) {
     this.argumentDataType = argumentDataType;
+    Type type = Type.fromTsDataType(argumentDataType);
+    this.inputStrategy = TypeServices.GROUPED_AVG_INPUT_SERVICE.call(type);

Review Comment:
   Use a typed batch loop for grouped AVG so input type dispatch is outside the 
row loop. Group IDs still use logical input positions, and count/sum updates 
preserve input order. NumericBatchAggregationTest verifies masks, group 
placement and floating-point order; local mixed-type kernels improved 
3.08–3.38x, with fixed-DOUBLE performance flat or better.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/MinAccumulator.java:
##########
@@ -20,31 +20,38 @@
 package org.apache.iotdb.calc.execution.operator.source.relational.aggregation;
 
 import org.apache.iotdb.calc.i18n.CalcMessages;
+import org.apache.iotdb.calc.utils.TypeServices;
 
 import org.apache.tsfile.block.column.Column;
 import org.apache.tsfile.block.column.ColumnBuilder;
 import org.apache.tsfile.enums.TSDataType;
-import org.apache.tsfile.file.metadata.statistics.BinaryStatistics;
 import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.read.common.type.Type;
 import org.apache.tsfile.utils.Binary;
 import org.apache.tsfile.utils.RamUsageEstimator;
 import org.apache.tsfile.utils.TsPrimitiveType;
 import org.apache.tsfile.write.UnSupportedDataTypeException;
 
-import java.nio.charset.StandardCharsets;
+import java.util.function.Supplier;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
 public class MinAccumulator implements TableAccumulator {
   private static final long INSTANCE_SIZE =
       RamUsageEstimator.shallowSizeOfInstance(MinAccumulator.class);
   private final TSDataType seriesDataType;
+  private final Type type;
+  private final TypeServices.ColumnBatchUpdater valueUpdater;
+  private final TypeServices.StatisticsValueUpdater statisticsValueUpdater;
   private final TsPrimitiveType minResult;
   private boolean initResult;
 
   public MinAccumulator(TSDataType seriesDataType) {
     this.seriesDataType = seriesDataType;
-    this.minResult = TsPrimitiveType.getByType(seriesDataType);
+    this.type = Type.fromTsDataType(seriesDataType);
+    this.minResult = type.getTsPrimitiveType();
+    this.valueUpdater = 
TypeServices.MIN_COLUMN_BATCH_UPDATER_SERVICE.call(type);

Review Comment:
   MIN now selects a TypeService strategy containing the native scan, removing 
the shared per-value updater dispatch. NumericBatchAggregationTest verifies 
masked/null inputs and the existing NaN, signed-zero and integer-boundary 
behavior. The local mixed-type benchmark improved; fixed-DOUBLE results were 
smaller or approximately flat.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/MaxAccumulator.java:
##########
@@ -20,31 +20,38 @@
 package org.apache.iotdb.calc.execution.operator.source.relational.aggregation;
 
 import org.apache.iotdb.calc.i18n.CalcMessages;
+import org.apache.iotdb.calc.utils.TypeServices;
 
 import org.apache.tsfile.block.column.Column;
 import org.apache.tsfile.block.column.ColumnBuilder;
 import org.apache.tsfile.enums.TSDataType;
-import org.apache.tsfile.file.metadata.statistics.BinaryStatistics;
 import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.read.common.type.Type;
 import org.apache.tsfile.utils.Binary;
 import org.apache.tsfile.utils.RamUsageEstimator;
 import org.apache.tsfile.utils.TsPrimitiveType;
 import org.apache.tsfile.write.UnSupportedDataTypeException;
 
-import java.nio.charset.StandardCharsets;
+import java.util.function.Supplier;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
 public class MaxAccumulator implements TableAccumulator {
   private static final long INSTANCE_SIZE =
       RamUsageEstimator.shallowSizeOfInstance(MaxAccumulator.class);
   private final TSDataType seriesDataType;
+  private final Type type;
+  private final TypeServices.ColumnBatchUpdater valueUpdater;
+  private final TypeServices.StatisticsValueUpdater statisticsValueUpdater;
   private final TsPrimitiveType maxResult;
   private boolean initResult;
 
   public MaxAccumulator(TSDataType seriesDataType) {
     this.seriesDataType = seriesDataType;
-    this.maxResult = TsPrimitiveType.getByType(seriesDataType);
+    this.type = Type.fromTsDataType(seriesDataType);
+    this.maxResult = type.getTsPrimitiveType();
+    this.valueUpdater = 
TypeServices.MAX_COLUMN_BATCH_UPDATER_SERVICE.call(type);

Review Comment:
   MAX now selects a TypeService strategy containing the native scan, removing 
the shared per-value updater dispatch. NumericBatchAggregationTest verifies 
masked/null inputs and the existing NaN, signed-zero and integer-boundary 
behavior. The local mixed-type benchmark improved; fixed-DOUBLE results were 
smaller or approximately flat.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/ExtremeAccumulator.java:
##########
@@ -19,25 +19,36 @@
 
 package org.apache.iotdb.calc.execution.operator.source.relational.aggregation;
 
+import org.apache.iotdb.calc.i18n.CalcMessages;
+import org.apache.iotdb.calc.utils.TypeServices;
+
 import org.apache.tsfile.block.column.Column;
 import org.apache.tsfile.block.column.ColumnBuilder;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.read.common.type.Type;
 import org.apache.tsfile.utils.RamUsageEstimator;
 import org.apache.tsfile.utils.TsPrimitiveType;
 import org.apache.tsfile.write.UnSupportedDataTypeException;
 
+import java.util.function.Supplier;
+
 public class ExtremeAccumulator implements TableAccumulator {
   private static final long INSTANCE_SIZE =
       RamUsageEstimator.shallowSizeOfInstance(ExtremeAccumulator.class);
-  private static final String UNSUPPORTED_DATA_TYPE = "Unsupported data type 
in EXTREME: %s";
   private final TSDataType seriesDataType;
+  private final Type type;
   private final TsPrimitiveType extremeResult;
+  private final TypeServices.ColumnBatchUpdater valueUpdater;
+  private final TypeServices.StatisticsValueUpdater statisticsValueUpdater;
   private boolean initResult;
 
   public ExtremeAccumulator(TSDataType seriesDataType) {
     this.seriesDataType = seriesDataType;
-    this.extremeResult = TsPrimitiveType.getByType(seriesDataType);
+    this.type = Type.fromTsDataType(seriesDataType);
+    this.extremeResult = type.getTsPrimitiveType();
+    this.valueUpdater = 
TypeServices.EXTREME_COLUMN_BATCH_UPDATER_SERVICE.call(type);

Review Comment:
   EXTREME now selects a TypeService strategy containing the native scan, 
removing the shared per-value updater dispatch. NumericBatchAggregationTest 
verifies masked/null inputs and the existing NaN, signed-zero and 
integer-boundary behavior. The local mixed-type benchmark improved; 
fixed-DOUBLE results were smaller or approximately flat.



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

Reply via email to