Skip to content

Commit d751364

Browse files
authored
Refactor UDF management process to support table model user-defined function
1 parent b072f9e commit d751364

File tree

57 files changed

+1211
-475
lines changed

Some content is hidden

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

57 files changed

+1211
-475
lines changed

integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBConfigNodeSnapshotIT.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.iotdb.confignode.it;
2121

22+
import org.apache.iotdb.common.rpc.thrift.Model;
2223
import org.apache.iotdb.common.rpc.thrift.TSStatus;
2324
import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
2425
import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
@@ -39,6 +40,7 @@
3940
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
4041
import org.apache.iotdb.confignode.rpc.thrift.TGetTriggerTableResp;
4142
import org.apache.iotdb.confignode.rpc.thrift.TGetUDFTableResp;
43+
import org.apache.iotdb.confignode.rpc.thrift.TGetUdfTableReq;
4244
import org.apache.iotdb.confignode.rpc.thrift.TSchemaPartitionReq;
4345
import org.apache.iotdb.confignode.rpc.thrift.TSchemaPartitionTableResp;
4446
import org.apache.iotdb.confignode.rpc.thrift.TShowCQResp;
@@ -71,9 +73,11 @@
7173
import java.util.List;
7274
import java.util.Map;
7375
import java.util.Set;
76+
import java.util.stream.Collectors;
7477

7578
import static org.apache.iotdb.confignode.it.utils.ConfigNodeTestUtils.generatePatternTreeBuffer;
7679
import static org.junit.Assert.assertEquals;
80+
import static org.junit.Assert.assertTrue;
7781

7882
@RunWith(IoTDBTestRunner.class)
7983
@Category({ClusterIT.class})
@@ -183,7 +187,7 @@ public void testPartitionInfoSnapshot() throws Exception {
183187
}
184188

185189
assertTriggerInformation(createTriggerReqs, client.getTriggerTable());
186-
assertUDFInformation(createFunctionReqs, client.getUDFTable());
190+
assertUDFInformation(createFunctionReqs, client.getUDFTable(new TGetUdfTableReq(Model.TREE)));
187191

188192
TShowCQResp showCQResp = client.showCQ();
189193
assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), showCQResp.getStatus().getCode());
@@ -283,12 +287,14 @@ private List<TCreateFunctionReq> createUDF(SyncConfigNodeIServiceClient client)
283287

284288
TCreateFunctionReq createFunctionReq1 =
285289
new TCreateFunctionReq("test1", "org.apache.iotdb.udf.UDTFExample", true)
290+
.setModel(Model.TREE)
286291
.setJarName(jarName)
287292
.setJarFile(jarFile)
288293
.setJarMD5(jarMD5);
289294

290295
TCreateFunctionReq createFunctionReq2 =
291296
new TCreateFunctionReq("test2", "org.apache.iotdb.udf.UDTFExample", true)
297+
.setModel(Model.TREE)
292298
.setJarName(jarName)
293299
.setJarFile(jarFile)
294300
.setJarMD5(jarMD5);
@@ -307,11 +313,13 @@ private List<TCreateFunctionReq> createUDF(SyncConfigNodeIServiceClient client)
307313
}
308314

309315
private void assertUDFInformation(List<TCreateFunctionReq> req, TGetUDFTableResp resp) {
316+
Map<String, TCreateFunctionReq> nameToReqMap =
317+
req.stream().collect(Collectors.toMap(r -> r.getUdfName().toUpperCase(), r -> r));
310318
for (int i = 0; i < req.size(); i++) {
311-
TCreateFunctionReq createFunctionReq = req.get(i);
312319
UDFInformation udfInformation =
313320
UDFInformation.deserialize(resp.getAllUDFInformation().get(i));
314-
321+
assertTrue(nameToReqMap.containsKey(udfInformation.getFunctionName()));
322+
TCreateFunctionReq createFunctionReq = nameToReqMap.get(udfInformation.getFunctionName());
315323
assertEquals(createFunctionReq.getUdfName().toUpperCase(), udfInformation.getFunctionName());
316324
assertEquals(createFunctionReq.getClassName(), udfInformation.getClassName());
317325
assertEquals(createFunctionReq.getJarName(), udfInformation.getJarName());

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,8 @@ public void showFunctions(CloseableHttpClient httpClient) {
11151115
Map map = queryMetaData(httpClient, sql);
11161116
List<String> columnNamesResult = (List<String>) map.get("columnNames");
11171117
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
1118-
assertEquals(3, columnNamesResult.size());
1119-
assertEquals(3, valuesResult.size());
1118+
assertEquals(4, columnNamesResult.size());
1119+
assertEquals(4, valuesResult.size());
11201120
}
11211121

11221122
public void showTimeseries(CloseableHttpClient httpClient) {
@@ -1767,8 +1767,8 @@ public void showFunctionsV2(CloseableHttpClient httpClient) {
17671767
Map map = queryMetaDataV2(httpClient, sql);
17681768
List<String> columnNamesResult = (List<String>) map.get("column_names");
17691769
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
1770-
assertEquals(3, columnNamesResult.size());
1771-
assertEquals(3, valuesResult.size());
1770+
assertEquals(4, columnNamesResult.size());
1771+
assertEquals(4, valuesResult.size());
17721772
}
17731773

17741774
public void showTimeseriesV2(CloseableHttpClient httpClient) {

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSyntaxConventionStringLiteralIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public void testUDFClassName() {
322322

323323
// executed correctly
324324
try (ResultSet resultSet = statement.executeQuery("show functions")) {
325-
assertEquals(3, resultSet.getMetaData().getColumnCount());
325+
assertEquals(4, resultSet.getMetaData().getColumnCount());
326326
int count = 0;
327327
while (resultSet.next()) {
328328
StringBuilder stringBuilder = new StringBuilder();

integration-test/src/test/java/org/apache/iotdb/db/it/udaf/IoTDBUDAFManagementIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void createReflectShowDropUDAFTest() {
8181
statement.executeQuery("SELECT udaf(*) FROM root.vehicle");
8282

8383
try (ResultSet resultSet = statement.executeQuery("SHOW FUNCTIONS")) {
84-
assertEquals(3, resultSet.getMetaData().getColumnCount());
84+
assertEquals(4, resultSet.getMetaData().getColumnCount());
8585
int count = 0;
8686
while (resultSet.next()) {
8787
++count;
@@ -108,7 +108,7 @@ public void createAndDropUDAFSeveralTimesTest() {
108108
++count;
109109
}
110110
Assert.assertEquals(1 + FUNCTIONS_COUNT, count);
111-
assertEquals(3, resultSet.getMetaData().getColumnCount());
111+
assertEquals(4, resultSet.getMetaData().getColumnCount());
112112
statement.execute("DROP FUNCTION udaf");
113113

114114
statement.execute(
@@ -122,7 +122,7 @@ public void createAndDropUDAFSeveralTimesTest() {
122122
++count;
123123
}
124124
Assert.assertEquals(1 + FUNCTIONS_COUNT, count);
125-
assertEquals(3, resultSet.getMetaData().getColumnCount());
125+
assertEquals(4, resultSet.getMetaData().getColumnCount());
126126
statement.execute("DROP FUNCTION udaf");
127127
}
128128
} catch (SQLException throwable) {
@@ -222,7 +222,7 @@ public void createFunctionWithURITest() throws SQLException {
222222
++count;
223223
}
224224
Assert.assertEquals(2 + FUNCTIONS_COUNT, count);
225-
assertEquals(3, resultSet.getMetaData().getColumnCount());
225+
assertEquals(4, resultSet.getMetaData().getColumnCount());
226226
statement.execute("DROP FUNCTION udaf1");
227227
statement.execute("DROP FUNCTION udaf2");
228228
} catch (Exception e) {
@@ -309,7 +309,7 @@ public void testShowBuiltinFunction() {
309309
"CREATE FUNCTION udaf AS 'org.apache.iotdb.db.query.udf.example.UDAFCount'");
310310

311311
try (ResultSet resultSet = statement.executeQuery("SHOW FUNCTIONS")) {
312-
assertEquals(3, resultSet.getMetaData().getColumnCount());
312+
assertEquals(4, resultSet.getMetaData().getColumnCount());
313313
int count = 0;
314314
while (resultSet.next()) {
315315
StringBuilder stringBuilder = new StringBuilder();
@@ -320,7 +320,7 @@ public void testShowBuiltinFunction() {
320320
if (result.contains(FUNCTION_TYPE_EXTERNAL_UDAF)) {
321321
Assert.assertEquals(
322322
String.format(
323-
"UDAF,%s,org.apache.iotdb.db.query.udf.example.UDAFCount,",
323+
"UDAF,%s,org.apache.iotdb.db.query.udf.example.UDAFCount,AVAILABLE,",
324324
FUNCTION_TYPE_EXTERNAL_UDAF),
325325
result);
326326
}

integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDFManagementIT.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void testCreateReflectShowDrop() {
8787
statement.executeQuery("select udf(*, *) from root.vehicle");
8888

8989
try (ResultSet resultSet = statement.executeQuery("show functions")) {
90-
assertEquals(3, resultSet.getMetaData().getColumnCount());
90+
assertEquals(4, resultSet.getMetaData().getColumnCount());
9191
int count = 0;
9292
while (resultSet.next()) {
9393
StringBuilder stringBuilder = new StringBuilder();
@@ -123,7 +123,7 @@ public void testCreateAndDropSeveralTimes() {
123123
Assert.assertEquals(
124124
1 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
125125
count);
126-
assertEquals(3, resultSet.getMetaData().getColumnCount());
126+
assertEquals(4, resultSet.getMetaData().getColumnCount());
127127
statement.execute("drop function udf");
128128

129129
statement.execute("create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'");
@@ -138,7 +138,7 @@ public void testCreateAndDropSeveralTimes() {
138138
Assert.assertEquals(
139139
1 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
140140
count);
141-
assertEquals(3, resultSet.getMetaData().getColumnCount());
141+
assertEquals(4, resultSet.getMetaData().getColumnCount());
142142
statement.execute("drop function udf");
143143
}
144144
} catch (SQLException throwable) {
@@ -249,7 +249,7 @@ public void testCreateFunctionWithURI() throws SQLException {
249249
Assert.assertEquals(
250250
2 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
251251
count);
252-
assertEquals(3, resultSet.getMetaData().getColumnCount());
252+
assertEquals(4, resultSet.getMetaData().getColumnCount());
253253
statement.execute("drop function udf");
254254
statement.execute("drop function udf1");
255255
} catch (Exception e) {
@@ -353,7 +353,10 @@ public void testCreateBuiltinFunction() {
353353
statement.execute("create function sin as 'org.apache.iotdb.db.query.udf.example.Adder'");
354354
fail();
355355
} catch (SQLException throwable) {
356-
assertTrue(throwable.getMessage().contains("the same name UDF has been created"));
356+
assertTrue(
357+
throwable
358+
.getMessage()
359+
.contains("the given function name conflicts with the built-in function name"));
357360
}
358361
}
359362

@@ -376,7 +379,7 @@ public void testShowBuiltinFunction() {
376379
statement.execute("create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'");
377380

378381
try (ResultSet resultSet = statement.executeQuery("show functions")) {
379-
assertEquals(3, resultSet.getMetaData().getColumnCount());
382+
assertEquals(4, resultSet.getMetaData().getColumnCount());
380383
int count = 0;
381384
while (resultSet.next()) {
382385
StringBuilder stringBuilder = new StringBuilder();
@@ -391,7 +394,7 @@ public void testShowBuiltinFunction() {
391394
if (result.contains(FUNCTION_TYPE_EXTERNAL_UDTF)) {
392395
Assert.assertEquals(
393396
String.format(
394-
"UDF,%s,org.apache.iotdb.db.query.udf.example.Adder,",
397+
"UDF,%s,org.apache.iotdb.db.query.udf.example.Adder,AVAILABLE,",
395398
FUNCTION_TYPE_EXTERNAL_UDTF),
396399
result);
397400
++count;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.udf.api.relational;
21+
22+
public interface AggregationFunction extends SQLFunction {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.udf.api.relational;
21+
22+
public interface SQLFunction {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.udf.api.relational;
21+
22+
public interface ScalarFunction extends SQLFunction {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.udf.api.relational;
21+
22+
public interface TableFunction extends SQLFunction {}

0 commit comments

Comments
 (0)