JackieTien97 commented on code in PR #18035:
URL: https://github.com/apache/iotdb/pull/18035#discussion_r3479492216
##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/UserDefinedAggregateFunctionAccumulator.java:
##########
@@ -46,17 +49,51 @@ public class UserDefinedAggregateFunctionAccumulator
implements TableAccumulator
RamUsageEstimator.shallowSizeOfInstance(UserDefinedAggregateFunctionAccumulator.class);
private final AggregateFunctionAnalysis analysis;
private final AggregateFunction aggregateFunction;
+ private final FunctionArguments functionArguments;
private final List<Type> inputDataTypes;
private final State state;
+ private final IoTDBLocal ioTDBLocal;
+ private boolean init;
public UserDefinedAggregateFunctionAccumulator(
AggregateFunctionAnalysis analysis,
AggregateFunction aggregateFunction,
- List<Type> inputDataTypes) {
+ FunctionArguments functionArguments,
+ List<Type> inputDataTypes,
+ IoTDBLocal ioTDBLocal) {
+ this(analysis, aggregateFunction, functionArguments, inputDataTypes,
ioTDBLocal, false);
+ }
+
+ private UserDefinedAggregateFunctionAccumulator(
+ AggregateFunctionAnalysis analysis,
+ AggregateFunction aggregateFunction,
+ FunctionArguments functionArguments,
+ List<Type> inputDataTypes,
+ IoTDBLocal ioTDBLocal,
+ boolean init) {
+ checkArgument(ioTDBLocal != null, "IoTDBLocal must not be null for UDAF");
this.analysis = analysis;
this.aggregateFunction = aggregateFunction;
+ this.functionArguments = functionArguments;
this.inputDataTypes = inputDataTypes;
this.state = aggregateFunction.createState();
+ this.ioTDBLocal = ioTDBLocal;
+ this.init = init;
+ }
+
+ private void initIfNeeded() {
+ if (init) {
+ return;
+ }
+ init = true;
+ try {
+ aggregateFunction.beforeStart(functionArguments, ioTDBLocal);
+ } catch (UDFException e) {
+ throw new RuntimeException(
Review Comment:
never throw RuntimeException, use IoTDBRunTimeExeception instead, and use
`EXECUTE_UDF_ERROR(1206)` status code
##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/UserDefinedAggregateFunctionAccumulator.java:
##########
@@ -66,23 +103,26 @@ public long getEstimatedSize() {
@Override
public TableAccumulator copy() {
- return new UserDefinedAggregateFunctionAccumulator(analysis,
aggregateFunction, inputDataTypes);
+ return new UserDefinedAggregateFunctionAccumulator(
+ analysis, aggregateFunction, functionArguments, inputDataTypes,
ioTDBLocal, true);
Review Comment:
```suggestion
analysis, aggregateFunction, functionArguments, inputDataTypes,
ioTDBLocal, init);
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/FragmentInstance.java:
##########
@@ -83,6 +83,9 @@ public class FragmentInstance implements IConsensusRequest {
private final boolean debug;
private final boolean verbose;
+ // Outer query deadline (startTime + timeout) for IoTDBLocal on remote
DataNodes.
+ private long outerQueryDeadlineMs = -1L;
Review Comment:
no need to add this field? we can infer this just using timeOut +
System.currentTime
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/FragmentInstance.java:
##########
@@ -83,6 +83,9 @@ public class FragmentInstance implements IConsensusRequest {
private final boolean debug;
private final boolean verbose;
+ // Outer query deadline (startTime + timeout) for IoTDBLocal on remote
DataNodes.
+ private long outerQueryDeadlineMs = -1L;
Review Comment:
avoid changing FI serde method, we would try our best to promise rolling
upgrading.
##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/source/relational/aggregation/UserDefinedAggregateFunctionAccumulator.java:
##########
@@ -150,7 +191,8 @@ public boolean removable() {
@Override
public void close() {
- aggregateFunction.beforeDestroy();
+ aggregateFunction.beforeDestroy(ioTDBLocal);
Review Comment:
```suggestion
if (init) {
aggregateFunction.beforeDestroy(ioTDBLocal);
}
```
only call `beforeDestroy` if we call beforeStart
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/udf/UDFResultSetImpl.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.iotdb.db.queryengine.udf;
+
+import
org.apache.iotdb.calc.execution.operator.source.relational.aggregation.RecordIterator;
+import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.schema.column.ColumnHeader;
+import org.apache.iotdb.commons.udf.utils.UDFDataTypeTransformer;
+import org.apache.iotdb.udf.api.UDFResultSet;
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.access.Record;
+
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.type.Type;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/** Server-side implementation of {@link UDFResultSet}. */
+public class UDFResultSetImpl implements UDFResultSet {
+
+ private final List<UDFResultSetImpl> openResultSets;
+ private final int index;
+ private final InternalQueryResult queryResult;
+ private final List<Type> columnTypes;
+
+ private Iterator<Record> rowIterator;
+ private boolean closed;
+
+ public UDFResultSetImpl(
+ List<UDFResultSetImpl> openResultSets, int index, InternalQueryResult
queryResult) {
+ this.openResultSets = openResultSets;
+ this.index = index;
+ this.queryResult = queryResult;
+ this.columnTypes =
buildColumnTypes(queryResult.getDatasetHeader().getColumnHeaders());
+ }
+
+ @Override
+ public boolean hasNext() throws UDFException {
+ ensureOpen();
+
+ while (rowIterator == null || !rowIterator.hasNext()) {
+ if (!queryResult.getQueryExecution().hasNextResult()) {
+ return false;
+ }
+ Optional<TsBlock> batch;
+ try {
+ batch = queryResult.getQueryExecution().getBatchResult();
+ } catch (IoTDBException e) {
+ throw new UDFException(e.getMessage(), e);
+ }
+ if (!batch.isPresent()) {
+ return false;
+ }
+ TsBlock currentBlock = batch.get();
+ rowIterator =
+ new RecordIterator(
+ Arrays.asList(currentBlock.getValueColumns()),
Review Comment:
should rearrange the column sequence according to
DatasetHeader.columnIndex2TsBlockColumnIndexList, add an IT about this.
--
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]