Skip to content

Commit e0c37ac

Browse files
committed
Merge branch 'master' into force_ci/alter_column_datatype
# Conflicts: # iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanType.java # pom.xml
2 parents 7fe66e1 + 82c8548 commit e0c37ac

File tree

299 files changed

+14189
-4003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+14189
-4003
lines changed

.github/workflows/pipe-it-2cluster.yml

Lines changed: 294 additions & 48 deletions
Large diffs are not rendered by default.

example/udf/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
<artifactId>udf-example</artifactId>
3030
<name>IoTDB: Example: UDF</name>
3131
<dependencies>
32+
<dependency>
33+
<groupId>org.slf4j</groupId>
34+
<artifactId>slf4j-api</artifactId>
35+
</dependency>
3236
<dependency>
3337
<groupId>org.apache.iotdb</groupId>
34-
<artifactId>iotdb-server</artifactId>
38+
<artifactId>udf-api</artifactId>
3539
<version>${project.version}</version>
3640
<scope>provided</scope>
3741
</dependency>

example/udf/src/main/java/org/apache/iotdb/udf/AggregateFunctionExample.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
package org.apache.iotdb.udf;
2121

2222
import org.apache.iotdb.udf.api.State;
23-
import org.apache.iotdb.udf.api.customizer.config.AggregateFunctionConfig;
24-
import org.apache.iotdb.udf.api.customizer.parameter.FunctionParameters;
25-
import org.apache.iotdb.udf.api.exception.UDFException;
26-
import org.apache.iotdb.udf.api.exception.UDFParameterNotValidException;
23+
import org.apache.iotdb.udf.api.customizer.analysis.AggregateFunctionAnalysis;
24+
import org.apache.iotdb.udf.api.customizer.parameter.FunctionArguments;
25+
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
2726
import org.apache.iotdb.udf.api.relational.AggregateFunction;
2827
import org.apache.iotdb.udf.api.relational.access.Record;
2928
import org.apache.iotdb.udf.api.type.Type;
@@ -47,10 +46,10 @@
4746
*
4847
* <p>SHOW FUNCTIONS;
4948
*
50-
* <p>SELECT time, device_id, my_count(s1) as s1_count, my_count(s2) as s2_count FROM t1 group by
49+
* <p>SELECT device_id, my_count(s1) as s1_count, my_count(s2) as s2_count FROM t1 group by
5150
* device_id;
5251
*
53-
* <p>SELECT time, my_count(s1) as s1_count, my_count(s2) as s2_count FROM t1;
52+
* <p>SELECT my_count(s1) as s1_count, my_count(s2) as s2_count FROM t1;
5453
*/
5554
public class AggregateFunctionExample implements AggregateFunction {
5655

@@ -78,15 +77,15 @@ public void deserialize(byte[] bytes) {
7877
}
7978

8079
@Override
81-
public void validate(FunctionParameters parameters) throws UDFException {
82-
if (parameters.getChildExpressionsSize() != 1) {
83-
throw new UDFParameterNotValidException("Only one parameter is required.");
80+
public AggregateFunctionAnalysis analyze(FunctionArguments arguments)
81+
throws UDFArgumentNotValidException {
82+
if (arguments.getArgumentsSize() != 1) {
83+
throw new UDFArgumentNotValidException("Only one parameter is required.");
8484
}
85-
}
86-
87-
@Override
88-
public void beforeStart(FunctionParameters parameters, AggregateFunctionConfig configurations) {
89-
configurations.setOutputDataType(Type.INT64);
85+
return new AggregateFunctionAnalysis.Builder()
86+
.outputDataType(Type.INT64)
87+
.removable(true)
88+
.build();
9089
}
9190

9291
@Override
@@ -114,4 +113,12 @@ public void outputFinal(State state, ResultValue resultValue) {
114113
CountState countState = (CountState) state;
115114
resultValue.setLong(countState.count);
116115
}
116+
117+
@Override
118+
public void remove(State state, Record input) {
119+
CountState countState = (CountState) state;
120+
if (!input.isNull(0)) {
121+
countState.count--;
122+
}
123+
}
117124
}

example/udf/src/main/java/org/apache/iotdb/udf/ScalarFunctionExample.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,42 @@
1919

2020
package org.apache.iotdb.udf;
2121

22-
import org.apache.iotdb.udf.api.customizer.config.ScalarFunctionConfig;
23-
import org.apache.iotdb.udf.api.customizer.parameter.FunctionParameters;
22+
import org.apache.iotdb.udf.api.customizer.analysis.ScalarFunctionAnalysis;
23+
import org.apache.iotdb.udf.api.customizer.parameter.FunctionArguments;
24+
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
2425
import org.apache.iotdb.udf.api.exception.UDFException;
25-
import org.apache.iotdb.udf.api.exception.UDFParameterNotValidException;
2626
import org.apache.iotdb.udf.api.relational.ScalarFunction;
2727
import org.apache.iotdb.udf.api.relational.access.Record;
2828
import org.apache.iotdb.udf.api.type.Type;
2929

30-
/** This is an internal example of the ScalarFunction implementation. */
30+
/**
31+
* This is an internal example of the ScalarFunction implementation.
32+
*
33+
* <p>CREATE DATABASE test;
34+
*
35+
* <p>USE test;
36+
*
37+
* <p>CREATE TABLE t1(device_id STRING TAG, s1 TEXT FIELD, s2 INT32 FIELD);
38+
*
39+
* <p>INSERT INTO t1(time, device_id, s1, s2) VALUES (1, 'd1', 'a', 1), (2, 'd1', null, 2), (3,
40+
* 'd1', 'c', null);
41+
*
42+
* <p>CREATE FUNCTION contain_null AS 'org.apache.iotdb.udf.ScalarFunctionExample';
43+
*
44+
* <p>SHOW FUNCTIONS;
45+
*
46+
* <p>SELECT time, device_id, s1, s2, contain_null(s1, s2) as contain_null, contain_null(s1) as
47+
* s1_isnull, contain_null(s2) as s2_isnull FROM t1;
48+
*/
3149
public class ScalarFunctionExample implements ScalarFunction {
32-
/**
33-
* CREATE DATABASE test;
34-
*
35-
* <p>USE test;
36-
*
37-
* <p>CREATE TABLE t1(device_id STRING TAG, s1 TEXT FIELD, s2 INT32 FIELD);
38-
*
39-
* <p>INSERT INTO t1(time, device_id, s1, s2) VALUES (1, 'd1', 'a', 1), (2, 'd1', null, 2), (3,
40-
* 'd1', 'c', null);
41-
*
42-
* <p>CREATE FUNCTION contain_null AS 'org.apache.iotdb.udf.ScalarFunctionExample';
43-
*
44-
* <p>SHOW FUNCTIONS;
45-
*
46-
* <p>SELECT time, device_id, s1, s2, contain_null(s1, s2) as contain_null, contain_null(s1) as
47-
* s1_isnull, contain_null(s2) as s2_isnull FROM t1;
48-
*/
49-
@Override
50-
public void validate(FunctionParameters parameters) throws UDFException {
51-
if (parameters.getChildExpressionsSize() < 1) {
52-
throw new UDFParameterNotValidException("At least one parameter is required.");
53-
}
54-
}
5550

5651
@Override
57-
public void beforeStart(FunctionParameters parameters, ScalarFunctionConfig configurations) {
58-
configurations.setOutputDataType(Type.BOOLEAN);
52+
public ScalarFunctionAnalysis analyze(FunctionArguments arguments)
53+
throws UDFArgumentNotValidException {
54+
if (arguments.getArgumentsSize() < 1) {
55+
throw new UDFArgumentNotValidException("At least one parameter is required.");
56+
}
57+
return new ScalarFunctionAnalysis.Builder().outputDataType(Type.BOOLEAN).build();
5958
}
6059

6160
@Override

integration-test/src/main/java/org/apache/iotdb/db/query/udf/example/relational/AllSum.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,61 @@
1919

2020
package org.apache.iotdb.db.query.udf.example.relational;
2121

22-
import org.apache.iotdb.udf.api.customizer.config.ScalarFunctionConfig;
23-
import org.apache.iotdb.udf.api.customizer.parameter.FunctionParameters;
22+
import org.apache.iotdb.udf.api.customizer.analysis.ScalarFunctionAnalysis;
23+
import org.apache.iotdb.udf.api.customizer.parameter.FunctionArguments;
24+
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
2425
import org.apache.iotdb.udf.api.exception.UDFException;
25-
import org.apache.iotdb.udf.api.exception.UDFParameterNotValidException;
2626
import org.apache.iotdb.udf.api.relational.ScalarFunction;
2727
import org.apache.iotdb.udf.api.relational.access.Record;
2828
import org.apache.iotdb.udf.api.type.Type;
2929

3030
import java.util.HashSet;
3131
import java.util.Set;
3232

33-
/** Calculate the sum of all parameters. Only support inputs of INT32,INT64,DOUBLE,FLOAT type. */
33+
/** Calculate the sum of all arguments. Only support inputs of INT32,INT64,DOUBLE,FLOAT type. */
3434
public class AllSum implements ScalarFunction {
3535

3636
private Type outputDataType;
3737

3838
@Override
39-
public void validate(FunctionParameters parameters) throws UDFException {
40-
if (parameters.getChildExpressionsSize() < 1) {
41-
throw new UDFParameterNotValidException("At least one parameter is required.");
39+
public ScalarFunctionAnalysis analyze(FunctionArguments arguments)
40+
throws UDFArgumentNotValidException {
41+
if (arguments.getArgumentsSize() < 1) {
42+
throw new UDFArgumentNotValidException("At least one parameter is required.");
4243
}
43-
for (int i = 0; i < parameters.getChildExpressionsSize(); i++) {
44-
if (parameters.getDataType(i) != Type.INT32
45-
&& parameters.getDataType(i) != Type.INT64
46-
&& parameters.getDataType(i) != Type.FLOAT
47-
&& parameters.getDataType(i) != Type.DOUBLE) {
48-
throw new UDFParameterNotValidException(
44+
for (int i = 0; i < arguments.getArgumentsSize(); i++) {
45+
if (arguments.getDataType(i) != Type.INT32
46+
&& arguments.getDataType(i) != Type.INT64
47+
&& arguments.getDataType(i) != Type.FLOAT
48+
&& arguments.getDataType(i) != Type.DOUBLE) {
49+
throw new UDFArgumentNotValidException(
4950
"Only support inputs of INT32,INT64,DOUBLE,FLOAT type.");
5051
}
5152
}
53+
return new ScalarFunctionAnalysis.Builder()
54+
.outputDataType(inferOutputDataType(arguments))
55+
.build();
5256
}
5357

5458
@Override
55-
public void beforeStart(FunctionParameters parameters, ScalarFunctionConfig configurations) {
59+
public void beforeStart(FunctionArguments arguments) throws UDFException {
60+
this.outputDataType = inferOutputDataType(arguments);
61+
}
62+
63+
private Type inferOutputDataType(FunctionArguments arguments) {
5664
Set<Type> inputTypeSet = new HashSet<>();
57-
for (int i = 0; i < parameters.getChildExpressionsSize(); i++) {
58-
inputTypeSet.add(parameters.getDataType(i));
65+
for (int i = 0; i < arguments.getArgumentsSize(); i++) {
66+
inputTypeSet.add(arguments.getDataType(i));
5967
}
6068
if (inputTypeSet.contains(Type.DOUBLE)) {
61-
outputDataType = Type.DOUBLE;
69+
return Type.DOUBLE;
6270
} else if (inputTypeSet.contains(Type.FLOAT)) {
63-
outputDataType = Type.FLOAT;
71+
return Type.FLOAT;
6472
} else if (inputTypeSet.contains(Type.INT64)) {
65-
outputDataType = Type.INT64;
73+
return Type.INT64;
6674
} else {
67-
outputDataType = Type.INT32;
75+
return Type.INT32;
6876
}
69-
configurations.setOutputDataType(outputDataType);
7077
}
7178

7279
@Override

integration-test/src/main/java/org/apache/iotdb/db/query/udf/example/relational/ContainNull.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,22 @@
1919

2020
package org.apache.iotdb.db.query.udf.example.relational;
2121

22-
import org.apache.iotdb.udf.api.customizer.config.ScalarFunctionConfig;
23-
import org.apache.iotdb.udf.api.customizer.parameter.FunctionParameters;
24-
import org.apache.iotdb.udf.api.exception.UDFException;
25-
import org.apache.iotdb.udf.api.exception.UDFParameterNotValidException;
22+
import org.apache.iotdb.udf.api.customizer.analysis.ScalarFunctionAnalysis;
23+
import org.apache.iotdb.udf.api.customizer.parameter.FunctionArguments;
24+
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
2625
import org.apache.iotdb.udf.api.relational.ScalarFunction;
2726
import org.apache.iotdb.udf.api.relational.access.Record;
2827
import org.apache.iotdb.udf.api.type.Type;
2928

3029
public class ContainNull implements ScalarFunction {
31-
@Override
32-
public void validate(FunctionParameters parameters) throws UDFException {
33-
if (parameters.getChildExpressionsSize() < 1) {
34-
throw new UDFParameterNotValidException("At least one parameter is required.");
35-
}
36-
}
3730

3831
@Override
39-
public void beforeStart(FunctionParameters parameters, ScalarFunctionConfig configurations) {
40-
configurations.setOutputDataType(Type.BOOLEAN);
32+
public ScalarFunctionAnalysis analyze(FunctionArguments arguments)
33+
throws UDFArgumentNotValidException {
34+
if (arguments.getArgumentsSize() < 1) {
35+
throw new UDFArgumentNotValidException("At least one parameter is required.");
36+
}
37+
return new ScalarFunctionAnalysis.Builder().outputDataType(Type.BOOLEAN).build();
4138
}
4239

4340
@Override

integration-test/src/main/java/org/apache/iotdb/db/query/udf/example/relational/DatePlusOne.java renamed to integration-test/src/main/java/org/apache/iotdb/db/query/udf/example/relational/DatePlus.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,30 @@
1919

2020
package org.apache.iotdb.db.query.udf.example.relational;
2121

22-
import org.apache.iotdb.udf.api.customizer.config.ScalarFunctionConfig;
23-
import org.apache.iotdb.udf.api.customizer.parameter.FunctionParameters;
24-
import org.apache.iotdb.udf.api.exception.UDFException;
25-
import org.apache.iotdb.udf.api.exception.UDFParameterNotValidException;
22+
import org.apache.iotdb.udf.api.customizer.analysis.ScalarFunctionAnalysis;
23+
import org.apache.iotdb.udf.api.customizer.parameter.FunctionArguments;
24+
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
2625
import org.apache.iotdb.udf.api.relational.ScalarFunction;
2726
import org.apache.iotdb.udf.api.relational.access.Record;
2827
import org.apache.iotdb.udf.api.type.Type;
2928

3029
import java.time.LocalDate;
3130

32-
public class DatePlusOne implements ScalarFunction {
31+
public class DatePlus implements ScalarFunction {
32+
3333
@Override
34-
public void validate(FunctionParameters parameters) throws UDFException {
35-
if (parameters.getChildExpressionsSize() != 2) {
36-
throw new UDFParameterNotValidException("Only two parameter is required.");
34+
public ScalarFunctionAnalysis analyze(FunctionArguments arguments)
35+
throws UDFArgumentNotValidException {
36+
if (arguments.getArgumentsSize() != 2) {
37+
throw new UDFArgumentNotValidException("Only two parameter is required.");
3738
}
38-
if (parameters.getDataType(0) != Type.DATE) {
39-
throw new UDFParameterNotValidException("The first parameter should be DATE type.");
39+
if (arguments.getDataType(0) != Type.DATE) {
40+
throw new UDFArgumentNotValidException("The first parameter should be DATE type.");
4041
}
41-
if (parameters.getDataType(1) != Type.INT32 && parameters.getDataType(1) != Type.INT64) {
42-
throw new UDFParameterNotValidException("The second parameter should be INT type.");
42+
if (arguments.getDataType(1) != Type.INT32 && arguments.getDataType(1) != Type.INT64) {
43+
throw new UDFArgumentNotValidException("The second parameter should be INT type.");
4344
}
44-
}
45-
46-
@Override
47-
public void beforeStart(FunctionParameters parameters, ScalarFunctionConfig configurations) {
48-
configurations.setOutputDataType(Type.DATE);
45+
return new ScalarFunctionAnalysis.Builder().outputDataType(Type.DATE).build();
4946
}
5047

5148
@Override

integration-test/src/main/java/org/apache/iotdb/db/query/udf/example/relational/FirstTwoSum.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
package org.apache.iotdb.db.query.udf.example.relational;
2121

2222
import org.apache.iotdb.udf.api.State;
23-
import org.apache.iotdb.udf.api.customizer.config.AggregateFunctionConfig;
24-
import org.apache.iotdb.udf.api.customizer.parameter.FunctionParameters;
23+
import org.apache.iotdb.udf.api.customizer.analysis.AggregateFunctionAnalysis;
24+
import org.apache.iotdb.udf.api.customizer.parameter.FunctionArguments;
25+
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
2526
import org.apache.iotdb.udf.api.exception.UDFException;
2627
import org.apache.iotdb.udf.api.relational.AggregateFunction;
2728
import org.apache.iotdb.udf.api.relational.access.Record;
@@ -67,27 +68,25 @@ public void deserialize(byte[] bytes) {
6768
}
6869

6970
@Override
70-
public void validate(FunctionParameters parameters) throws UDFException {
71-
if (parameters.getChildExpressionsSize() != 3) {
72-
throw new UDFException("FirstTwoSum should accept three column as input");
71+
public AggregateFunctionAnalysis analyze(FunctionArguments arguments)
72+
throws UDFArgumentNotValidException {
73+
if (arguments.getArgumentsSize() != 3) {
74+
throw new UDFArgumentNotValidException("FirstTwoSum should accept three column as input");
7375
}
7476
for (int i = 0; i < 2; i++) {
75-
if (parameters.getDataType(i) != Type.INT32
76-
&& parameters.getDataType(i) != Type.INT64
77-
&& parameters.getDataType(i) != Type.FLOAT
78-
&& parameters.getDataType(i) != Type.DOUBLE) {
79-
throw new UDFException(
77+
if (arguments.getDataType(i) != Type.INT32
78+
&& arguments.getDataType(i) != Type.INT64
79+
&& arguments.getDataType(i) != Type.FLOAT
80+
&& arguments.getDataType(i) != Type.DOUBLE) {
81+
throw new UDFArgumentNotValidException(
8082
"FirstTwoSum should accept INT32, INT64, FLOAT, DOUBLE as the first two inputs");
8183
}
8284
}
83-
if (parameters.getDataType(2) != Type.TIMESTAMP) {
84-
throw new UDFException("FirstTwoSum should accept TIMESTAMP as the third input");
85+
if (arguments.getDataType(2) != Type.TIMESTAMP) {
86+
throw new UDFArgumentNotValidException(
87+
"FirstTwoSum should accept TIMESTAMP as the third input");
8588
}
86-
}
87-
88-
@Override
89-
public void beforeStart(FunctionParameters parameters, AggregateFunctionConfig configurations) {
90-
configurations.setOutputDataType(Type.DOUBLE);
89+
return new AggregateFunctionAnalysis.Builder().outputDataType(Type.DOUBLE).build();
9190
}
9291

9392
@Override

0 commit comments

Comments
 (0)