Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static String toSql(ScalarFunction fn, boolean ifNotExists) {
boolean isReturnNull = fn.getNullableMode() == NullableMode.ALWAYS_NULLABLE;
sb.append(",\n \"ALWAYS_NULLABLE\"=").append("\"" + isReturnNull + "\"");
sb.append(",\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\"");
sb.append(",\n \"STATIC_LOAD\"=").append("\"" + fn.isStaticLoad() + "\"");
Comment thread
zhangstar333 marked this conversation as resolved.
} else if (fn.getBinaryType() == Function.BinaryType.PYTHON_UDF) {
appendFileIfPresent(sb, fn, true);
boolean isReturnNull = fn.getNullableMode() == NullableMode.ALWAYS_NULLABLE;
Expand Down Expand Up @@ -164,6 +165,7 @@ public static String toSql(AggregateFunction fn, boolean ifNotExists) {
boolean isReturnNull = fn.getNullableMode() == NullableMode.ALWAYS_NULLABLE;
sb.append("\n \"ALWAYS_NULLABLE\"=").append("\"" + isReturnNull + "\",");
sb.append("\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\",");
sb.append("\n \"STATIC_LOAD\"=").append("\"" + fn.isStaticLoad() + "\",");
} else if (fn.getBinaryType() == Function.BinaryType.PYTHON_UDF) {
appendFileIfPresent(sb, fn, false);
if (fn.getLocation() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private String buildProperties(Function function) {
properties.put(locationKey, function.getLocation().toString());
}
properties.put("NULLABLE_MODE", function.getNullableMode().name());
if (function.isStaticLoad()) {
if (function.getBinaryType() == Function.BinaryType.JAVA_UDF) {
properties.put("STATIC_LOAD", String.valueOf(function.isStaticLoad()));
Comment thread
zhangstar333 marked this conversation as resolved.
}
if (!Strings.isNullOrEmpty(function.getRuntimeVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,25 @@ void testScalarFunction_javaUdf_basicSql() throws AnalysisException {
Assertions.assertTrue(sql.contains("\"TYPE\"=\"JAVA_UDF\""));
Assertions.assertTrue(sql.contains("\"VOLATILITY\"=\"volatile\""));
Assertions.assertTrue(sql.contains("\"ALWAYS_NULLABLE\"="));
Assertions.assertTrue(sql.contains("\"STATIC_LOAD\"=\"false\""));
Assertions.assertFalse(sql.contains("OBJECT_FILE"));
Assertions.assertFalse(sql.contains("IF NOT EXISTS"));
Assertions.assertFalse(sql.contains("GLOBAL"));
}

@Test
void testScalarFunction_javaUdf_staticLoad() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用驼峰命名,不要下划线

FunctionName name = new FunctionName("testDb", "static_load_fn");
Type[] argTypes = {Type.INT};
ScalarFunction fn = ScalarFunction.createUdf(BinaryType.JAVA_UDF, name, argTypes,
Type.INT, false, null, "com.example.StaticLoadFn", null, null);
fn.setStaticLoad(true);

String sql = FunctionToSqlConverter.toSql(fn, false);

Assertions.assertTrue(sql.contains("\"STATIC_LOAD\"=\"true\""));
}

@Test
void testScalarFunction_javaUdf_alwaysNullable() {
FunctionName name = new FunctionName("testDb", "nullable_fn");
Expand Down Expand Up @@ -275,13 +289,33 @@ void testAggregateFunction_javaUdf_basicSql() throws AnalysisException {
Assertions.assertTrue(sql.contains("\"TYPE\"=\"JAVA_UDF\""));
Assertions.assertTrue(sql.contains("\"VOLATILITY\"=\"stable\""));
Assertions.assertTrue(sql.contains("\"ALWAYS_NULLABLE\"="));
Assertions.assertTrue(sql.contains("\"STATIC_LOAD\"=\"false\""));
Assertions.assertFalse(sql.contains("INIT_FN"));
Assertions.assertFalse(sql.contains("UPDATE_FN"));
Assertions.assertFalse(sql.contains("MERGE_FN"));
Assertions.assertFalse(sql.contains("IF NOT EXISTS"));
Assertions.assertFalse(sql.contains("GLOBAL"));
}

@Test
void testAggregateFunction_javaUdf_staticLoad() {
FunctionName name = new FunctionName("testDb", "static_load_sum");
Type[] argTypes = {Type.BIGINT};
AggregateFunction fn = AggregateFunction.AggregateFunctionBuilder.createUdfBuilder()
.name(name)
.argsType(argTypes)
.retType(Type.BIGINT)
.intermediateType(Type.BIGINT)
.hasVarArgs(false)
.symbolName("com.example.StaticLoadSum")
.build();
fn.setStaticLoad(true);

String sql = FunctionToSqlConverter.toSql(fn, false);

Assertions.assertTrue(sql.contains("\"STATIC_LOAD\"=\"true\""));
}

@Test
void testAggregateFunction_javaUdf_ifNotExists() {
FunctionName name = new FunctionName("testDb", "my_agg");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ void testBuildProperties_scalarUdfEmitsVolatility() {

Assertions.assertTrue(properties.contains("SYMBOL=com.example.ScalarFn"));
Assertions.assertTrue(properties.contains("VOLATILITY=immutable"));
Assertions.assertTrue(properties.contains("STATIC_LOAD=false"));
}

@Test
void testBuildProperties_javaUdfEmitsStaticLoad() {
ShowFunctionsCommand sf = new ShowFunctionsCommand("test", true, null);
ScalarFunction fn = ScalarFunction.createUdf(Function.BinaryType.JAVA_UDF,
new FunctionName("test", "java_static_load_fn"), new Type[] {Type.INT},
Type.INT, false, null, "com.example.StaticLoadFn", null, null);
fn.setStaticLoad(true);

String properties = sf.buildPropertiesForTest(fn);

Assertions.assertTrue(properties.contains("STATIC_LOAD=true"));
}

@Test
Expand Down
Loading