Skip to content

Commit

Permalink
fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpaulyz committed Nov 19, 2024
1 parent f55f48d commit 87dc7ea
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,8 @@ public void showFunctions(CloseableHttpClient httpClient) {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
assertEquals(3, columnNamesResult.size());
assertEquals(3, valuesResult.size());
assertEquals(4, columnNamesResult.size());
assertEquals(4, valuesResult.size());
}

public void showTimeseries(CloseableHttpClient httpClient) {
Expand Down Expand Up @@ -1767,8 +1767,8 @@ public void showFunctionsV2(CloseableHttpClient httpClient) {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
assertEquals(3, columnNamesResult.size());
assertEquals(3, valuesResult.size());
assertEquals(4, columnNamesResult.size());
assertEquals(4, valuesResult.size());
}

public void showTimeseriesV2(CloseableHttpClient httpClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void testUDFClassName() {

// executed correctly
try (ResultSet resultSet = statement.executeQuery("show functions")) {
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
int count = 0;
while (resultSet.next()) {
StringBuilder stringBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void createReflectShowDropUDAFTest() {
statement.executeQuery("SELECT udaf(*) FROM root.vehicle");

try (ResultSet resultSet = statement.executeQuery("SHOW FUNCTIONS")) {
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
int count = 0;
while (resultSet.next()) {
++count;
Expand All @@ -108,7 +108,7 @@ public void createAndDropUDAFSeveralTimesTest() {
++count;
}
Assert.assertEquals(1 + FUNCTIONS_COUNT, count);
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
statement.execute("DROP FUNCTION udaf");

statement.execute(
Expand All @@ -122,7 +122,7 @@ public void createAndDropUDAFSeveralTimesTest() {
++count;
}
Assert.assertEquals(1 + FUNCTIONS_COUNT, count);
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
statement.execute("DROP FUNCTION udaf");
}
} catch (SQLException throwable) {
Expand Down Expand Up @@ -222,7 +222,7 @@ public void createFunctionWithURITest() throws SQLException {
++count;
}
Assert.assertEquals(2 + FUNCTIONS_COUNT, count);
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
statement.execute("DROP FUNCTION udaf1");
statement.execute("DROP FUNCTION udaf2");
} catch (Exception e) {
Expand Down Expand Up @@ -309,7 +309,7 @@ public void testShowBuiltinFunction() {
"CREATE FUNCTION udaf AS 'org.apache.iotdb.db.query.udf.example.UDAFCount'");

try (ResultSet resultSet = statement.executeQuery("SHOW FUNCTIONS")) {
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
int count = 0;
while (resultSet.next()) {
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -320,7 +320,7 @@ public void testShowBuiltinFunction() {
if (result.contains(FUNCTION_TYPE_EXTERNAL_UDAF)) {
Assert.assertEquals(
String.format(
"UDAF,%s,org.apache.iotdb.db.query.udf.example.UDAFCount,",
"UDAF,%s,org.apache.iotdb.db.query.udf.example.UDAFCount,AVAILABLE,",
FUNCTION_TYPE_EXTERNAL_UDAF),
result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testCreateReflectShowDrop() {
statement.executeQuery("select udf(*, *) from root.vehicle");

try (ResultSet resultSet = statement.executeQuery("show functions")) {
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
int count = 0;
while (resultSet.next()) {
StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -123,7 +123,7 @@ public void testCreateAndDropSeveralTimes() {
Assert.assertEquals(
1 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
count);
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
statement.execute("drop function udf");

statement.execute("create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'");
Expand All @@ -138,7 +138,7 @@ public void testCreateAndDropSeveralTimes() {
Assert.assertEquals(
1 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
count);
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
statement.execute("drop function udf");
}
} catch (SQLException throwable) {
Expand Down Expand Up @@ -249,7 +249,7 @@ public void testCreateFunctionWithURI() throws SQLException {
Assert.assertEquals(
2 + NATIVE_FUNCTIONS_COUNT + BUILTIN_FUNCTIONS_COUNT + BUILTIN_SCALAR_FUNCTIONS_COUNT,
count);
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
statement.execute("drop function udf");
statement.execute("drop function udf1");
} catch (Exception e) {
Expand Down Expand Up @@ -376,7 +376,7 @@ public void testShowBuiltinFunction() {
statement.execute("create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'");

try (ResultSet resultSet = statement.executeQuery("show functions")) {
assertEquals(3, resultSet.getMetaData().getColumnCount());
assertEquals(4, resultSet.getMetaData().getColumnCount());
int count = 0;
while (resultSet.next()) {
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -391,7 +391,7 @@ public void testShowBuiltinFunction() {
if (result.contains(FUNCTION_TYPE_EXTERNAL_UDTF)) {
Assert.assertEquals(
String.format(
"UDF,%s,org.apache.iotdb.db.query.udf.example.Adder,",
"UDF,%s,org.apache.iotdb.db.query.udf.example.Adder,AVAILABLE,",
FUNCTION_TYPE_EXTERNAL_UDTF),
result);
++count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.iotdb.commons.trigger.service.TriggerExecutableManager;
import org.apache.iotdb.commons.udf.service.UDFClassLoader;
import org.apache.iotdb.commons.udf.service.UDFExecutableManager;
import org.apache.iotdb.commons.udf.service.UDFManagementService;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.TimePartitionUtils;
Expand Down Expand Up @@ -491,6 +492,15 @@ public SettableFuture<ConfigTaskResult> createFunction(
Optional<String> stringURI,
Class<?> baseClazz) {
SettableFuture<ConfigTaskResult> future = SettableFuture.create();
if (UDFManagementService.getInstance().checkIsBuiltInFunctionName(model, udfName)) {
future.setException(
new IoTDBException(
String.format(
"Failed to create UDF [%s], the same name UDF has been created",
udfName.toUpperCase()),
TSStatusCode.CREATE_UDF_ERROR.getStatusCode()));
return future;
}
try (ConfigNodeClient client =
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
TCreateFunctionReq tCreateFunctionReq =
Expand Down Expand Up @@ -599,6 +609,13 @@ public SettableFuture<ConfigTaskResult> createFunction(
@Override
public SettableFuture<ConfigTaskResult> dropFunction(Model model, String udfName) {
SettableFuture<ConfigTaskResult> future = SettableFuture.create();
if (UDFManagementService.getInstance().checkIsBuiltInFunctionName(model, udfName)) {
future.setException(
new IoTDBException(
String.format("Built-in function %s can not be deregistered.", udfName.toUpperCase()),
TSStatusCode.DROP_UDF_ERROR.getStatusCode()));
return future;
}
try (ConfigNodeClient client =
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
final TSStatus executionStatus =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,31 @@ private Class<?> getBaseClass(Model model) {
}
}

private void checkIsBuiltInFunctionName(Model model, UDFInformation udfInformation)
public boolean checkIsBuiltInFunctionName(Model model, String functionName)
throws UDFManagementException {
String functionName = udfInformation.getFunctionName();
String className = udfInformation.getClassName();
if (Model.TREE.equals(model)) {
if (BuiltinAggregationFunction.getNativeFunctionNames().contains(functionName.toLowerCase())
return BuiltinAggregationFunction.getNativeFunctionNames()
.contains(functionName.toLowerCase())
|| BuiltinTimeSeriesGeneratingFunction.getNativeFunctionNames()
.contains(functionName.toUpperCase())
|| BuiltinScalarFunction.getNativeFunctionNames().contains(functionName.toLowerCase())) {
String errorMessage =
String.format(
"Failed to register UDF %s(%s), because the given function name conflicts with the built-in function name",
functionName, className);

LOGGER.warn(errorMessage);
throw new UDFManagementException(errorMessage);
}
|| BuiltinScalarFunction.getNativeFunctionNames().contains(functionName.toLowerCase());
} else {
// TODO: Table model UDF
return false;
}
}

private void checkIfRegistered(Model model, UDFInformation udfInformation)
throws UDFManagementException {
checkIsBuiltInFunctionName(model, udfInformation);
if (checkIsBuiltInFunctionName(model, udfInformation.getFunctionName())) {
String errorMessage =
String.format(
"Failed to register UDF %s(%s), because the given function name conflicts with the built-in function name",
udfInformation.getFunctionName(), udfInformation.getClassName());

LOGGER.warn(errorMessage);
throw new UDFManagementException(errorMessage);
}
String functionName = udfInformation.getFunctionName();
String className = udfInformation.getClassName();
UDFInformation information = udfTable.getUDFInformation(model, functionName);
Expand Down

0 comments on commit 87dc7ea

Please sign in to comment.