JackieTien97 commented on code in PR #16041:
URL: https://github.com/apache/iotdb/pull/16041#discussion_r2262182286
##########
integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java:
##########
@@ -4353,6 +4394,22 @@ public void exceptionTest() {
"select approx_most_frequent() from table1",
"701: Aggregation functions [approx_most_frequent] should only have
three arguments",
DATABASE_NAME);
+ tableAssertTestFail(
+ "select approx_percentile() from table1",
+ "701: Aggregation functions [approx_percentile] should only have two
or three arguments",
+ DATABASE_NAME);
+ tableAssertTestFail(
+ "select approx_percentile(s1,1.1) from table1",
+ "701: q should be in [0,1], got 1.1",
Review Comment:
what does q mean? using percentage may be better?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/approximate/TDigest.java:
##########
@@ -0,0 +1,906 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+
+public class TDigest implements Serializable {
+
+ // Scale function implementation - using K_2 as default
+ private static final ScaleFunction SCALE_FUNCTION = new K2ScaleFunction();
+ private static final double DEFAULT_COMPRESSION = 100.0;
+
+ private int mergeCount = 0;
+ private final double publicCompression;
+ private final double compression;
+
+ // points to the first unused centroid
+ private int lastUsedCell;
+
+ // sum_i weight[i] See also unmergedWeight
+ private double totalWeight = 0;
+
+ // number of points that have been added to each merged centroid
+ private final double[] weight;
+ // mean of points added to each merged centroid
+ private final double[] mean;
+
+ // sum_i tempWeight[i]
+ private double unmergedWeight = 0;
+
+ // this is the index of the next temporary centroid
+ private int tempUsed = 0;
+ private final double[] tempWeight;
+ private final double[] tempMean;
+
+ // array used for sorting the temp centroids
+ private final int[] order;
+
+ // Min/max values
+ private double min = Double.POSITIVE_INFINITY;
+ private double max = Double.NEGATIVE_INFINITY;
+
+ // Configuration flags
+ public boolean useAlternatingSort = true;
+ public boolean useTwoLevelCompression = true;
+ public static boolean useWeightLimit = true;
Review Comment:
```suggestion
private boolean useAlternatingSort = true;
private boolean useTwoLevelCompression = true;
private boolean useWeightLimit = true;
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/approximate/TDigestStateFactory.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate;
+
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.TDigestBigArray;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import static java.util.Objects.requireNonNull;
+
+public class TDigestStateFactory {
Review Comment:
It seems that this class is never used
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/approximate/TDigestStateFactory.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate;
+
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.TDigestBigArray;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import static java.util.Objects.requireNonNull;
+
+public class TDigestStateFactory {
Review Comment:
It seems that this class is never used.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/AbstractApproxPercentileAccumulator.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate.TDigest;
+
+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.utils.Binary;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.apache.tsfile.write.UnSupportedDataTypeException;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractApproxPercentileAccumulator implements
TableAccumulator {
+ private static final long INSTANCE_SIZE =
+
RamUsageEstimator.shallowSizeOfInstance(ApproxPercentileAccumulator.class);
+
+ protected final TDigest tDigest = new TDigest();
+ protected final TSDataType seriesDataType;
+ protected double percentage;
+
+ public AbstractApproxPercentileAccumulator(TSDataType seriesDataType) {
+ this.seriesDataType = seriesDataType;
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE + tDigest.getEstimatedSize();
+ }
+
+ @Override
+ public TableAccumulator copy() {
+ return new ApproxPercentileAccumulator(seriesDataType);
+ }
+
+ @Override
+ public void addInput(Column[] arguments, AggregationMask mask) {
+ if (arguments.length == 2) {
+ percentage = arguments[1].getDouble(0);
+ } else if (arguments.length == 3) {
+ percentage = arguments[2].getDouble(0);
+ } else {
+ throw new SemanticException(
+ String.format(
+ "APPROX_PERCENTILE requires 2 or 3 arguments, but got %d",
arguments.length));
+ }
+ switch (seriesDataType) {
+ case INT32:
+ addIntInput(arguments, mask);
+ return;
+ case INT64:
+ case TIMESTAMP:
+ addLongInput(arguments, mask);
+ return;
+ case FLOAT:
+ addFloatInput(arguments, mask);
+ return;
+ case DOUBLE:
+ addDoubleInput(arguments, mask);
+ return;
+ default:
+ throw new UnSupportedDataTypeException(
+ String.format(
+ "Unsupported data type in APPROX_PERCENTILE Aggregation: %s",
seriesDataType));
+ }
+ }
+
+ @Override
+ public void addIntermediate(Column argument) {
+ for (int i = 0; i < argument.getPositionCount(); i++) {
+ if (!argument.isNull(i)) {
+ byte[] data = argument.getBinary(i).getValues();
+ // Read percentage from the first 8 bytes and TDigest from the rest
+ ByteBuffer buffer = ByteBuffer.wrap(data);
+ this.percentage = ReadWriteIOUtils.readDouble(buffer);
+ byte[] tDigestData = new byte[data.length - 8];
+ buffer.get(tDigestData);
Review Comment:
there is no need to copy that into a new byte array again
##########
integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java:
##########
@@ -4291,6 +4292,46 @@ public void approxMostFrequentTest() {
DATABASE_NAME);
}
+ @Test
+ public void approxPercentileTest() {
+ tableResultSetEqualTest(
+ "select approx_percentile(time,
0.5),approx_percentile(s1,0.5),approx_percentile(s2,0.5),approx_percentile(s3,0.5),approx_percentile(s4,0.5)
from table1",
+ buildHeaders(5),
+ new String[] {"2024-09-24T06:15:40.000Z,40,46000,40.0,46.0,"},
+ DATABASE_NAME);
+
+ tableResultSetEqualTest(
+ "select
time,province,approx_percentile(s1,0.5),approx_percentile(s2,0.5) from table1
group by 1,2 order by 2,1",
+ new String[] {"time", "province", "_col2", "_col3"},
+ new String[] {
+ "2024-09-24T06:15:30.000Z,beijing,30,0,",
+ "2024-09-24T06:15:31.000Z,beijing,0,31000,",
+ "2024-09-24T06:15:35.000Z,beijing,0,35000,",
+ "2024-09-24T06:15:36.000Z,beijing,36,0,",
+ "2024-09-24T06:15:40.000Z,beijing,40,40000,",
+ "2024-09-24T06:15:41.000Z,beijing,41,0,",
+ "2024-09-24T06:15:46.000Z,beijing,0,46000,",
+ "2024-09-24T06:15:50.000Z,beijing,0,50000,",
+ "2024-09-24T06:15:51.000Z,beijing,0,0,",
+ "2024-09-24T06:15:55.000Z,beijing,55,0,",
+ "2024-09-24T06:15:30.000Z,shanghai,30,0,",
+ "2024-09-24T06:15:31.000Z,shanghai,0,31000,",
+ "2024-09-24T06:15:35.000Z,shanghai,0,35000,",
+ "2024-09-24T06:15:36.000Z,shanghai,36,0,",
+ "2024-09-24T06:15:40.000Z,shanghai,40,40000,",
+ "2024-09-24T06:15:41.000Z,shanghai,41,0,",
+ "2024-09-24T06:15:46.000Z,shanghai,0,46000,",
+ "2024-09-24T06:15:50.000Z,shanghai,0,50000,",
+ "2024-09-24T06:15:51.000Z,shanghai,0,0,",
+ "2024-09-24T06:15:55.000Z,shanghai,55,0,",
+ },
+ DATABASE_NAME);
+
+ TDigest a = new TDigest();
+ TDigest b = new TDigest();
+ a.add(b);
Review Comment:
what are these codes used for?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/AbstractGroupedApproxPercentileAccumulator.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.AggregationMask;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate.TDigest;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.TDigestBigArray;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.apache.tsfile.write.UnSupportedDataTypeException;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractGroupedApproxPercentileAccumulator implements
GroupedAccumulator {
+
+ private static final long INSTANCE_SIZE =
+
RamUsageEstimator.shallowSizeOfInstance(GroupedApproxPercentileAccumulator.class);
+ protected final TSDataType seriesDataType;
+ protected double percentage;
+ protected final TDigestBigArray array = new TDigestBigArray();
+
+ public AbstractGroupedApproxPercentileAccumulator(TSDataType seriesDataType)
{
Review Comment:
```suggestion
AbstractGroupedApproxPercentileAccumulator(TSDataType seriesDataType) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/AbstractGroupedApproxPercentileAccumulator.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.AggregationMask;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate.TDigest;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.TDigestBigArray;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.apache.tsfile.write.UnSupportedDataTypeException;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractGroupedApproxPercentileAccumulator implements
GroupedAccumulator {
+
+ private static final long INSTANCE_SIZE =
+
RamUsageEstimator.shallowSizeOfInstance(GroupedApproxPercentileAccumulator.class);
+ protected final TSDataType seriesDataType;
+ protected double percentage;
+ protected final TDigestBigArray array = new TDigestBigArray();
+
+ public AbstractGroupedApproxPercentileAccumulator(TSDataType seriesDataType)
{
+ this.seriesDataType = seriesDataType;
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE + array.sizeOf();
+ }
+
+ @Override
+ public void setGroupCount(long groupCount) {
+ array.ensureCapacity(groupCount);
+ }
+
+ @Override
+ public void addInput(int[] groupIds, Column[] arguments, AggregationMask
mask) {
+ if (arguments.length == 2) {
+ percentage = arguments[1].getDouble(0);
+ } else if (arguments.length == 3) {
+ percentage = arguments[2].getDouble(0);
+ } else {
+ throw new SemanticException(
+ String.format(
+ "APPROX_PERCENTILE requires 2 or 3 arguments, but got %d",
arguments.length));
+ }
+
+ switch (seriesDataType) {
+ case INT32:
+ addIntInput(groupIds, arguments, mask);
+ break;
+ case INT64:
+ case TIMESTAMP:
+ addLongInput(groupIds, arguments, mask);
+ break;
+ case FLOAT:
+ addFloatInput(groupIds, arguments, mask);
+ break;
+ case DOUBLE:
+ addDoubleInput(groupIds, arguments, mask);
+ break;
+ default:
+ throw new UnSupportedDataTypeException(
+ String.format(
+ "Unsupported data type in APPROX_PERCENTILE Aggregation: %s",
seriesDataType));
+ }
+ }
+
+ @Override
+ public void addIntermediate(int[] groupIds, Column argument) {
+ for (int i = 0; i < groupIds.length; i++) {
+ int groupId = groupIds[i];
+ if (!argument.isNull(i)) {
+ byte[] data = argument.getBinary(i).getValues();
+ ByteBuffer buffer = ByteBuffer.wrap(data);
+ this.percentage = ReadWriteIOUtils.readDouble(buffer);
+ byte[] tDigestData = new byte[data.length - 8];
+ buffer.get(tDigestData);
Review Comment:
avoid copy the byte array again. you can let TDigest implememy a deserialize
method from ByteBuffer
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/AbstractApproxPercentileAccumulator.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate.TDigest;
+
+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.utils.Binary;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.apache.tsfile.write.UnSupportedDataTypeException;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractApproxPercentileAccumulator implements
TableAccumulator {
+ private static final long INSTANCE_SIZE =
+
RamUsageEstimator.shallowSizeOfInstance(ApproxPercentileAccumulator.class);
+
+ protected final TDigest tDigest = new TDigest();
+ protected final TSDataType seriesDataType;
+ protected double percentage;
+
+ public AbstractApproxPercentileAccumulator(TSDataType seriesDataType) {
+ this.seriesDataType = seriesDataType;
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE + tDigest.getEstimatedSize();
+ }
+
+ @Override
+ public TableAccumulator copy() {
+ return new ApproxPercentileAccumulator(seriesDataType);
+ }
+
+ @Override
+ public void addInput(Column[] arguments, AggregationMask mask) {
+ if (arguments.length == 2) {
+ percentage = arguments[1].getDouble(0);
+ } else if (arguments.length == 3) {
+ percentage = arguments[2].getDouble(0);
+ } else {
+ throw new SemanticException(
+ String.format(
+ "APPROX_PERCENTILE requires 2 or 3 arguments, but got %d",
arguments.length));
+ }
+ switch (seriesDataType) {
+ case INT32:
+ addIntInput(arguments, mask);
+ return;
+ case INT64:
+ case TIMESTAMP:
+ addLongInput(arguments, mask);
+ return;
+ case FLOAT:
+ addFloatInput(arguments, mask);
+ return;
+ case DOUBLE:
+ addDoubleInput(arguments, mask);
+ return;
+ default:
+ throw new UnSupportedDataTypeException(
+ String.format(
+ "Unsupported data type in APPROX_PERCENTILE Aggregation: %s",
seriesDataType));
+ }
+ }
+
+ @Override
+ public void addIntermediate(Column argument) {
+ for (int i = 0; i < argument.getPositionCount(); i++) {
+ if (!argument.isNull(i)) {
+ byte[] data = argument.getBinary(i).getValues();
+ // Read percentage from the first 8 bytes and TDigest from the rest
+ ByteBuffer buffer = ByteBuffer.wrap(data);
+ this.percentage = ReadWriteIOUtils.readDouble(buffer);
+ byte[] tDigestData = new byte[data.length - 8];
+ buffer.get(tDigestData);
+ TDigest other = TDigest.fromByteArray(tDigestData);
+ tDigest.add(other);
+ }
+ }
+ }
+
+ @Override
+ public void evaluateIntermediate(ColumnBuilder columnBuilder) {
+ byte[] tDigestData = tDigest.toByteArray();
+ // Create a buffer with space for percentage (8 bytes) + TDigest data
+ ByteBuffer buffer = ByteBuffer.allocate(8 + tDigestData.length);
+ ReadWriteIOUtils.write(percentage, buffer);
+ buffer.put(tDigestData);
Review Comment:
avoid copy one array twice
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/AbstractGroupedApproxPercentileAccumulator.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed 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.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.AggregationMask;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.approximate.TDigest;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.TDigestBigArray;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.RamUsageEstimator;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.apache.tsfile.write.UnSupportedDataTypeException;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractGroupedApproxPercentileAccumulator implements
GroupedAccumulator {
+
+ private static final long INSTANCE_SIZE =
+
RamUsageEstimator.shallowSizeOfInstance(GroupedApproxPercentileAccumulator.class);
+ protected final TSDataType seriesDataType;
+ protected double percentage;
+ protected final TDigestBigArray array = new TDigestBigArray();
+
+ public AbstractGroupedApproxPercentileAccumulator(TSDataType seriesDataType)
{
+ this.seriesDataType = seriesDataType;
+ }
+
+ @Override
+ public long getEstimatedSize() {
+ return INSTANCE_SIZE + array.sizeOf();
+ }
+
+ @Override
+ public void setGroupCount(long groupCount) {
+ array.ensureCapacity(groupCount);
+ }
+
+ @Override
+ public void addInput(int[] groupIds, Column[] arguments, AggregationMask
mask) {
+ if (arguments.length == 2) {
+ percentage = arguments[1].getDouble(0);
+ } else if (arguments.length == 3) {
+ percentage = arguments[2].getDouble(0);
+ } else {
+ throw new SemanticException(
Review Comment:
It's an abnormal case, just throw `IllegalArgumentException`
--
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]