World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#9871] fix(function): move returnType/returnColumns to FunctionDefinition level (#9872)
mchadese4a4870feab4
diff --git a/api/src/main/java/org/apache/gravitino/function/Function.java b/api/src/main/java/org/apache/gravitino/function/Function.javaindex d5b88dd878..a55c9eab69 100644--- a/api/src/main/java/org/apache/gravitino/function/Function.java+++ b/api/src/main/java/org/apache/gravitino/function/Function.java@@ -22,7 +22,6 @@ import javax.annotation.Nullable;import org.apache.gravitino.Auditable;import org.apache.gravitino.Namespace;import org.apache.gravitino.annotation.Evolving;-import org.apache.gravitino.rel.types.Type;/*** An interface representing a user-defined function under a schema {@link Namespace}. A function is@@ -32,14 +31,12 @@ import org.apache.gravitino.rel.types.Type;* reuse it across multiple compute engines like Spark, Trino, and AI engines.** <p>A function is characterized by its name, type (scalar for row-by-row operations, aggregate for- * group operations, or table-valued for set-returning operations), whether it is deterministic, its- * return type or columns (for table function), and its definitions that contain parameters and+ * group operations, or table-valued for set-returning operations), whether it is deterministic, and+ * its definitions that contain parameters, return type or columns (for table function), and* implementations for different runtime engines.*/@Evolvingpublic interface Function extends Auditable {- /** An empty array of {@link FunctionColumn}. */- FunctionColumn[] EMPTY = new FunctionColumn[0];/*** @return The function name.@@ -64,30 +61,6 @@ public interface Function extends Auditable {return null;}- /**- * The return type for scalar or aggregate functions.- *- * @return The return type, null if this is a table-valued function.- */- @Nullable- default Type returnType() {- return null;- }-- /**- * The output columns for a table-valued function.- *- * <p>A table-valued function is a function that returns a table instead of a scalar value or an- * aggregate result. The returned table has a fixed schema defined by the columns returned from- * this method.- *- * @return The output columns that define the schema of the table returned by this function, or an- * empty array if this is a scalar or aggregate function.- */- default FunctionColumn[] returnColumns() {- return EMPTY;- }-/*** @return The definitions of the function.*/diff --git a/api/src/main/java/org/apache/gravitino/function/FunctionCatalog.java b/api/src/main/java/org/apache/gravitino/function/FunctionCatalog.javaindex 2b4b409d9e..175e00dd4d 100644--- a/api/src/main/java/org/apache/gravitino/function/FunctionCatalog.java+++ b/api/src/main/java/org/apache/gravitino/function/FunctionCatalog.java@@ -24,7 +24,6 @@ import org.apache.gravitino.annotation.Evolving;import org.apache.gravitino.exceptions.FunctionAlreadyExistsException;import org.apache.gravitino.exceptions.NoSuchFunctionException;import org.apache.gravitino.exceptions.NoSuchSchemaException;-import org.apache.gravitino.rel.types.Type;/** The FunctionCatalog interface defines the public API for managing functions in a schema. */@Evolving@@ -75,14 +74,15 @@ public interface FunctionCatalog {}/**- * Register a scalar or aggregate function with one or more definitions (overloads).+ * Register a function with one or more definitions (overloads). Each definition contains its own+ * return type (for scalar/aggregate functions) or return columns (for table-valued functions).** @param ident The function identifier.* @param comment The optional function comment.- * @param functionType The function type.+ * @param functionType The function type (SCALAR, AGGREGATE, or TABLE).* @param deterministic Whether the function is deterministic.- * @param returnType The return type.- * @param definitions The function definitions.+ * @param definitions The function definitions, each containing parameters, return type/columns,+ * and implementations.* @return The registered function.* @throws NoSuchSchemaException If the schema does not exist.* @throws FunctionAlreadyExistsException If the function already exists.@@ -92,27 +92,6 @@ public interface FunctionCatalog {String comment,FunctionType functionType,boolean deterministic,- Type returnType,- FunctionDefinition[] definitions)- throws NoSuchSchemaException, FunctionAlreadyExistsException;-- /**- * Register a table-valued function with one or more definitions (overloads).- *- * @param ident The function identifier.- * @param comment The optional function comment.- * @param deterministic Whether the function is deterministic.- * @param returnColumns The return columns.- * @param definitions The function definitions.- * @return The registered function.- * @throws NoSuchSchemaException If the schema does not exist.- * @throws FunctionAlreadyExistsException If the function already exists.- */- Function registerFunction(- NameIdentifier ident,- String comment,- boolean deterministic,- FunctionColumn[] returnColumns,FunctionDefinition[] definitions)throws NoSuchSchemaException, FunctionAlreadyExistsException;diff --git a/api/src/main/java/org/apache/gravitino/function/FunctionDefinition.java b/api/src/main/java/org/apache/gravitino/function/FunctionDefinition.javaindex c7ea9562d4..f6fd591d18 100644--- a/api/src/main/java/org/apache/gravitino/function/FunctionDefinition.java+++ b/api/src/main/java/org/apache/gravitino/function/FunctionDefinition.java@@ -18,21 +18,54 @@*/package org.apache.gravitino.function;+import javax.annotation.Nullable;import org.apache.gravitino.annotation.Evolving;+import org.apache.gravitino.rel.types.Type;/**- * A function definition that pairs a specific parameter list with its implementations. A single- * function can include multiple definitions (overloads), each with distinct parameters and- * implementations.+ * A function definition that pairs a specific parameter list with its implementations and return+ * type. A single function can include multiple definitions (overloads), each with distinct+ * parameters and implementations. Overload resolution is based on parameters only; return type or+ * return columns are metadata and do not participate in definition matching.+ *+ * <p>For scalar or aggregate functions, use {@link #returnType()} to specify the return type. For+ * table-valued functions, use {@link #returnColumns()} to specify the output columns.*/@Evolvingpublic interface FunctionDefinition {+ /** An empty array of {@link FunctionColumn}. */+ FunctionColumn[] EMPTY_COLUMNS = new FunctionColumn[0];+/*** @return The parameters for this definition. Maybe an empty array for a no-arg definition.*/FunctionParam[] parameters();+ /**+ * The return type for scalar or aggregate function definitions.+ *+ * @return The return type, or null if this is a table-valued function definition.+ */+ @Nullable+ default Type returnType() {+ return null;+ }++ /**+ * The output columns for a table-valued function definition.+ *+ * <p>A table-valued function is a function that returns a table instead of a scalar value or an+ * aggregate result. The returned table has a fixed schema defined by the columns returned from+ * this method.+ *+ * @return The output columns that define the schema of the table returned by this definition, or+ * an empty array if this is a scalar or aggregate function definition.+ */+ default FunctionColumn[] returnColumns() {+ return EMPTY_COLUMNS;+ }+/*** @return The implementations associated with this definition.*/diff --git a/api/src/main/java/org/apache/gravitino/function/FunctionDefinitions.java b/api/src/main/java/org/apache/gravitino/function/FunctionDefinitions.javaindex af0c4472b5..cbe702fa01 100644--- a/api/src/main/java/org/apache/gravitino/function/FunctionDefinitions.java+++ b/api/src/main/java/org/apache/gravitino/function/FunctionDefinitions.java@@ -20,7 +20,10 @@ package org.apache.gravitino.function;import com.google.common.base.Preconditions;import java.util.Arrays;+import java.util.Objects;+import javax.annotation.Nullable;import org.apache.commons.lang3.ArrayUtils;+import org.apache.gravitino.rel.types.Type;/** Helper methods to create {@link FunctionDefinition} instances. */public final class FunctionDefinitions {@@ -40,23 +43,63 @@ public final class FunctionDefinitions {}/**- * Create a {@link FunctionDefinition} instance.+ * Create a {@link FunctionDefinition} instance for a scalar or aggregate function.** @param parameters The parameters for this definition, it may be null or empty.+ * @param returnType The return type for this definition, it must not be null.* @param impls The implementations for this definition, it must not be null or empty.* @return A {@link FunctionDefinition} instance.*/+ public static FunctionDefinition of(+ FunctionParam[] parameters, Type returnType, FunctionImpl[] impls) {+ return new FunctionDefinitionImpl(parameters, returnType, null, impls);+ }++ /**+ * Create a {@link FunctionDefinition} instance for a table-valued function.+ *+ * @param parameters The parameters for this definition, it may be null or empty.+ * @param returnColumns The return columns for this definition, it must not be null or empty.+ * @param impls The implementations for this definition, it must not be null or empty.+ * @return A {@link FunctionDefinition} instance.+ */+ public static FunctionDefinition of(+ FunctionParam[] parameters, FunctionColumn[] returnColumns, FunctionImpl[] impls) {+ return new FunctionDefinitionImpl(parameters, null, returnColumns, impls);+ }++ /**+ * Create a {@link FunctionDefinition} instance. This method is kept for backward compatibility.+ *+ * @param parameters The parameters for this definition, it may be null or empty.+ * @param impls The implementations for this definition, it must not be null or empty.+ * @return A {@link FunctionDefinition} instance.+ * @deprecated Use {@link #of(FunctionParam[], Type, FunctionImpl[])} or {@link+ * #of(FunctionParam[], FunctionColumn[], FunctionImpl[])} instead.+ */+ @Deprecatedpublic static FunctionDefinition of(FunctionParam[] parameters, FunctionImpl[] impls) {- return new FunctionDefinitionImpl(parameters, impls);+ return new FunctionDefinitionImpl(parameters, null, null, impls);}private static final class FunctionDefinitionImpl implements FunctionDefinition {private final FunctionParam[] parameters;+ private final Type returnType;+ private final FunctionColumn[] returnColumns;private final FunctionImpl[] impls;- FunctionDefinitionImpl(FunctionParam[] parameters, FunctionImpl[] impls) {+ FunctionDefinitionImpl(+ FunctionParam[] parameters,+ @Nullable Type returnType,+ @Nullable FunctionColumn[] returnColumns,+ FunctionImpl[] impls) {this.parameters =parameters == null ? new FunctionParam[0] : Arrays.copyOf(parameters, parameters.length);+ this.returnType = returnType;+ this.returnColumns =+ returnColumns == null+ ? FunctionDefinition.EMPTY_COLUMNS+ : Arrays.copyOf(returnColumns, returnColumns.length);Preconditions.checkArgument(impls != null && impls.length > 0, "Impls cannot be null or empty");this.impls = Arrays.copyOf(impls, impls.length);@@ -67,6 +110,18 @@ public final class FunctionDefinitions {return Arrays.copyOf(parameters, parameters.length);}+ @Override+ public Type returnType() {+ return returnType;+ }++ @Override+ public FunctionColumn[] returnColumns() {+ return returnColumns.length == 0+ ? FunctionDefinition.EMPTY_COLUMNS+ : Arrays.copyOf(returnColumns, returnColumns.length);+ }+@Overridepublic FunctionImpl[] impls() {return Arrays.copyOf(impls, impls.length);@@ -81,12 +136,17 @@ public final class FunctionDefinitions {return false;}FunctionDefinition that = (FunctionDefinition) obj;- return Arrays.equals(parameters, that.parameters()) && Arrays.equals(impls, that.impls());+ return Arrays.equals(parameters, that.parameters())+ && Objects.equals(returnType, that.returnType())+ && Arrays.equals(returnColumns, that.returnColumns())+ && Arrays.equals(impls, that.impls());}@Overridepublic int hashCode() {int result = Arrays.hashCode(parameters);+ result = 31 * result + Objects.hashCode(returnType);+ result = 31 * result + Arrays.hashCode(returnColumns);result = 31 * result + Arrays.hashCode(impls);return result;}@@ -95,6 +155,10 @@ public final class FunctionDefinitions {public String toString() {return "FunctionDefinition{parameters="+ Arrays.toString(parameters)+ + ", returnType="+ + returnType+ + ", returnColumns="+ + Arrays.toString(returnColumns)+ ", impls="+ Arrays.toString(impls)+ '}';diff --git a/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHive2IT.java b/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHive2IT.javaindex ec332c3072..800ae44e22 100644--- a/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHive2IT.java+++ b/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/integration/test/CatalogHive2IT.java@@ -809,10 +809,10 @@ public class CatalogHive2IT extends BaseIT {"test comment",FunctionType.SCALAR,true,- Types.StringType.get(),FunctionDefinitions.of(FunctionDefinitions.of(FunctionParams.of(FunctionParams.of("input", Types.StringType.get())),+ Types.StringType.get(),FunctionImpls.of(FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "mock.udf.class.name")))));diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java b/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.javaindex 64a3ba8732..45ae377ca2 100644--- a/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java@@ -49,7 +49,6 @@ import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionCatalog;import org.apache.gravitino.function.FunctionChange;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionType;import org.apache.gravitino.policy.Policy;@@ -358,21 +357,9 @@ abstract class BaseSchemaCatalog extends CatalogDTOString comment,FunctionType functionType,boolean deterministic,- org.apache.gravitino.rel.types.Type returnType,FunctionDefinition[] definitions) {return functionOperations.registerFunction(- ident, comment, functionType, deterministic, returnType, definitions);- }-- @Override- public Function registerFunction(- NameIdentifier ident,- String comment,- boolean deterministic,- FunctionColumn[] returnColumns,- FunctionDefinition[] definitions) {- return functionOperations.registerFunction(- ident, comment, deterministic, returnColumns, definitions);+ ident, comment, functionType, deterministic, definitions);}@Overridediff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/FunctionCatalogOperations.java b/clients/client-java/src/main/java/org/apache/gravitino/client/FunctionCatalogOperations.javaindex 1e8abade24..b7dc36d1ed 100644--- a/clients/client-java/src/main/java/org/apache/gravitino/client/FunctionCatalogOperations.java+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/FunctionCatalogOperations.java@@ -27,7 +27,6 @@ import java.util.Map;import java.util.stream.Collectors;import org.apache.gravitino.NameIdentifier;import org.apache.gravitino.Namespace;-import org.apache.gravitino.dto.function.FunctionColumnDTO;import org.apache.gravitino.dto.function.FunctionDefinitionDTO;import org.apache.gravitino.dto.requests.FunctionRegisterRequest;import org.apache.gravitino.dto.requests.FunctionUpdateRequest;@@ -42,10 +41,8 @@ import org.apache.gravitino.exceptions.NoSuchSchemaException;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionCatalog;import org.apache.gravitino.function.FunctionChange;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionType;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rest.RESTUtils;/**@@ -141,14 +138,14 @@ class FunctionCatalogOperations implements FunctionCatalog {}/**- * Register a scalar or aggregate function with one or more definitions (overloads).+ * Register a function with one or more definitions (overloads). Each definition carries its own+ * return type or return columns.** @param ident The function identifier.* @param comment The optional function comment.* @param functionType The function type.* @param deterministic Whether the function is deterministic.- * @param returnType The return type.- * @param definitions The function definitions.+ * @param definitions The function definitions, each containing its own return type/columns.* @return The registered function.* @throws NoSuchSchemaException If the schema does not exist.* @throws FunctionAlreadyExistsException If the function already exists.@@ -159,7 +156,6 @@ class FunctionCatalogOperations implements FunctionCatalog {String comment,FunctionType functionType,boolean deterministic,- Type returnType,FunctionDefinition[] definitions)throws NoSuchSchemaException, FunctionAlreadyExistsException {checkFunctionNameIdentifier(ident);@@ -171,53 +167,6 @@ class FunctionCatalogOperations implements FunctionCatalog {.withComment(comment).withFunctionType(functionType).withDeterministic(deterministic)- .withReturnType(returnType)- .withDefinitions(toFunctionDefinitionDTOs(definitions))- .build();- req.validate();-- FunctionResponse resp =- restClient.post(- formatFunctionRequestPath(fullNamespace),- req,- FunctionResponse.class,- Collections.emptyMap(),- ErrorHandlers.functionErrorHandler());- resp.validate();-- return resp.getFunction();- }-- /**- * Register a table-valued function with one or more definitions (overloads).- *- * @param ident The function identifier.- * @param comment The optional function comment.- * @param deterministic Whether the function is deterministic.- * @param returnColumns The return columns.- * @param definitions The function definitions.- * @return The registered function.- * @throws NoSuchSchemaException If the schema does not exist.- * @throws FunctionAlreadyExistsException If the function already exists.- */- @Override- public Function registerFunction(- NameIdentifier ident,- String comment,- boolean deterministic,- FunctionColumn[] returnColumns,- FunctionDefinition[] definitions)- throws NoSuchSchemaException, FunctionAlreadyExistsException {- checkFunctionNameIdentifier(ident);-- Namespace fullNamespace = getFunctionFullNamespace(ident.namespace());- FunctionRegisterRequest req =- FunctionRegisterRequest.builder()- .withName(ident.name())- .withComment(comment)- .withFunctionType(FunctionType.TABLE)- .withDeterministic(deterministic)- .withReturnColumns(toFunctionColumnDTOs(returnColumns)).withDefinitions(toFunctionDefinitionDTOs(definitions)).build();req.validate();@@ -343,13 +292,4 @@ class FunctionCatalogOperations implements FunctionCatalog {.map(DTOConverters::toFunctionDefinitionDTO).toArray(FunctionDefinitionDTO[]::new);}-- private FunctionColumnDTO[] toFunctionColumnDTOs(FunctionColumn[] columns) {- if (columns == null) {- return null;- }- return Arrays.stream(columns)- .map(DTOConverters::toFunctionColumnDTO)- .toArray(FunctionColumnDTO[]::new);- }}diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/TestFunctionCatalog.java b/clients/client-java/src/test/java/org/apache/gravitino/client/TestFunctionCatalog.javaindex e6790fec2d..8786c98945 100644--- a/clients/client-java/src/test/java/org/apache/gravitino/client/TestFunctionCatalog.java+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/TestFunctionCatalog.java@@ -47,8 +47,13 @@ import org.apache.gravitino.exceptions.NoSuchFunctionException;import org.apache.gravitino.exceptions.NoSuchSchemaException;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionCatalog;+import org.apache.gravitino.function.FunctionDefinition;+import org.apache.gravitino.function.FunctionDefinitions;import org.apache.gravitino.function.FunctionImpl;+import org.apache.gravitino.function.FunctionImpls;+import org.apache.gravitino.function.FunctionParam;import org.apache.gravitino.function.FunctionType;+import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;import org.apache.hc.core5.http.Method;import org.junit.jupiter.api.Assertions;@@ -202,8 +207,7 @@ public class TestFunctionCatalog extends TestBase {"mock comment",FunctionType.SCALAR,true,- Types.StringType.get(),- mockFunction.definitions());+ FunctionDefinitions.of(mockDefinition(Types.StringType.get())));Assertions.assertNotNull(registeredFunction);assertFunction(mockFunction, registeredFunction);@@ -223,8 +227,7 @@ public class TestFunctionCatalog extends TestBase {"mock comment",FunctionType.SCALAR,true,- Types.StringType.get(),- mockFunction.definitions()),+ FunctionDefinitions.of(mockDefinition(Types.StringType.get()))),"function already exists");}@@ -284,6 +287,19 @@ public class TestFunctionCatalog extends TestBase {private static FunctionDTO mockFunctionDTO(String name, FunctionType functionType, String comment, boolean deterministic) {+ FunctionDefinitionDTO definition = mockDefinitionDTO(Types.StringType.get());++ return FunctionDTO.builder()+ .withName(name)+ .withFunctionType(functionType)+ .withComment(comment)+ .withDeterministic(deterministic)+ .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())+ .build();+ }++ private static FunctionDefinitionDTO mockDefinitionDTO(Type returnType) {FunctionParamDTO[] params =new FunctionParamDTO[] {FunctionParamDTO.builder()@@ -295,30 +311,38 @@ public class TestFunctionCatalog extends TestBase {SQLImplDTO impl =new SQLImplDTO(FunctionImpl.RuntimeType.SPARK.name(), null, null, "SELECT param1 + 1");- FunctionDefinitionDTO definition =- FunctionDefinitionDTO.builder()- .withParameters(params)- .withImpls(new FunctionImplDTO[] {impl})- .build();-- return FunctionDTO.builder()- .withName(name)- .withFunctionType(functionType)- .withComment(comment)- .withDeterministic(deterministic)- .withReturnType(Types.StringType.get())- .withDefinitions(new FunctionDefinitionDTO[] {definition})- .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())+ return FunctionDefinitionDTO.builder()+ .withParameters(params)+ .withReturnType(returnType)+ .withImpls(new FunctionImplDTO[] {impl}).build();}+ private static FunctionDefinition mockDefinition(Type returnType) {+ FunctionParam[] params =+ new FunctionParam[] {+ FunctionParamDTO.builder()+ .withName("param1")+ .withDataType(Types.IntegerType.get())+ .build()+ };++ FunctionImpl[] impls =+ new FunctionImpl[] {+ FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT param1 + 1")+ };++ return FunctionDefinitions.of(params, returnType, impls);+ }+private static void assertFunction(FunctionDTO expected, Function actual) {Assertions.assertEquals(expected.name(), actual.name());Assertions.assertEquals(expected.functionType(), actual.functionType());Assertions.assertEquals(expected.comment(), actual.comment());Assertions.assertEquals(expected.deterministic(), actual.deterministic());- Assertions.assertEquals(expected.returnType(), actual.returnType());Assertions.assertEquals(expected.definitions().length, actual.definitions().length);+ Assertions.assertEquals(+ expected.definitions()[0].returnType(), actual.definitions()[0].returnType());}private static String formatFunctionRequestPath(Namespace ns) {diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/FunctionIT.java b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/FunctionIT.javaindex 598c47a23a..3bd3599f2c 100644--- a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/FunctionIT.java+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/FunctionIT.java@@ -130,7 +130,8 @@ public class FunctionIT extends BaseIT {FunctionParams.of("x", Types.IntegerType.get(), null, Literals.integerLiteral(0));FunctionImpl impl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param}, new FunctionImpl[] {impl});+ FunctionDefinitions.of(+ new FunctionParam[] {param}, Types.IntegerType.get(), new FunctionImpl[] {impl});Function registered =functionCatalog.registerFunction(@@ -138,14 +139,13 @@ public class FunctionIT extends BaseIT {"Add one to input",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {definition});Assertions.assertEquals(functionName, registered.name());Assertions.assertEquals(FunctionType.SCALAR, registered.functionType());Assertions.assertTrue(registered.deterministic());Assertions.assertEquals("Add one to input", registered.comment());- Assertions.assertEquals(Types.IntegerType.get(), registered.returnType());+ Assertions.assertEquals(Types.IntegerType.get(), registered.definitions()[0].returnType());Assertions.assertEquals(1, registered.definitions().length);Function loaded = functionCatalog.getFunction(ident);@@ -153,7 +153,7 @@ public class FunctionIT extends BaseIT {Assertions.assertEquals(FunctionType.SCALAR, loaded.functionType());Assertions.assertTrue(loaded.deterministic());Assertions.assertEquals("Add one to input", loaded.comment());- Assertions.assertEquals(Types.IntegerType.get(), loaded.returnType());+ Assertions.assertEquals(Types.IntegerType.get(), loaded.definitions()[0].returnType());Assertions.assertTrue(functionCatalog.functionExists(ident));Assertions.assertFalse(@@ -165,7 +165,8 @@ public class FunctionIT extends BaseIT {FunctionImpl nonDetImpl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT RAND()");FunctionDefinition nonDetDefinition =- FunctionDefinitions.of(new FunctionParam[0], new FunctionImpl[] {nonDetImpl});+ FunctionDefinitions.of(+ new FunctionParam[0], Types.DoubleType.get(), new FunctionImpl[] {nonDetImpl});Function nonDetRegistered =functionCatalog.registerFunction(@@ -173,7 +174,6 @@ public class FunctionIT extends BaseIT {"Non-deterministic function",FunctionType.SCALAR,false,- Types.DoubleType.get(),new FunctionDefinition[] {nonDetDefinition});Assertions.assertFalse(nonDetRegistered.deterministic());@@ -185,18 +185,22 @@ public class FunctionIT extends BaseIT {FunctionParam tableParam = FunctionParams.of("n", Types.IntegerType.get());FunctionImpl tableImpl =FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.GenerateRowsUDTF");+ FunctionColumn[] returnColumns =+ new FunctionColumn[] {FunctionColumn.of("x", Types.StringType.get(), "comment")};FunctionDefinition tableDefinition =- FunctionDefinitions.of(new FunctionParam[] {tableParam}, new FunctionImpl[] {tableImpl});+ FunctionDefinitions.of(+ new FunctionParam[] {tableParam}, returnColumns, new FunctionImpl[] {tableImpl});Function tableRegistered =functionCatalog.registerFunction(tableFuncIdent,"Table function",+ FunctionType.TABLE,true,- new FunctionColumn[] {FunctionColumn.of("x", Types.StringType.get(), "comment")},new FunctionDefinition[] {tableDefinition});Assertions.assertEquals(FunctionType.TABLE, tableRegistered.functionType());+ Assertions.assertArrayEquals(returnColumns, tableRegistered.definitions()[0].returnColumns());}@Test@@ -208,15 +212,11 @@ public class FunctionIT extends BaseIT {FunctionParam param = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param}, new FunctionImpl[] {impl});+ FunctionDefinitions.of(+ new FunctionParam[] {param}, Types.IntegerType.get(), new FunctionImpl[] {impl});functionCatalog.registerFunction(- ident,- "comment",- FunctionType.SCALAR,- true,- Types.IntegerType.get(),- new FunctionDefinition[] {definition});+ ident, "comment", FunctionType.SCALAR, true, new FunctionDefinition[] {definition});Assertions.assertThrows(FunctionAlreadyExistsException.class,@@ -226,7 +226,6 @@ public class FunctionIT extends BaseIT {"comment",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {definition}));// Test 2: Register function with ambiguous definitions should fail@@ -247,12 +246,14 @@ public class FunctionIT extends BaseIT {FunctionDefinition def1 =FunctionDefinitions.of(new FunctionParam[] {intParam, floatParamWithDefault},+ Types.IntegerType.get(),new FunctionImpl[] {ambiguousImpl});// Definition 2: foo(int, string default 'x') supports arities: (int), (int, string)FunctionDefinition def2 =FunctionDefinitions.of(new FunctionParam[] {intParam, stringParamWithDefault},+ Types.IntegerType.get(),new FunctionImpl[] {ambiguousImpl});// Both definitions support call foo(1), so this should fail@@ -264,7 +265,6 @@ public class FunctionIT extends BaseIT {"Ambiguous function",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {def1, def2}));}@@ -294,7 +294,8 @@ public class FunctionIT extends BaseIT {FunctionParam param = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param}, new FunctionImpl[] {impl});+ FunctionDefinitions.of(+ new FunctionParam[] {param}, Types.IntegerType.get(), new FunctionImpl[] {impl});Function func1 =functionCatalog.registerFunction(@@ -302,7 +303,6 @@ public class FunctionIT extends BaseIT {"comment1",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {definition});Function func2 =@@ -311,7 +311,6 @@ public class FunctionIT extends BaseIT {"comment2",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {definition});// List functions@@ -340,15 +339,11 @@ public class FunctionIT extends BaseIT {FunctionParam param = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param}, new FunctionImpl[] {impl});+ FunctionDefinitions.of(+ new FunctionParam[] {param}, Types.IntegerType.get(), new FunctionImpl[] {impl});functionCatalog.registerFunction(- ident,- "comment",- FunctionType.SCALAR,- true,- Types.IntegerType.get(),- new FunctionDefinition[] {definition});+ ident, "comment", FunctionType.SCALAR, true, new FunctionDefinition[] {definition});// Function existsAssertions.assertTrue(functionCatalog.functionExists(ident));@@ -371,14 +366,14 @@ public class FunctionIT extends BaseIT {FunctionParam param = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param}, new FunctionImpl[] {impl});+ FunctionDefinitions.of(+ new FunctionParam[] {param}, Types.IntegerType.get(), new FunctionImpl[] {impl});functionCatalog.registerFunction(ident,"original comment",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {definition});// Alter comment@@ -401,22 +396,19 @@ public class FunctionIT extends BaseIT {FunctionParam param1 = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl1 = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition1 =- FunctionDefinitions.of(new FunctionParam[] {param1}, new FunctionImpl[] {impl1});+ FunctionDefinitions.of(+ new FunctionParam[] {param1}, Types.IntegerType.get(), new FunctionImpl[] {impl1});functionCatalog.registerFunction(- ident,- "comment",- FunctionType.SCALAR,- true,- Types.IntegerType.get(),- new FunctionDefinition[] {definition1});+ ident, "comment", FunctionType.SCALAR, true, new FunctionDefinition[] {definition1});// Add a new definition with different parameter typeFunctionParam param2 = FunctionParams.of("x", Types.StringType.get());FunctionImpl impl2 =FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT CONCAT(x, '_suffix')");FunctionDefinition definition2 =- FunctionDefinitions.of(new FunctionParam[] {param2}, new FunctionImpl[] {impl2});+ FunctionDefinitions.of(+ new FunctionParam[] {param2}, Types.StringType.get(), new FunctionImpl[] {impl2});Function altered =functionCatalog.alterFunction(ident, FunctionChange.addDefinition(definition2));@@ -433,15 +425,11 @@ public class FunctionIT extends BaseIT {FunctionParam param = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl sparkImpl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param}, new FunctionImpl[] {sparkImpl});+ FunctionDefinitions.of(+ new FunctionParam[] {param}, Types.IntegerType.get(), new FunctionImpl[] {sparkImpl});functionCatalog.registerFunction(- ident,- "comment",- FunctionType.SCALAR,- true,- Types.IntegerType.get(),- new FunctionDefinition[] {definition});+ ident, "comment", FunctionType.SCALAR, true, new FunctionDefinition[] {definition});// Test 1: Add Trino implementationFunctionImpl trinoImpl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.TRINO, "SELECT x + 1");@@ -495,7 +483,10 @@ public class FunctionIT extends BaseIT {FunctionImpl javaImpl =FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.AddOneUDF");FunctionDefinition javaDefinition =- FunctionDefinitions.of(new FunctionParam[] {javaParam}, new FunctionImpl[] {javaImpl});+ FunctionDefinitions.of(+ new FunctionParam[] {javaParam},+ Types.IntegerType.get(),+ new FunctionImpl[] {javaImpl});Function javaRegistered =functionCatalog.registerFunction(@@ -503,7 +494,6 @@ public class FunctionIT extends BaseIT {"Java UDF",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {javaDefinition});Assertions.assertEquals(javaFuncName, javaRegistered.name());@@ -523,7 +513,10 @@ public class FunctionIT extends BaseIT {null,null);FunctionDefinition pythonDefinition =- FunctionDefinitions.of(new FunctionParam[] {pythonParam}, new FunctionImpl[] {pythonImpl});+ FunctionDefinitions.of(+ new FunctionParam[] {pythonParam},+ Types.IntegerType.get(),+ new FunctionImpl[] {pythonImpl});Function pythonRegistered =functionCatalog.registerFunction(@@ -531,7 +524,6 @@ public class FunctionIT extends BaseIT {"Python UDF",FunctionType.SCALAR,true,- Types.IntegerType.get(),new FunctionDefinition[] {pythonDefinition});Assertions.assertEquals(pythonFuncName, pythonRegistered.name());@@ -545,13 +537,15 @@ public class FunctionIT extends BaseIT {FunctionParam param1 = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl1 = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition1 =- FunctionDefinitions.of(new FunctionParam[] {param1}, new FunctionImpl[] {impl1});+ FunctionDefinitions.of(+ new FunctionParam[] {param1}, Types.IntegerType.get(), new FunctionImpl[] {impl1});FunctionParam param2 = FunctionParams.of("x", Types.StringType.get());FunctionImpl impl2 =FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT CONCAT(x, '_suffix')");FunctionDefinition definition2 =- FunctionDefinitions.of(new FunctionParam[] {param2}, new FunctionImpl[] {impl2});+ FunctionDefinitions.of(+ new FunctionParam[] {param2}, Types.StringType.get(), new FunctionImpl[] {impl2});Function multiRegistered =functionCatalog.registerFunction(@@ -559,7 +553,6 @@ public class FunctionIT extends BaseIT {"Overloaded function",FunctionType.SCALAR,true,- Types.StringType.get(),new FunctionDefinition[] {definition1, definition2});Assertions.assertEquals(2, multiRegistered.definitions().length);@@ -574,20 +567,21 @@ public class FunctionIT extends BaseIT {FunctionParam param1 = FunctionParams.of("x", Types.IntegerType.get());FunctionImpl impl1 = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT x + 1");FunctionDefinition definition1 =- FunctionDefinitions.of(new FunctionParam[] {param1}, new FunctionImpl[] {impl1});+ FunctionDefinitions.of(+ new FunctionParam[] {param1}, Types.IntegerType.get(), new FunctionImpl[] {impl1});FunctionParam param2 = FunctionParams.of("x", Types.StringType.get());FunctionImpl impl2 =FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT CONCAT(x, '_suffix')");FunctionDefinition definition2 =- FunctionDefinitions.of(new FunctionParam[] {param2}, new FunctionImpl[] {impl2});+ FunctionDefinitions.of(+ new FunctionParam[] {param2}, Types.StringType.get(), new FunctionImpl[] {impl2});functionCatalog.registerFunction(ident,"comment",FunctionType.SCALAR,true,- Types.StringType.get(),new FunctionDefinition[] {definition1, definition2});// Remove one definitiondiff --git a/common/src/main/java/org/apache/gravitino/dto/function/FunctionDTO.java b/common/src/main/java/org/apache/gravitino/dto/function/FunctionDTO.javaindex 4fa5e391b7..f0e2a2e4ca 100644--- a/common/src/main/java/org/apache/gravitino/dto/function/FunctionDTO.java+++ b/common/src/main/java/org/apache/gravitino/dto/function/FunctionDTO.java@@ -19,8 +19,6 @@package org.apache.gravitino.dto.function;import com.fasterxml.jackson.annotation.JsonProperty;-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;-import com.fasterxml.jackson.databind.annotation.JsonSerialize;import java.util.Arrays;import javax.annotation.Nullable;import lombok.AllArgsConstructor;@@ -30,11 +28,8 @@ import lombok.NoArgsConstructor;import org.apache.gravitino.Audit;import org.apache.gravitino.dto.AuditDTO;import org.apache.gravitino.function.Function;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionType;-import org.apache.gravitino.json.JsonUtils;-import org.apache.gravitino.rel.types.Type;/** Represents a Function DTO (Data Transfer Object). */@NoArgsConstructor@@ -56,15 +51,6 @@ public class FunctionDTO implements Function {@JsonProperty("comment")private String comment;- @Nullable- @JsonProperty("returnType")- @JsonSerialize(using = JsonUtils.TypeSerializer.class)- @JsonDeserialize(using = JsonUtils.TypeDeserializer.class)- private Type returnType;-- @JsonProperty("returnColumns")- private FunctionColumnDTO[] returnColumns;-@JsonProperty("definitions")private FunctionDefinitionDTO[] definitions;@@ -91,21 +77,6 @@ public class FunctionDTO implements Function {return comment;}- @Override- public Type returnType() {- return returnType;- }-- @Override- public FunctionColumn[] returnColumns() {- if (returnColumns == null) {- return new FunctionColumn[0];- }- return Arrays.stream(returnColumns)- .map(FunctionColumnDTO::toFunctionColumn)- .toArray(FunctionColumn[]::new);- }-@Overridepublic FunctionDefinition[] definitions() {if (definitions == null) {@@ -132,10 +103,6 @@ public class FunctionDTO implements Function {+ ", comment='"+ comment+ '\''- + ", returnType="- + returnType- + ", returnColumns="- + Arrays.toString(returnColumns)+ ", definitions="+ Arrays.toString(definitions)+ ", audit="diff --git a/common/src/main/java/org/apache/gravitino/dto/function/FunctionDefinitionDTO.java b/common/src/main/java/org/apache/gravitino/dto/function/FunctionDefinitionDTO.javaindex 9182ae86db..bfc6b225b9 100644--- a/common/src/main/java/org/apache/gravitino/dto/function/FunctionDefinitionDTO.java+++ b/common/src/main/java/org/apache/gravitino/dto/function/FunctionDefinitionDTO.java@@ -19,17 +19,23 @@package org.apache.gravitino.dto.function;import com.fasterxml.jackson.annotation.JsonProperty;+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;+import com.fasterxml.jackson.databind.annotation.JsonSerialize;import java.util.Arrays;+import javax.annotation.Nullable;import lombok.AccessLevel;import lombok.AllArgsConstructor;import lombok.Builder;import lombok.EqualsAndHashCode;import lombok.Getter;import lombok.NoArgsConstructor;+import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionDefinitions;import org.apache.gravitino.function.FunctionImpl;import org.apache.gravitino.function.FunctionParam;+import org.apache.gravitino.json.JsonUtils;+import org.apache.gravitino.rel.types.Type;/** DTO for function definition. */@Getter@@ -42,6 +48,15 @@ public class FunctionDefinitionDTO implements FunctionDefinition {@JsonProperty("parameters")private FunctionParamDTO[] parameters;+ @Nullable+ @JsonProperty("returnType")+ @JsonSerialize(using = JsonUtils.TypeSerializer.class)+ @JsonDeserialize(using = JsonUtils.TypeDeserializer.class)+ private Type returnType;++ @JsonProperty("returnColumns")+ private FunctionColumnDTO[] returnColumns;+@JsonProperty("impls")private FunctionImplDTO[] impls;@@ -53,6 +68,21 @@ public class FunctionDefinitionDTO implements FunctionDefinition {return parameters;}+ @Override+ public Type returnType() {+ return returnType;+ }++ @Override+ public FunctionColumn[] returnColumns() {+ if (returnColumns == null) {+ return FunctionDefinition.EMPTY_COLUMNS;+ }+ return Arrays.stream(returnColumns)+ .map(FunctionColumnDTO::toFunctionColumn)+ .toArray(FunctionColumn[]::new);+ }+@Overridepublic FunctionImpl[] impls() {if (impls == null) {@@ -66,6 +96,7 @@ public class FunctionDefinitionDTO implements FunctionDefinition {** @return The function definition.*/+ @SuppressWarnings("deprecation")public FunctionDefinition toFunctionDefinition() {FunctionParam[] params =parameters == null@@ -79,7 +110,19 @@ public class FunctionDefinitionDTO implements FunctionDefinition {: Arrays.stream(impls).map(FunctionImplDTO::toFunctionImpl).toArray(FunctionImpl[]::new);- return FunctionDefinitions.of(params, implArr);++ if (returnType != null) {+ return FunctionDefinitions.of(params, returnType, implArr);+ } else if (returnColumns != null && returnColumns.length > 0) {+ FunctionColumn[] cols =+ Arrays.stream(returnColumns)+ .map(FunctionColumnDTO::toFunctionColumn)+ .toArray(FunctionColumn[]::new);+ return FunctionDefinitions.of(params, cols, implArr);+ } else {+ // Fallback for backward compatibility+ return FunctionDefinitions.of(params, implArr);+ }}/**@@ -99,13 +142,28 @@ public class FunctionDefinitionDTO implements FunctionDefinition {? (FunctionParamDTO) param: FunctionParamDTO.fromFunctionParam(param)).toArray(FunctionParamDTO[]::new);++ FunctionColumnDTO[] columnDTOs = null;+ if (definition.returnColumns() != null && definition.returnColumns().length > 0) {+ columnDTOs =+ Arrays.stream(definition.returnColumns())+ .map(FunctionColumnDTO::fromFunctionColumn)+ .toArray(FunctionColumnDTO[]::new);+ }+FunctionImplDTO[] implDTOs =definition.impls() == null? new FunctionImplDTO[0]: Arrays.stream(definition.impls()).map(FunctionImplDTO::fromFunctionImpl).toArray(FunctionImplDTO[]::new);- return new FunctionDefinitionDTO(paramDTOs, implDTOs);++ return FunctionDefinitionDTO.builder()+ .withParameters(paramDTOs)+ .withReturnType(definition.returnType())+ .withReturnColumns(columnDTOs)+ .withImpls(implDTOs)+ .build();}@Override@@ -113,6 +171,10 @@ public class FunctionDefinitionDTO implements FunctionDefinition {return "FunctionDefinitionDTO{"+ "parameters="+ Arrays.toString(parameters)+ + ", returnType="+ + returnType+ + ", returnColumns="+ + Arrays.toString(returnColumns)+ ", impls="+ Arrays.toString(impls)+ '}';diff --git a/common/src/main/java/org/apache/gravitino/dto/requests/FunctionRegisterRequest.java b/common/src/main/java/org/apache/gravitino/dto/requests/FunctionRegisterRequest.javaindex dc8c2c3841..24ea83b667 100644--- a/common/src/main/java/org/apache/gravitino/dto/requests/FunctionRegisterRequest.java+++ b/common/src/main/java/org/apache/gravitino/dto/requests/FunctionRegisterRequest.java@@ -19,8 +19,6 @@package org.apache.gravitino.dto.requests;import com.fasterxml.jackson.annotation.JsonProperty;-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;-import com.fasterxml.jackson.databind.annotation.JsonSerialize;import com.google.common.base.Preconditions;import javax.annotation.Nullable;import lombok.AllArgsConstructor;@@ -30,11 +28,8 @@ import lombok.Getter;import lombok.NoArgsConstructor;import lombok.ToString;import org.apache.commons.lang3.StringUtils;-import org.apache.gravitino.dto.function.FunctionColumnDTO;import org.apache.gravitino.dto.function.FunctionDefinitionDTO;import org.apache.gravitino.function.FunctionType;-import org.apache.gravitino.json.JsonUtils;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rest.RESTRequest;/** Represents a request to register a function. */@@ -59,16 +54,6 @@ public class FunctionRegisterRequest implements RESTRequest {@JsonProperty("comment")private String comment;- @Nullable- @JsonProperty("returnType")- @JsonSerialize(using = JsonUtils.TypeSerializer.class)- @JsonDeserialize(using = JsonUtils.TypeDeserializer.class)- private Type returnType;-- @Nullable- @JsonProperty("returnColumns")- private FunctionColumnDTO[] returnColumns;-@JsonProperty("definitions")private FunctionDefinitionDTO[] definitions;@@ -86,15 +71,19 @@ public class FunctionRegisterRequest implements RESTRequest {definitions != null && definitions.length > 0,"\"definitions\" field is required and cannot be empty");- if (functionType == FunctionType.TABLE) {- Preconditions.checkArgument(- returnColumns != null && returnColumns.length > 0,- "\"returnColumns\" is required for TABLE function type");- } else if (functionType == FunctionType.SCALAR || functionType == FunctionType.AGGREGATE) {- Preconditions.checkArgument(- returnType != null, "\"returnType\" is required for SCALAR or AGGREGATE function type");- } else {- throw new IllegalArgumentException("Unsupported function type: " + functionType);+ // Validate each definition has appropriate return type/columns based on function type+ for (FunctionDefinitionDTO definition : definitions) {+ if (functionType == FunctionType.TABLE) {+ Preconditions.checkArgument(+ definition.getReturnColumns() != null && definition.getReturnColumns().length > 0,+ "\"returnColumns\" is required in each definition for TABLE function type");+ } else if (functionType == FunctionType.SCALAR || functionType == FunctionType.AGGREGATE) {+ Preconditions.checkArgument(+ definition.getReturnType() != null,+ "\"returnType\" is required in each definition for SCALAR or AGGREGATE function type");+ } else {+ throw new IllegalArgumentException("Unsupported function type: " + functionType);+ }}}}diff --git a/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.javaindex a5a8792b2c..17e610223f 100644--- a/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java+++ b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java@@ -51,7 +51,6 @@ import org.apache.gravitino.dto.authorization.UserDTO;import org.apache.gravitino.dto.credential.CredentialDTO;import org.apache.gravitino.dto.file.FileInfoDTO;import org.apache.gravitino.dto.file.FilesetDTO;-import org.apache.gravitino.dto.function.FunctionColumnDTO;import org.apache.gravitino.dto.function.FunctionDTO;import org.apache.gravitino.dto.function.FunctionDefinitionDTO;import org.apache.gravitino.dto.job.JobTemplateDTO;@@ -737,14 +736,6 @@ public class DTOConverters {* @return The function DTO.*/public static FunctionDTO toDTO(Function function) {- FunctionColumnDTO[] returnColumnDTOs = null;- if (function.returnColumns() != null && function.returnColumns().length > 0) {- returnColumnDTOs =- Arrays.stream(function.returnColumns())- .map(FunctionColumnDTO::fromFunctionColumn)- .toArray(FunctionColumnDTO[]::new);- }-FunctionDefinitionDTO[] definitionDTOs = null;if (function.definitions() != null) {definitionDTOs =@@ -758,8 +749,6 @@ public class DTOConverters {.withFunctionType(function.functionType()).withDeterministic(function.deterministic()).withComment(function.comment())- .withReturnType(function.returnType())- .withReturnColumns(returnColumnDTOs).withDefinitions(definitionDTOs).withAudit(toDTO(function.auditInfo())).build();diff --git a/common/src/test/java/org/apache/gravitino/dto/function/TestFunctionDTO.java b/common/src/test/java/org/apache/gravitino/dto/function/TestFunctionDTO.javaindex be49db901a..5a414c602e 100644--- a/common/src/test/java/org/apache/gravitino/dto/function/TestFunctionDTO.java+++ b/common/src/test/java/org/apache/gravitino/dto/function/TestFunctionDTO.java@@ -61,10 +61,11 @@ public class TestFunctionDTO {ImmutableMap.of("key", "value"),"SELECT x + y");- // Create function definition+ // Create function definition with returnTypeFunctionDefinitionDTO definition =FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[] {param1, param2})+ .withReturnType(Types.FloatType.get()).withImpls(new FunctionImplDTO[] {sqlImpl}).build();@@ -75,7 +76,6 @@ public class TestFunctionDTO {.withFunctionType(FunctionType.SCALAR).withDeterministic(true).withComment("A simple add function")- .withReturnType(Types.FloatType.get()).withDefinitions(new FunctionDefinitionDTO[] {definition}).withAudit(audit).build();@@ -88,8 +88,9 @@ public class TestFunctionDTO {Assertions.assertEquals(scalarFunction.functionType(), deserialized.functionType());Assertions.assertEquals(scalarFunction.deterministic(), deserialized.deterministic());Assertions.assertEquals(scalarFunction.comment(), deserialized.comment());- Assertions.assertEquals(scalarFunction.returnType(), deserialized.returnType());Assertions.assertEquals(scalarFunction.definitions().length, deserialized.definitions().length);+ // Verify returnType is in definition+ Assertions.assertEquals(Types.FloatType.get(), deserialized.definitions()[0].returnType());}@Test@@ -117,10 +118,11 @@ public class TestFunctionDTO {ImmutableMap.of(),"com.example.TableFunction");- // Create function definition+ // Create function definition with returnColumnsFunctionDefinitionDTO definition =FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[] {})+ .withReturnColumns(new FunctionColumnDTO[] {col1, col2}).withImpls(new FunctionImplDTO[] {javaImpl}).build();@@ -131,7 +133,6 @@ public class TestFunctionDTO {.withFunctionType(FunctionType.TABLE).withDeterministic(false).withComment("A table function")- .withReturnColumns(new FunctionColumnDTO[] {col1, col2}).withDefinitions(new FunctionDefinitionDTO[] {definition}).withAudit(audit).build();@@ -142,7 +143,8 @@ public class TestFunctionDTO {Assertions.assertEquals(tableFunction.name(), deserialized.name());Assertions.assertEquals(FunctionType.TABLE, deserialized.functionType());- Assertions.assertEquals(2, deserialized.returnColumns().length);+ // Verify returnColumns is in definition+ Assertions.assertEquals(2, deserialized.definitions()[0].returnColumns().length);}@Test@@ -246,6 +248,7 @@ public class TestFunctionDTO {FunctionDefinitionDTO definition =FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[] {param})+ .withReturnType(Types.StringType.get()).withImpls(new FunctionImplDTO[] {impl}).build();@@ -256,5 +259,35 @@ public class TestFunctionDTO {Assertions.assertEquals(1, deserialized.parameters().length);Assertions.assertEquals("input", deserialized.parameters()[0].name());Assertions.assertEquals(1, deserialized.impls().length);+ Assertions.assertEquals(Types.StringType.get(), deserialized.returnType());+ }++ @Test+ public void testFunctionDefinitionDTOWithReturnColumns() throws JsonProcessingException {+ FunctionParamDTO param =+ FunctionParamDTO.builder().withName("n").withDataType(Types.IntegerType.get()).build();++ FunctionColumnDTO col1 =+ FunctionColumnDTO.builder().withName("id").withDataType(Types.IntegerType.get()).build();+ FunctionColumnDTO col2 =+ FunctionColumnDTO.builder().withName("value").withDataType(Types.StringType.get()).build();++ SQLImplDTO impl = new SQLImplDTO("SPARK", null, null, "SELECT id, value FROM t LIMIT n");++ FunctionDefinitionDTO definition =+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[] {param})+ .withReturnColumns(new FunctionColumnDTO[] {col1, col2})+ .withImpls(new FunctionImplDTO[] {impl})+ .build();++ String json = JsonUtils.objectMapper().writeValueAsString(definition);+ FunctionDefinitionDTO deserialized =+ JsonUtils.objectMapper().readValue(json, FunctionDefinitionDTO.class);++ Assertions.assertEquals(1, deserialized.parameters().length);+ Assertions.assertNull(deserialized.returnType());+ Assertions.assertEquals(2, deserialized.returnColumns().length);+ Assertions.assertEquals("id", deserialized.returnColumns()[0].name());}}diff --git a/common/src/test/java/org/apache/gravitino/dto/requests/TestFunctionRegisterRequest.java b/common/src/test/java/org/apache/gravitino/dto/requests/TestFunctionRegisterRequest.javaindex aaced9d58e..ff206e12fa 100644--- a/common/src/test/java/org/apache/gravitino/dto/requests/TestFunctionRegisterRequest.java+++ b/common/src/test/java/org/apache/gravitino/dto/requests/TestFunctionRegisterRequest.java@@ -41,6 +41,7 @@ public class TestFunctionRegisterRequest {FunctionDefinitionDTO definition =FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[] {param})+ .withReturnType(Types.IntegerType.get()).withImpls(new SQLImplDTO[] {impl}).build();@@ -50,7 +51,6 @@ public class TestFunctionRegisterRequest {.withFunctionType(FunctionType.SCALAR).withDeterministic(true).withComment("test function")- .withReturnType(Types.IntegerType.get()).withDefinitions(new FunctionDefinitionDTO[] {definition}).build();@@ -63,27 +63,33 @@ public class TestFunctionRegisterRequest {@Testpublic void testValidateScalarFunction() {- FunctionDefinitionDTO definition =- FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();+ // Definition with returnType for SCALAR function+ FunctionDefinitionDTO validDefinition =+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[0])+ .withReturnType(Types.IntegerType.get())+ .build();FunctionRegisterRequest validRequest =FunctionRegisterRequest.builder().withName("scalar_func").withFunctionType(FunctionType.SCALAR).withDeterministic(true)- .withReturnType(Types.IntegerType.get())- .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withDefinitions(new FunctionDefinitionDTO[] {validDefinition}).build();Assertions.assertDoesNotThrow(validRequest::validate);- // Missing returnType for SCALAR function+ // Definition without returnType for SCALAR function should fail+ FunctionDefinitionDTO invalidDefinition =+ FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();+FunctionRegisterRequest invalidRequest =FunctionRegisterRequest.builder().withName("scalar_func").withFunctionType(FunctionType.SCALAR).withDeterministic(true)- .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withDefinitions(new FunctionDefinitionDTO[] {invalidDefinition}).build();Assertions.assertThrows(IllegalArgumentException.class, invalidRequest::validate);@@ -91,27 +97,33 @@ public class TestFunctionRegisterRequest {@Testpublic void testValidateAggregateFunction() {- FunctionDefinitionDTO definition =- FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();+ // Definition with returnType for AGGREGATE function+ FunctionDefinitionDTO validDefinition =+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[0])+ .withReturnType(Types.IntegerType.get())+ .build();FunctionRegisterRequest validRequest =FunctionRegisterRequest.builder().withName("agg_func").withFunctionType(FunctionType.AGGREGATE).withDeterministic(true)- .withReturnType(Types.IntegerType.get())- .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withDefinitions(new FunctionDefinitionDTO[] {validDefinition}).build();Assertions.assertDoesNotThrow(validRequest::validate);- // Missing returnType for AGGREGATE function+ // Definition without returnType for AGGREGATE function should fail+ FunctionDefinitionDTO invalidDefinition =+ FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();+FunctionRegisterRequest invalidRequest =FunctionRegisterRequest.builder().withName("agg_func").withFunctionType(FunctionType.AGGREGATE).withDeterministic(true)- .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withDefinitions(new FunctionDefinitionDTO[] {invalidDefinition}).build();Assertions.assertThrows(IllegalArgumentException.class, invalidRequest::validate);@@ -119,30 +131,36 @@ public class TestFunctionRegisterRequest {@Testpublic void testValidateTableFunction() {- FunctionDefinitionDTO definition =- FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();-FunctionColumnDTO col =FunctionColumnDTO.builder().withName("id").withDataType(Types.IntegerType.get()).build();+ // Definition with returnColumns for TABLE function+ FunctionDefinitionDTO validDefinition =+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[0])+ .withReturnColumns(new FunctionColumnDTO[] {col})+ .build();+FunctionRegisterRequest validRequest =FunctionRegisterRequest.builder().withName("table_func").withFunctionType(FunctionType.TABLE).withDeterministic(false)- .withReturnColumns(new FunctionColumnDTO[] {col})- .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withDefinitions(new FunctionDefinitionDTO[] {validDefinition}).build();Assertions.assertDoesNotThrow(validRequest::validate);- // Missing returnColumns for TABLE function+ // Definition without returnColumns for TABLE function should fail+ FunctionDefinitionDTO invalidDefinition =+ FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();+FunctionRegisterRequest invalidRequest =FunctionRegisterRequest.builder().withName("table_func").withFunctionType(FunctionType.TABLE).withDeterministic(false)- .withDefinitions(new FunctionDefinitionDTO[] {definition})+ .withDefinitions(new FunctionDefinitionDTO[] {invalidDefinition}).build();Assertions.assertThrows(IllegalArgumentException.class, invalidRequest::validate);@@ -151,13 +169,15 @@ public class TestFunctionRegisterRequest {@Testpublic void testValidateMissingName() {FunctionDefinitionDTO definition =- FunctionDefinitionDTO.builder().withParameters(new FunctionParamDTO[0]).build();+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[0])+ .withReturnType(Types.IntegerType.get())+ .build();FunctionRegisterRequest invalidRequest =FunctionRegisterRequest.builder().withFunctionType(FunctionType.SCALAR).withDeterministic(true)- .withReturnType(Types.IntegerType.get()).withDefinitions(new FunctionDefinitionDTO[] {definition}).build();@@ -171,9 +191,40 @@ public class TestFunctionRegisterRequest {.withName("test_func").withFunctionType(FunctionType.SCALAR).withDeterministic(true)- .withReturnType(Types.IntegerType.get()).build();Assertions.assertThrows(IllegalArgumentException.class, invalidRequest::validate);}++ @Test+ public void testValidateMultipleDefinitionsWithDifferentReturnTypes() {+ // Test that multiple definitions can have different return types+ FunctionParamDTO intParam =+ FunctionParamDTO.builder().withName("x").withDataType(Types.IntegerType.get()).build();+ FunctionParamDTO floatParam =+ FunctionParamDTO.builder().withName("x").withDataType(Types.FloatType.get()).build();++ FunctionDefinitionDTO intDef =+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[] {intParam})+ .withReturnType(Types.IntegerType.get())+ .build();++ FunctionDefinitionDTO floatDef =+ FunctionDefinitionDTO.builder()+ .withParameters(new FunctionParamDTO[] {floatParam})+ .withReturnType(Types.FloatType.get())+ .build();++ FunctionRegisterRequest request =+ FunctionRegisterRequest.builder()+ .withName("overloaded_func")+ .withFunctionType(FunctionType.SCALAR)+ .withDeterministic(true)+ .withDefinitions(new FunctionDefinitionDTO[] {intDef, floatDef})+ .build();++ // This should succeed - different definitions can have different return types+ Assertions.assertDoesNotThrow(request::validate);+ }}diff --git a/core/src/main/java/org/apache/gravitino/catalog/FunctionNormalizeDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/FunctionNormalizeDispatcher.javaindex fa7317cc7c..810ca4ed5e 100644--- a/core/src/main/java/org/apache/gravitino/catalog/FunctionNormalizeDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/catalog/FunctionNormalizeDispatcher.java@@ -31,10 +31,8 @@ import org.apache.gravitino.exceptions.NoSuchFunctionException;import org.apache.gravitino.exceptions.NoSuchSchemaException;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionChange;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionType;-import org.apache.gravitino.rel.types.Type;/*** {@code FunctionNormalizeDispatcher} normalizes function identifiers and namespaces by applying@@ -77,28 +75,10 @@ public class FunctionNormalizeDispatcher implements FunctionDispatcher {String comment,FunctionType functionType,boolean deterministic,- Type returnType,FunctionDefinition[] definitions)throws NoSuchSchemaException, FunctionAlreadyExistsException {return dispatcher.registerFunction(- normalizeNameIdentifier(ident),- comment,- functionType,- deterministic,- returnType,- definitions);- }-- @Override- public Function registerFunction(- NameIdentifier ident,- String comment,- boolean deterministic,- FunctionColumn[] returnColumns,- FunctionDefinition[] definitions)- throws NoSuchSchemaException, FunctionAlreadyExistsException {- return dispatcher.registerFunction(- normalizeNameIdentifier(ident), comment, deterministic, returnColumns, definitions);+ normalizeNameIdentifier(ident), comment, functionType, deterministic, definitions);}@Overridediff --git a/core/src/main/java/org/apache/gravitino/catalog/FunctionOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/FunctionOperationDispatcher.javaindex d02894d35d..7d88196887 100644--- a/core/src/main/java/org/apache/gravitino/catalog/FunctionOperationDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/catalog/FunctionOperationDispatcher.java@@ -28,12 +28,10 @@ import org.apache.gravitino.exceptions.NoSuchFunctionException;import org.apache.gravitino.exceptions.NoSuchSchemaException;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionChange;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionType;import org.apache.gravitino.lock.LockType;import org.apache.gravitino.lock.TreeLockUtils;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.storage.IdGenerator;/**@@ -110,14 +108,15 @@ public class FunctionOperationDispatcher extends OperationDispatcher implements}/**- * Register a scalar or aggregate function with one or more definitions (overloads).+ * Register a function with one or more definitions (overloads). Each definition contains its own+ * return type (for scalar/aggregate functions) or return columns (for table-valued functions).** @param ident The function identifier.* @param comment The optional function comment.- * @param functionType The function type.+ * @param functionType The function type (SCALAR, AGGREGATE, or TABLE).* @param deterministic Whether the function is deterministic.- * @param returnType The return type.- * @param definitions The function definitions.+ * @param definitions The function definitions, each containing parameters, return type/columns,+ * and implementations.* @return The registered function.* @throws NoSuchSchemaException If the schema does not exist.* @throws FunctionAlreadyExistsException If the function already exists.@@ -128,51 +127,9 @@ public class FunctionOperationDispatcher extends OperationDispatcher implementsString comment,FunctionType functionType,boolean deterministic,- Type returnType,FunctionDefinition[] definitions)throws NoSuchSchemaException, FunctionAlreadyExistsException {- Preconditions.checkArgument(- functionType == FunctionType.SCALAR || functionType == FunctionType.AGGREGATE,- "This method is for scalar or aggregate functions only");- Preconditions.checkArgument(returnType != null, "Return type is required");- Preconditions.checkArgument(- definitions != null && definitions.length > 0, "At least one definition is required");-- NameIdentifier schemaIdent = NameIdentifier.of(ident.namespace().levels());- // Validate schema exists in the underlying catalog- schemaOps.loadSchema(schemaIdent);-- return TreeLockUtils.doWithTreeLock(- ident,- LockType.WRITE,- () ->- managedFunctionOps.registerFunction(- ident, comment, functionType, deterministic, returnType, definitions));- }-- /**- * Register a table-valued function with one or more definitions (overloads).- *- * @param ident The function identifier.- * @param comment The optional function comment.- * @param deterministic Whether the function is deterministic.- * @param returnColumns The return columns.- * @param definitions The function definitions.- * @return The registered function.- * @throws NoSuchSchemaException If the schema does not exist.- * @throws FunctionAlreadyExistsException If the function already exists.- */- @Override- public Function registerFunction(- NameIdentifier ident,- String comment,- boolean deterministic,- FunctionColumn[] returnColumns,- FunctionDefinition[] definitions)- throws NoSuchSchemaException, FunctionAlreadyExistsException {- Preconditions.checkArgument(- returnColumns != null && returnColumns.length > 0,- "At least one return column is required for table-valued function");+ Preconditions.checkArgument(functionType != null, "Function type is required");Preconditions.checkArgument(definitions != null && definitions.length > 0, "At least one definition is required");@@ -185,7 +142,7 @@ public class FunctionOperationDispatcher extends OperationDispatcher implementsLockType.WRITE,() ->managedFunctionOps.registerFunction(- ident, comment, deterministic, returnColumns, definitions));+ ident, comment, functionType, deterministic, definitions));}/**diff --git a/core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java b/core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.javaindex 778cc4ed09..067d68c131 100644--- a/core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java+++ b/core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java@@ -27,7 +27,6 @@ import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;-import java.util.Optional;import java.util.Set;import java.util.stream.Collectors;import org.apache.gravitino.Entity;@@ -42,7 +41,6 @@ import org.apache.gravitino.exceptions.NoSuchSchemaException;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionCatalog;import org.apache.gravitino.function.FunctionChange;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionDefinitions;import org.apache.gravitino.function.FunctionImpl;@@ -52,7 +50,6 @@ import org.apache.gravitino.meta.AuditInfo;import org.apache.gravitino.meta.FunctionEntity;import org.apache.gravitino.rel.Column;import org.apache.gravitino.rel.expressions.Expression;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.storage.IdGenerator;import org.apache.gravitino.utils.PrincipalUtils;@@ -122,35 +119,9 @@ public class ManagedFunctionOperations implements FunctionCatalog {String comment,FunctionType functionType,boolean deterministic,- Type returnType,FunctionDefinition[] definitions)throws NoSuchSchemaException, FunctionAlreadyExistsException {- return doRegisterFunction(- ident,- comment,- functionType,- deterministic,- Optional.of(returnType),- Optional.empty(),- definitions);- }-- @Override- public Function registerFunction(- NameIdentifier ident,- String comment,- boolean deterministic,- FunctionColumn[] returnColumns,- FunctionDefinition[] definitions)- throws NoSuchSchemaException, FunctionAlreadyExistsException {- return doRegisterFunction(- ident,- comment,- FunctionType.TABLE,- deterministic,- Optional.empty(),- Optional.of(returnColumns),- definitions);+ return doRegisterFunction(ident, comment, functionType, deterministic, definitions);}@Override@@ -188,8 +159,6 @@ public class ManagedFunctionOperations implements FunctionCatalog {String comment,FunctionType functionType,boolean deterministic,- Optional<Type> returnType,- Optional<FunctionColumn[]> returnColumns,FunctionDefinition[] definitions)throws NoSuchSchemaException, FunctionAlreadyExistsException {Preconditions.checkArgument(@@ -209,8 +178,6 @@ public class ManagedFunctionOperations implements FunctionCatalog {.withComment(comment).withFunctionType(functionType).withDeterministic(deterministic)- .withReturnType(returnType.orElse(null))- .withReturnColumns(returnColumns.orElse(null)).withDefinitions(definitions).withAuditInfo(auditInfo).build();@@ -321,8 +288,6 @@ public class ManagedFunctionOperations implements FunctionCatalog {.withComment(newComment).withFunctionType(oldEntity.functionType()).withDeterministic(oldEntity.deterministic())- .withReturnType(oldEntity.returnType())- .withReturnColumns(oldEntity.returnColumns()).withDefinitions(newDefinitions.toArray(new FunctionDefinition[0])).withAuditInfo(newAuditInfo).build();@@ -492,7 +457,7 @@ public class ManagedFunctionOperations implements FunctionCatalog {}List<FunctionImpl> impls = new ArrayList<>(Arrays.asList(def.impls()));impls.add(implToAdd);- result.add(FunctionDefinitions.of(def.parameters(), impls.toArray(new FunctionImpl[0])));+ result.add(rebuildDefinitionWithNewImpls(def, impls.toArray(new FunctionImpl[0])));} else {result.add(def);}@@ -527,7 +492,7 @@ public class ManagedFunctionOperations implements FunctionCatalog {impls.add(impl);}}- result.add(FunctionDefinitions.of(def.parameters(), impls.toArray(new FunctionImpl[0])));+ result.add(rebuildDefinitionWithNewImpls(def, impls.toArray(new FunctionImpl[0])));} else {result.add(def);}@@ -575,7 +540,7 @@ public class ManagedFunctionOperations implements FunctionCatalog {impls.add(impl);}}- result.add(FunctionDefinitions.of(def.parameters(), impls.toArray(new FunctionImpl[0])));+ result.add(rebuildDefinitionWithNewImpls(def, impls.toArray(new FunctionImpl[0])));} else {result.add(def);}@@ -594,4 +559,20 @@ public class ManagedFunctionOperations implements FunctionCatalog {return result;}++ /**+ * Rebuilds a FunctionDefinition with new implementations while preserving+ * returnType/returnColumns.+ */+ @SuppressWarnings("deprecation")+ private FunctionDefinition rebuildDefinitionWithNewImpls(+ FunctionDefinition original, FunctionImpl[] newImpls) {+ if (original.returnType() != null) {+ return FunctionDefinitions.of(original.parameters(), original.returnType(), newImpls);+ } else if (original.returnColumns() != null && original.returnColumns().length > 0) {+ return FunctionDefinitions.of(original.parameters(), original.returnColumns(), newImpls);+ } else {+ return FunctionDefinitions.of(original.parameters(), newImpls);+ }+ }}diff --git a/core/src/main/java/org/apache/gravitino/meta/FunctionEntity.java b/core/src/main/java/org/apache/gravitino/meta/FunctionEntity.javaindex e8fb9d9d6b..041702b17a 100644--- a/core/src/main/java/org/apache/gravitino/meta/FunctionEntity.java+++ b/core/src/main/java/org/apache/gravitino/meta/FunctionEntity.java@@ -30,10 +30,8 @@ import org.apache.gravitino.Field;import org.apache.gravitino.HasIdentifier;import org.apache.gravitino.Namespace;import org.apache.gravitino.function.Function;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;import org.apache.gravitino.function.FunctionType;-import org.apache.gravitino.rel.types.Type;/** A class representing a function entity in the metadata store. */@ToString@@ -49,14 +47,6 @@ public class FunctionEntity implements Entity, Auditable, HasIdentifier, FunctioField.required("function_type", FunctionType.class, "The type of the function.");public static final Field DETERMINISTIC =Field.required("deterministic", Boolean.class, "Whether the function is deterministic.");- public static final Field RETURN_TYPE =- Field.optional(- "return_type", Type.class, "The return type for scalar or aggregate functions.");- public static final Field RETURN_COLUMNS =- Field.optional(- "return_columns",- FunctionColumn[].class,- "The output columns for table-valued functions.");public static final Field DEFINITIONS =Field.required("definitions", FunctionDefinition[].class, "The definitions of the function.");public static final Field AUDIT_INFO =@@ -68,8 +58,6 @@ public class FunctionEntity implements Entity, Auditable, HasIdentifier, Functioprivate String comment;private FunctionType functionType;private boolean deterministic;- private Type returnType;- private FunctionColumn[] returnColumns;private FunctionDefinition[] definitions;private AuditInfo auditInfo;@@ -83,8 +71,6 @@ public class FunctionEntity implements Entity, Auditable, HasIdentifier, Functiofields.put(COMMENT, comment);fields.put(FUNCTION_TYPE, functionType);fields.put(DETERMINISTIC, deterministic);- fields.put(RETURN_TYPE, returnType);- fields.put(RETURN_COLUMNS, returnColumns);fields.put(DEFINITIONS, definitions);fields.put(AUDIT_INFO, auditInfo);@@ -121,16 +107,6 @@ public class FunctionEntity implements Entity, Auditable, HasIdentifier, Functioreturn deterministic;}- @Override- public Type returnType() {- return returnType;- }-- @Override- public FunctionColumn[] returnColumns() {- return returnColumns != null ? returnColumns : new FunctionColumn[0];- }-@Overridepublic FunctionDefinition[] definitions() {return definitions;@@ -163,18 +139,13 @@ public class FunctionEntity implements Entity, Auditable, HasIdentifier, Functio&& Objects.equals(comment, that.comment)&& functionType == that.functionType&& deterministic == that.deterministic- && Objects.equals(returnType, that.returnType)- && Arrays.equals(returnColumns, that.returnColumns)&& Arrays.equals(definitions, that.definitions)&& Objects.equals(auditInfo, that.auditInfo);}@Overridepublic int hashCode() {- int result =- Objects.hash(- id, name, namespace, comment, functionType, deterministic, returnType, auditInfo);- result = 31 * result + Arrays.hashCode(returnColumns);+ int result = Objects.hash(id, name, namespace, comment, functionType, deterministic, auditInfo);result = 31 * result + Arrays.hashCode(definitions);return result;}@@ -262,28 +233,6 @@ public class FunctionEntity implements Entity, Auditable, HasIdentifier, Functioreturn this;}- /**- * Sets the return type for scalar or aggregate functions.- *- * @param returnType The return type.- * @return This builder instance.- */- public Builder withReturnType(Type returnType) {- functionEntity.returnType = returnType;- return this;- }-- /**- * Sets the return columns for table-valued functions.- *- * @param returnColumns The output columns.- * @return This builder instance.- */- public Builder withReturnColumns(FunctionColumn[] returnColumns) {- functionEntity.returnColumns = returnColumns;- return this;- }-/*** Sets the function definitions.*diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FunctionMetaMapper.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FunctionMetaMapper.javaindex a57b40cc8a..ad50f07799 100644--- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FunctionMetaMapper.java+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FunctionMetaMapper.java@@ -70,7 +70,6 @@ public interface FunctionMetaMapper {@Result(property = "schemaId", column = "schema_id"),@Result(property = "functionType", column = "function_type"),@Result(property = "deterministic", column = "deterministic"),- @Result(property = "returnType", column = "return_type"),@Result(property = "functionCurrentVersion", column = "function_current_version"),@Result(property = "functionLatestVersion", column = "function_latest_version"),@Result(property = "auditInfo", column = "audit_info"),@@ -96,7 +95,6 @@ public interface FunctionMetaMapper {@Result(property = "schemaId", column = "schema_id"),@Result(property = "functionType", column = "function_type"),@Result(property = "deterministic", column = "deterministic"),- @Result(property = "returnType", column = "return_type"),@Result(property = "functionCurrentVersion", column = "function_current_version"),@Result(property = "functionLatestVersion", column = "function_latest_version"),@Result(property = "auditInfo", column = "audit_info"),diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/FunctionMetaBaseSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/FunctionMetaBaseSQLProvider.javaindex 772b76cdc5..ecd11a5232 100644--- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/FunctionMetaBaseSQLProvider.java+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/FunctionMetaBaseSQLProvider.java@@ -42,7 +42,6 @@ public class FunctionMetaBaseSQLProvider {fm.function_name,fm.function_type,fm.deterministic,- fm.return_type,fm.function_current_version,fm.function_latest_version,fm.audit_info,@@ -90,12 +89,12 @@ public class FunctionMetaBaseSQLProvider {return "INSERT INTO "+ TABLE_NAME+ " (function_id, function_name, metalake_id, catalog_id, schema_id,"- + " function_type, `deterministic`, return_type, function_current_version,"+ + " function_type, `deterministic`, function_current_version,"+ " function_latest_version, audit_info, deleted_at)"+ " VALUES (#{functionMeta.functionId}, #{functionMeta.functionName},"+ " #{functionMeta.metalakeId}, #{functionMeta.catalogId}, #{functionMeta.schemaId},"+ " #{functionMeta.functionType}, #{functionMeta.deterministic},"- + " #{functionMeta.returnType}, #{functionMeta.functionCurrentVersion},"+ + " #{functionMeta.functionCurrentVersion},"+ " #{functionMeta.functionLatestVersion}, #{functionMeta.auditInfo},"+ " #{functionMeta.deletedAt})";}@@ -105,12 +104,12 @@ public class FunctionMetaBaseSQLProvider {return "INSERT INTO "+ TABLE_NAME+ " (function_id, function_name, metalake_id, catalog_id, schema_id,"- + " function_type, `deterministic`, return_type,"+ + " function_type, `deterministic`,"+ " function_current_version, function_latest_version, audit_info, deleted_at)"+ " VALUES (#{functionMeta.functionId}, #{functionMeta.functionName},"+ " #{functionMeta.metalakeId}, #{functionMeta.catalogId}, #{functionMeta.schemaId},"+ " #{functionMeta.functionType}, #{functionMeta.deterministic},"- + " #{functionMeta.returnType}, #{functionMeta.functionCurrentVersion},"+ + " #{functionMeta.functionCurrentVersion},"+ " #{functionMeta.functionLatestVersion}, #{functionMeta.auditInfo},"+ " #{functionMeta.deletedAt})"+ " ON DUPLICATE KEY UPDATE"@@ -120,7 +119,6 @@ public class FunctionMetaBaseSQLProvider {+ " schema_id = #{functionMeta.schemaId},"+ " function_type = #{functionMeta.functionType},"+ " `deterministic` = #{functionMeta.deterministic},"- + " return_type = #{functionMeta.returnType},"+ " function_current_version = #{functionMeta.functionCurrentVersion},"+ " function_latest_version = #{functionMeta.functionLatestVersion},"+ " audit_info = #{functionMeta.auditInfo},"@@ -141,7 +139,6 @@ public class FunctionMetaBaseSQLProvider {fm.function_name,fm.function_type,fm.deterministic,- fm.return_type,fm.function_current_version,fm.function_latest_version,fm.audit_info,@@ -188,7 +185,7 @@ public class FunctionMetaBaseSQLProvider {public String listFunctionPOsBySchemaId(@Param("schemaId") Long schemaId) {return "SELECT fm.function_id, fm.function_name, fm.metalake_id, fm.catalog_id, fm.schema_id,"- + " fm.function_type, fm.`deterministic`, fm.return_type,"+ + " fm.function_type, fm.`deterministic`,"+ " fm.function_current_version, fm.function_latest_version,"+ " fm.audit_info, fm.deleted_at,"+ " vi.id, vi.metalake_id as version_metalake_id, vi.catalog_id as version_catalog_id,"@@ -206,7 +203,7 @@ public class FunctionMetaBaseSQLProvider {public String selectFunctionMetaBySchemaIdAndName(@Param("schemaId") Long schemaId, @Param("functionName") String functionName) {return "SELECT fm.function_id, fm.function_name, fm.metalake_id, fm.catalog_id, fm.schema_id,"- + " fm.function_type, fm.`deterministic`, fm.return_type,"+ + " fm.function_type, fm.`deterministic`,"+ " fm.function_current_version, fm.function_latest_version,"+ " fm.audit_info, fm.deleted_at,"+ " vi.id, vi.metalake_id as version_metalake_id, vi.catalog_id as version_catalog_id,"@@ -272,7 +269,6 @@ public class FunctionMetaBaseSQLProvider {+ " schema_id = #{newFunctionMeta.schemaId},"+ " function_type = #{newFunctionMeta.functionType},"+ " `deterministic` = #{newFunctionMeta.deterministic},"- + " return_type = #{newFunctionMeta.returnType},"+ " function_current_version = #{newFunctionMeta.functionCurrentVersion},"+ " function_latest_version = #{newFunctionMeta.functionLatestVersion},"+ " audit_info = #{newFunctionMeta.auditInfo},"diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/FunctionMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/FunctionMetaPostgreSQLProvider.javaindex e112cd0e31..0e285e4147 100644--- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/FunctionMetaPostgreSQLProvider.java+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/FunctionMetaPostgreSQLProvider.java@@ -30,10 +30,10 @@ public class FunctionMetaPostgreSQLProvider extends FunctionMetaBaseSQLProviderreturn "INSERT INTO "+ FunctionMetaMapper.TABLE_NAME+ " (function_id, function_name, metalake_id, catalog_id, schema_id,"- + " function_type, \"deterministic\", return_type, function_current_version, function_latest_version, audit_info, deleted_at)"+ + " function_type, \"deterministic\", function_current_version, function_latest_version, audit_info, deleted_at)"+ " VALUES (#{functionMeta.functionId}, #{functionMeta.functionName}, #{functionMeta.metalakeId},"+ " #{functionMeta.catalogId}, #{functionMeta.schemaId}, #{functionMeta.functionType},"- + " #{functionMeta.deterministic}, #{functionMeta.returnType},"+ + " #{functionMeta.deterministic},"+ " #{functionMeta.functionCurrentVersion}, #{functionMeta.functionLatestVersion}, #{functionMeta.auditInfo},"+ " #{functionMeta.deletedAt})";}@@ -44,10 +44,10 @@ public class FunctionMetaPostgreSQLProvider extends FunctionMetaBaseSQLProviderreturn "INSERT INTO "+ FunctionMetaMapper.TABLE_NAME+ " (function_id, function_name, metalake_id, catalog_id, schema_id,"- + " function_type, \"deterministic\", return_type, function_current_version, function_latest_version, audit_info, deleted_at)"+ + " function_type, \"deterministic\", function_current_version, function_latest_version, audit_info, deleted_at)"+ " VALUES (#{functionMeta.functionId}, #{functionMeta.functionName}, #{functionMeta.metalakeId},"+ " #{functionMeta.catalogId}, #{functionMeta.schemaId}, #{functionMeta.functionType},"- + " #{functionMeta.deterministic}, #{functionMeta.returnType},"+ + " #{functionMeta.deterministic},"+ " #{functionMeta.functionCurrentVersion}, #{functionMeta.functionLatestVersion}, #{functionMeta.auditInfo},"+ " #{functionMeta.deletedAt})"+ " ON CONFLICT (function_id) DO UPDATE SET"@@ -57,7 +57,6 @@ public class FunctionMetaPostgreSQLProvider extends FunctionMetaBaseSQLProvider+ " schema_id = #{functionMeta.schemaId},"+ " function_type = #{functionMeta.functionType},"+ " \"deterministic\" = #{functionMeta.deterministic},"- + " return_type = #{functionMeta.returnType},"+ " function_current_version = #{functionMeta.functionCurrentVersion},"+ " function_latest_version = #{functionMeta.functionLatestVersion},"+ " audit_info = #{functionMeta.auditInfo},"@@ -67,7 +66,7 @@ public class FunctionMetaPostgreSQLProvider extends FunctionMetaBaseSQLProvider@Overridepublic String listFunctionPOsBySchemaId(@Param("schemaId") Long schemaId) {return "SELECT fm.function_id, fm.function_name, fm.metalake_id, fm.catalog_id, fm.schema_id,"- + " fm.function_type, fm.\"deterministic\", fm.return_type, fm.function_current_version, fm.function_latest_version,"+ + " fm.function_type, fm.\"deterministic\", fm.function_current_version, fm.function_latest_version,"+ " fm.audit_info, fm.deleted_at,"+ " vi.id, vi.metalake_id as version_metalake_id, vi.catalog_id as version_catalog_id,"+ " vi.schema_id as version_schema_id, vi.function_id as version_function_id,"@@ -85,7 +84,7 @@ public class FunctionMetaPostgreSQLProvider extends FunctionMetaBaseSQLProviderpublic String selectFunctionMetaBySchemaIdAndName(@Param("schemaId") Long schemaId, @Param("functionName") String functionName) {return "SELECT fm.function_id, fm.function_name, fm.metalake_id, fm.catalog_id, fm.schema_id,"- + " fm.function_type, fm.\"deterministic\", fm.return_type, fm.function_current_version, fm.function_latest_version,"+ + " fm.function_type, fm.\"deterministic\", fm.function_current_version, fm.function_latest_version,"+ " fm.audit_info, fm.deleted_at,"+ " vi.id, vi.metalake_id as version_metalake_id, vi.catalog_id as version_catalog_id,"+ " vi.schema_id as version_schema_id, vi.function_id as version_function_id,"@@ -154,7 +153,6 @@ public class FunctionMetaPostgreSQLProvider extends FunctionMetaBaseSQLProvider+ " schema_id = #{newFunctionMeta.schemaId},"+ " function_type = #{newFunctionMeta.functionType},"+ " \"deterministic\" = #{newFunctionMeta.deterministic},"- + " return_type = #{newFunctionMeta.returnType},"+ " function_current_version = #{newFunctionMeta.functionCurrentVersion},"+ " function_latest_version = #{newFunctionMeta.functionLatestVersion},"+ " audit_info = #{newFunctionMeta.auditInfo},"diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/po/FunctionPO.java b/core/src/main/java/org/apache/gravitino/storage/relational/po/FunctionPO.javaindex 4cc3c47e09..764b5e10f5 100644--- a/core/src/main/java/org/apache/gravitino/storage/relational/po/FunctionPO.java+++ b/core/src/main/java/org/apache/gravitino/storage/relational/po/FunctionPO.java@@ -40,7 +40,6 @@ import org.apache.gravitino.json.JsonUtils;import org.apache.gravitino.meta.AuditInfo;import org.apache.gravitino.meta.FunctionEntity;import org.apache.gravitino.meta.NamespacedEntityId;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.storage.relational.service.EntityIdService;@EqualsAndHashCode@@ -65,8 +64,6 @@ public class FunctionPO {private Integer deterministic;- private String returnType;-private Integer functionLatestVersion;private Integer functionCurrentVersion;@@ -92,7 +89,6 @@ public class FunctionPO {Long schemaId,String functionType,Integer deterministic,- String returnType,Integer functionLatestVersion,Integer functionCurrentVersion,String auditInfo,@@ -120,7 +116,6 @@ public class FunctionPO {this.schemaId = schemaId;this.functionType = functionType;this.deterministic = deterministic;- this.returnType = returnType;this.functionLatestVersion = functionLatestVersion;this.functionCurrentVersion = functionCurrentVersion;this.auditInfo = auditInfo;@@ -151,7 +146,6 @@ public class FunctionPO {.withComment(versionPO.functionComment()).withFunctionType(FunctionType.valueOf(functionPO.functionType())).withDeterministic(functionPO.deterministic() != null && functionPO.deterministic() == 1)- .withReturnType(JsonUtils.anyFieldMapper().readValue(functionPO.returnType(), Type.class)).withDefinitions(definitions).withAuditInfo(JsonUtils.anyFieldMapper().readValue(functionPO.auditInfo(), AuditInfo.class))@@ -208,8 +202,6 @@ public class FunctionPO {.withFunctionName(functionEntity.name()).withFunctionType(functionEntity.functionType().name()).withDeterministic(functionEntity.deterministic() ? 1 : 0)- .withReturnType(- JsonUtils.anyFieldMapper().writeValueAsString(functionEntity.returnType())).withFunctionVersionPO(versionPO).withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(functionEntity.auditInfo())).withDeletedAt(DEFAULT_DELETED_AT)diff --git a/core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.java b/core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.javaindex 9a759cb28b..28a12ae951 100644--- a/core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.java+++ b/core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.java@@ -49,6 +49,7 @@ import org.apache.gravitino.function.FunctionType;import org.apache.gravitino.function.JavaImpl;import org.apache.gravitino.meta.FunctionEntity;import org.apache.gravitino.rel.expressions.literals.Literals;+import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;import org.apache.gravitino.storage.IdGenerator;import org.apache.gravitino.storage.RandomIdGenerator;@@ -79,15 +80,11 @@ public class TestManagedFunctionOperations {public void testRegisterAndListFunctions() {NameIdentifier func1Ident = getFunctionIdent("func1");FunctionParam[] params1 = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions1 = new FunctionDefinition[] {createSimpleDefinition(params1)};+ FunctionDefinition[] definitions1 =+ new FunctionDefinition[] {createSimpleDefinition(params1, Types.StringType.get())};functionOperations.registerFunction(- func1Ident,- "Test function 1",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions1);+ func1Ident, "Test function 1", FunctionType.SCALAR, true, definitions1);NameIdentifier func2Ident = getFunctionIdent("func2");FunctionParam[] params2 =@@ -95,15 +92,11 @@ public class TestManagedFunctionOperations {FunctionParams.of("x", Types.StringType.get()),FunctionParams.of("y", Types.StringType.get())};- FunctionDefinition[] definitions2 = new FunctionDefinition[] {createSimpleDefinition(params2)};+ FunctionDefinition[] definitions2 =+ new FunctionDefinition[] {createSimpleDefinition(params2, Types.IntegerType.get())};functionOperations.registerFunction(- func2Ident,- "Test function 2",- FunctionType.SCALAR,- false,- Types.IntegerType.get(),- definitions2);+ func2Ident, "Test function 2", FunctionType.SCALAR, false, definitions2);// List functionsNameIdentifier[] functionIdents = functionOperations.listFunctions(getFunctionNamespace());@@ -120,22 +113,18 @@ public class TestManagedFunctionOperations {NameIdentifier funcIdent = getFunctionIdent("my_func");FunctionParam[] params =new FunctionParam[] {FunctionParams.of("input", Types.StringType.get())};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.IntegerType.get())};Function newFunc =functionOperations.registerFunction(- funcIdent,- "My test function",- FunctionType.SCALAR,- true,- Types.IntegerType.get(),- definitions);+ funcIdent, "My test function", FunctionType.SCALAR, true, definitions);Assertions.assertEquals("my_func", newFunc.name());Assertions.assertEquals("My test function", newFunc.comment());Assertions.assertEquals(FunctionType.SCALAR, newFunc.functionType());Assertions.assertTrue(newFunc.deterministic());- Assertions.assertEquals(Types.IntegerType.get(), newFunc.returnType());+ Assertions.assertEquals(Types.IntegerType.get(), newFunc.definitions()[0].returnType());// Get functionFunction loadedFunc = functionOperations.getFunction(funcIdent);@@ -147,12 +136,7 @@ public class TestManagedFunctionOperations {FunctionAlreadyExistsException.class,() ->functionOperations.registerFunction(- funcIdent,- "Another function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions));+ funcIdent, "Another function", FunctionType.SCALAR, true, definitions));// Test get non-existing functionNameIdentifier nonExistingIdent = getFunctionIdent("non_existing_func");@@ -164,15 +148,11 @@ public class TestManagedFunctionOperations {public void testRegisterAndDropFunction() {NameIdentifier funcIdent = getFunctionIdent("func_to_drop");FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};functionOperations.registerFunction(- funcIdent,- "Function to drop",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions);+ funcIdent, "Function to drop", FunctionType.SCALAR, true, definitions);// Drop the functionboolean dropped = functionOperations.dropFunction(funcIdent);@@ -190,15 +170,11 @@ public class TestManagedFunctionOperations {public void testAlterFunctionUpdateComment() {NameIdentifier funcIdent = getFunctionIdent("func_to_alter");FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};functionOperations.registerFunction(- funcIdent,- "Original comment",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions);+ funcIdent, "Original comment", FunctionType.SCALAR, true, definitions);// Update commentString newComment = "Updated comment";@@ -216,15 +192,11 @@ public class TestManagedFunctionOperations {public void testAlterFunctionAddDefinition() {NameIdentifier funcIdent = getFunctionIdent("func_add_def");FunctionParam[] params1 = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions1 = new FunctionDefinition[] {createSimpleDefinition(params1)};+ FunctionDefinition[] definitions1 =+ new FunctionDefinition[] {createSimpleDefinition(params1, Types.StringType.get())};functionOperations.registerFunction(- funcIdent,- "Test function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions1);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions1);// Add a new definition with different parametersFunctionParam[] params2 =@@ -232,7 +204,7 @@ public class TestManagedFunctionOperations {FunctionParams.of("a", Types.IntegerType.get()),FunctionParams.of("b", Types.StringType.get())};- FunctionDefinition newDef = createSimpleDefinition(params2);+ FunctionDefinition newDef = createSimpleDefinition(params2, Types.StringType.get());org.apache.gravitino.function.Function updatedFunc =functionOperations.alterFunction(funcIdent, FunctionChange.addDefinition(newDef));@@ -250,15 +222,11 @@ public class TestManagedFunctionOperations {FunctionParams.of("a", Types.IntegerType.get()),FunctionParams.of("b", Types.FloatType.get(), null, Literals.floatLiteral(1.0f))};- FunctionDefinition[] definitions1 = new FunctionDefinition[] {createSimpleDefinition(params1)};+ FunctionDefinition[] definitions1 =+ new FunctionDefinition[] {createSimpleDefinition(params1, Types.StringType.get())};functionOperations.registerFunction(- funcIdent,- "Test function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions1);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions1);// Try to add definition: foo(int, string default 'x') which supports (int) and (int, string)// This should fail because both support the call foo(int)@@ -267,7 +235,7 @@ public class TestManagedFunctionOperations {FunctionParams.of("a", Types.IntegerType.get()),FunctionParams.of("c", Types.StringType.get(), null, Literals.stringLiteral("x"))};- FunctionDefinition newDef = createSimpleDefinition(params2);+ FunctionDefinition newDef = createSimpleDefinition(params2, Types.StringType.get());Assertions.assertThrows(IllegalArgumentException.class,@@ -291,18 +259,16 @@ public class TestManagedFunctionOperations {};FunctionDefinition[] definitions =- new FunctionDefinition[] {createSimpleDefinition(params1), createSimpleDefinition(params2)};+ new FunctionDefinition[] {+ createSimpleDefinition(params1, Types.StringType.get()),+ createSimpleDefinition(params2, Types.StringType.get())+ };Assertions.assertThrows(IllegalArgumentException.class,() ->functionOperations.registerFunction(- funcIdent,- "Test function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions));+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions));}@Test@@ -318,7 +284,7 @@ public class TestManagedFunctionOperations {FunctionParams.of("c", Types.IntegerType.get(), "param c", Literals.integerLiteral(2))};FunctionDefinition[] definitions =- new FunctionDefinition[] {createSimpleDefinition(invalidParams)};+ new FunctionDefinition[] {createSimpleDefinition(invalidParams, Types.StringType.get())};// Should throw IllegalArgumentException when trying to registerIllegalArgumentException ex =@@ -326,12 +292,7 @@ public class TestManagedFunctionOperations {IllegalArgumentException.class,() ->functionOperations.registerFunction(- funcIdent,- "Invalid function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions));+ funcIdent, "Invalid function", FunctionType.SCALAR, true, definitions));Assertions.assertTrue(ex.getMessage().contains("Invalid parameter order"),@@ -352,16 +313,11 @@ public class TestManagedFunctionOperations {FunctionParams.of("d", Types.IntegerType.get(), "param d", Literals.integerLiteral(2))};FunctionDefinition[] validDefinitions =- new FunctionDefinition[] {createSimpleDefinition(validParams)};+ new FunctionDefinition[] {createSimpleDefinition(validParams, Types.StringType.get())};// This should succeedfunctionOperations.registerFunction(- funcIdent,- "Valid function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- validDefinitions);+ funcIdent, "Valid function", FunctionType.SCALAR, true, validDefinitions);// Verify the function was registeredFunction func = functionOperations.getFunction(funcIdent);@@ -379,17 +335,15 @@ public class TestManagedFunctionOperations {FunctionParam[] params2 = new FunctionParam[] {FunctionParams.of("a", Types.StringType.get())};FunctionDefinition[] definitions =- new FunctionDefinition[] {createSimpleDefinition(params1), createSimpleDefinition(params2)};+ new FunctionDefinition[] {+ createSimpleDefinition(params1, Types.StringType.get()),+ createSimpleDefinition(params2, Types.StringType.get())+ };// Should succeed - no arity overlapFunction func =functionOperations.registerFunction(- funcIdent,- "Non-overlapping function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions);+ funcIdent, "Non-overlapping function", FunctionType.SCALAR, true, definitions);Assertions.assertNotNull(func);Assertions.assertEquals(2, func.definitions().length);@@ -401,16 +355,12 @@ public class TestManagedFunctionOperations {NameIdentifier funcIdent = getFunctionIdent("func_no_args");FunctionParam[] params = new FunctionParam[] {};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};Function func =functionOperations.registerFunction(- funcIdent,- "No args function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions);+ funcIdent, "No args function", FunctionType.SCALAR, true, definitions);Assertions.assertNotNull(func);Assertions.assertEquals(0, func.definitions()[0].parameters().length);@@ -429,16 +379,12 @@ public class TestManagedFunctionOperations {FunctionParams.of("b", Types.FloatType.get(), "param b", Literals.floatLiteral(1.0f)),FunctionParams.of("c", Types.StringType.get(), "param c", Literals.stringLiteral("x"))};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};Function func =functionOperations.registerFunction(- funcIdent,- "Multi default function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions);+ funcIdent, "Multi default function", FunctionType.SCALAR, true, definitions);Assertions.assertNotNull(func);Assertions.assertEquals(3, func.definitions()[0].parameters().length);@@ -462,17 +408,15 @@ public class TestManagedFunctionOperations {};FunctionDefinition[] definitions =- new FunctionDefinition[] {createSimpleDefinition(params1), createSimpleDefinition(params2)};+ new FunctionDefinition[] {+ createSimpleDefinition(params1, Types.StringType.get()),+ createSimpleDefinition(params2, Types.StringType.get())+ };// Should succeed - arities are "integer,integer" vs "string,string"Function func =functionOperations.registerFunction(- funcIdent,- "Same arity different types",- FunctionType.SCALAR,- true,- Types.StringType.get(),- definitions);+ funcIdent, "Same arity different types", FunctionType.SCALAR, true, definitions);Assertions.assertNotNull(func);Assertions.assertEquals(2, func.definitions().length);@@ -486,10 +430,13 @@ public class TestManagedFunctionOperations {FunctionParam[] params1 = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};FunctionParam[] params2 = new FunctionParam[] {FunctionParams.of("b", Types.StringType.get())};FunctionDefinition[] definitions =- new FunctionDefinition[] {createSimpleDefinition(params1), createSimpleDefinition(params2)};+ new FunctionDefinition[] {+ createSimpleDefinition(params1, Types.StringType.get()),+ createSimpleDefinition(params2, Types.StringType.get())+ };functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Remove one definitionFunction updatedFunc =@@ -502,10 +449,11 @@ public class TestManagedFunctionOperations {public void testAlterFunctionRemoveOnlyDefinition() {NameIdentifier funcIdent = getFunctionIdent("func_remove_only");FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to remove the only definition - should failAssertions.assertThrows(@@ -517,10 +465,11 @@ public class TestManagedFunctionOperations {public void testAlterFunctionRemoveNonExistingDefinition() {NameIdentifier funcIdent = getFunctionIdent("func_remove_nonexist");FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to remove a definition that doesn't existFunctionParam[] nonExistingParams =@@ -541,11 +490,11 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})+ createDefinitionWithImpls(params, Types.StringType.get(), new FunctionImpl[] {sparkImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Add Trino implementationFunctionImpl trinoImpl =@@ -564,11 +513,11 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})+ createDefinitionWithImpls(params, Types.StringType.get(), new FunctionImpl[] {sparkImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to add another Spark implementation - should failFunctionImpl anotherSparkImpl =@@ -585,10 +534,11 @@ public class TestManagedFunctionOperations {public void testAlterFunctionAddImplToNonExistingDefinition() {NameIdentifier funcIdent = getFunctionIdent("func_add_impl_nodef");FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};- FunctionDefinition[] definitions = new FunctionDefinition[] {createSimpleDefinition(params)};+ FunctionDefinition[] definitions =+ new FunctionDefinition[] {createSimpleDefinition(params, Types.StringType.get())};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to add impl to non-existing definitionFunctionParam[] nonExistingParams =@@ -611,11 +561,11 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.OldSparkUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})+ createDefinitionWithImpls(params, Types.StringType.get(), new FunctionImpl[] {sparkImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Update Spark implementationFunctionImpl newSparkImpl =@@ -641,11 +591,11 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})+ createDefinitionWithImpls(params, Types.StringType.get(), new FunctionImpl[] {sparkImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to update Trino implementation which doesn't existFunctionImpl trinoImpl =@@ -669,11 +619,12 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.TRINO, "com.example.TrinoUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl, trinoImpl})+ createDefinitionWithImpls(+ params, Types.StringType.get(), new FunctionImpl[] {sparkImpl, trinoImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Remove Spark implementationorg.apache.gravitino.function.Function updatedFunc =@@ -693,11 +644,11 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})+ createDefinitionWithImpls(params, Types.StringType.get(), new FunctionImpl[] {sparkImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to remove the only implementation - should failAssertions.assertThrows(@@ -715,11 +666,11 @@ public class TestManagedFunctionOperations {FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");FunctionDefinition[] definitions =new FunctionDefinition[] {- createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})+ createDefinitionWithImpls(params, Types.StringType.get(), new FunctionImpl[] {sparkImpl})};functionOperations.registerFunction(- funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);+ funcIdent, "Test function", FunctionType.SCALAR, true, definitions);// Try to remove Trino implementation which doesn't existAssertions.assertThrows(@@ -749,15 +700,10 @@ public class TestManagedFunctionOperations {FunctionParam[] initialParams =new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};FunctionDefinition[] initialDefinitions =- new FunctionDefinition[] {createSimpleDefinition(initialParams)};+ new FunctionDefinition[] {createSimpleDefinition(initialParams, Types.StringType.get())};functionOperations.registerFunction(- funcIdent,- "Initial function",- FunctionType.SCALAR,- true,- Types.StringType.get(),- initialDefinitions);+ funcIdent, "Initial function", FunctionType.SCALAR, true, initialDefinitions);// Try to add a definition with invalid parameter orderFunctionParam[] invalidParams =@@ -772,7 +718,8 @@ public class TestManagedFunctionOperations {() ->functionOperations.alterFunction(funcIdent,- FunctionChange.addDefinition(createSimpleDefinition(invalidParams))));+ FunctionChange.addDefinition(+ createSimpleDefinition(invalidParams, Types.StringType.get()))));Assertions.assertTrue(ex.getMessage().contains("Invalid parameter order"),@@ -904,12 +851,21 @@ public class TestManagedFunctionOperations {}private FunctionDefinition createSimpleDefinition(FunctionParam[] params) {+ return createSimpleDefinition(params, Types.StringType.get());+ }++ private FunctionDefinition createSimpleDefinition(FunctionParam[] params, Type returnType) {FunctionImpl impl = FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.TestUDF");- return FunctionDefinitions.of(params, new FunctionImpl[] {impl});+ return FunctionDefinitions.of(params, returnType, new FunctionImpl[] {impl});}private FunctionDefinition createDefinitionWithImpls(FunctionParam[] params, FunctionImpl[] impls) {- return FunctionDefinitions.of(params, impls);+ return createDefinitionWithImpls(params, Types.StringType.get(), impls);+ }++ private FunctionDefinition createDefinitionWithImpls(+ FunctionParam[] params, Type returnType, FunctionImpl[] impls) {+ return FunctionDefinitions.of(params, returnType, impls);}}diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/po/TestFunctionPO.java b/core/src/test/java/org/apache/gravitino/storage/relational/po/TestFunctionPO.javaindex a44c367e68..efbd6bd005 100644--- a/core/src/test/java/org/apache/gravitino/storage/relational/po/TestFunctionPO.java+++ b/core/src/test/java/org/apache/gravitino/storage/relational/po/TestFunctionPO.java@@ -34,7 +34,6 @@ public class TestFunctionPO {.withSchemaId(1L).withFunctionType("SCALAR").withDeterministic(1)- .withReturnType("STRING").withFunctionLatestVersion(1).withFunctionCurrentVersion(1).withAuditInfo("audit-info")@@ -48,7 +47,6 @@ public class TestFunctionPO {Assertions.assertEquals(1L, functionPO.schemaId());Assertions.assertEquals("SCALAR", functionPO.functionType());Assertions.assertEquals(1, functionPO.deterministic());- Assertions.assertEquals("STRING", functionPO.returnType());Assertions.assertEquals(1, functionPO.functionLatestVersion());Assertions.assertEquals(1, functionPO.functionCurrentVersion());Assertions.assertEquals("audit-info", functionPO.auditInfo());@@ -103,7 +101,6 @@ public class TestFunctionPO {.withSchemaId(1L).withFunctionType("SCALAR").withDeterministic(1)- .withReturnType("STRING").withFunctionLatestVersion(1).withFunctionCurrentVersion(1).withAuditInfo("audit-info")@@ -119,7 +116,6 @@ public class TestFunctionPO {.withSchemaId(1L).withFunctionType("SCALAR").withDeterministic(1)- .withReturnType("STRING").withFunctionLatestVersion(1).withFunctionCurrentVersion(1).withAuditInfo("audit-info")diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestFunctionMetaService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestFunctionMetaService.javaindex 5cc4c225ac..99c6fd78af 100644--- a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestFunctionMetaService.java+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestFunctionMetaService.java@@ -136,7 +136,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("updated comment").withFunctionType(function.functionType()).withDeterministic(function.deterministic())- .withReturnType(function.returnType()).withDefinitions(function.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -197,7 +196,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("updated comment").withFunctionType(function.functionType()).withDeterministic(true)- .withReturnType(function.returnType()).withDefinitions(function.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -263,7 +261,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("version 2 comment").withFunctionType(function.functionType()).withDeterministic(function.deterministic())- .withReturnType(function.returnType()).withDefinitions(function.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -300,7 +297,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("another function v2").withFunctionType(anotherFunction.functionType()).withDeterministic(anotherFunction.deterministic())- .withReturnType(anotherFunction.returnType()).withDefinitions(anotherFunction.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -314,7 +310,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("another function v3").withFunctionType(anotherFunction.functionType()).withDeterministic(anotherFunction.deterministic())- .withReturnType(anotherFunction.returnType()).withDefinitions(anotherFunction.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -391,7 +386,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("version " + version).withFunctionType(function.functionType()).withDeterministic(function.deterministic())- .withReturnType(function.returnType()).withDefinitions(function.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -441,7 +435,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("overwritten comment").withFunctionType(function.functionType()).withDeterministic(true)- .withReturnType(function.returnType()).withDefinitions(function.definitions()).withAuditInfo(AUDIT_INFO).build();@@ -461,7 +454,10 @@ public class TestFunctionMetaService extends TestJDBCBackend {FunctionParam param2 = FunctionParams.of("param2", Types.StringType.get());FunctionImpl impl = FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT param1 + 1");FunctionDefinition definition =- FunctionDefinitions.of(new FunctionParam[] {param1, param2}, new FunctionImpl[] {impl});+ FunctionDefinitions.of(+ new FunctionParam[] {param1, param2},+ Types.IntegerType.get(),+ new FunctionImpl[] {impl});return FunctionEntity.builder().withId(id)@@ -470,7 +466,6 @@ public class TestFunctionMetaService extends TestJDBCBackend {.withComment("test function comment").withFunctionType(FunctionType.SCALAR).withDeterministic(false)- .withReturnType(Types.IntegerType.get()).withDefinitions(new FunctionDefinition[] {definition}).withAuditInfo(auditInfo).build();diff --git a/scripts/h2/schema-1.2.0-h2.sql b/scripts/h2/schema-1.2.0-h2.sqlindex 4065ca170d..9bf2ea2892 100644--- a/scripts/h2/schema-1.2.0-h2.sql+++ b/scripts/h2/schema-1.2.0-h2.sql@@ -452,7 +452,6 @@ CREATE TABLE IF NOT EXISTS `function_meta` (`schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',`function_type` VARCHAR(64) NOT NULL COMMENT 'function type',`deterministic` TINYINT(1) DEFAULT 1 COMMENT 'whether the function result is deterministic',- `return_type` CLOB NOT NULL COMMENT 'function return type',`function_current_version` INT UNSIGNED DEFAULT 1 COMMENT 'function current version',`function_latest_version` INT UNSIGNED DEFAULT 1 COMMENT 'function latest version',`audit_info` CLOB NOT NULL COMMENT 'function audit info',diff --git a/scripts/h2/upgrade-1.1.0-to-1.2.0-h2.sql b/scripts/h2/upgrade-1.1.0-to-1.2.0-h2.sqlindex b011cf17e0..65b05958fe 100644--- a/scripts/h2/upgrade-1.1.0-to-1.2.0-h2.sql+++ b/scripts/h2/upgrade-1.1.0-to-1.2.0-h2.sql@@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS `function_meta` (`schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',`function_type` VARCHAR(64) NOT NULL COMMENT 'function type',`deterministic` TINYINT(1) DEFAULT 1 COMMENT 'whether the function result is deterministic',- `return_type` CLOB NOT NULL COMMENT 'function return type',`function_current_version` INT UNSIGNED DEFAULT 1 COMMENT 'function current version',`function_latest_version` INT UNSIGNED DEFAULT 1 COMMENT 'function latest version',`audit_info` CLOB NOT NULL COMMENT 'function audit info',diff --git a/scripts/mysql/schema-1.2.0-mysql.sql b/scripts/mysql/schema-1.2.0-mysql.sqlindex d795558a1f..e0fa45cd39 100644--- a/scripts/mysql/schema-1.2.0-mysql.sql+++ b/scripts/mysql/schema-1.2.0-mysql.sql@@ -443,7 +443,6 @@ CREATE TABLE IF NOT EXISTS `function_meta` (`schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',`function_type` VARCHAR(64) NOT NULL COMMENT 'function type',`deterministic` TINYINT(1) DEFAULT 1 COMMENT 'whether the function result is deterministic',- `return_type` TEXT NOT NULL COMMENT 'function return type',`function_current_version` INT UNSIGNED DEFAULT 1 COMMENT 'function current version',`function_latest_version` INT UNSIGNED DEFAULT 1 COMMENT 'function latest version',`audit_info` MEDIUMTEXT NOT NULL COMMENT 'function audit info',diff --git a/scripts/mysql/upgrade-1.1.0-to-1.2.0-mysql.sql b/scripts/mysql/upgrade-1.1.0-to-1.2.0-mysql.sqlindex 120af6bfa2..0de595267f 100644--- a/scripts/mysql/upgrade-1.1.0-to-1.2.0-mysql.sql+++ b/scripts/mysql/upgrade-1.1.0-to-1.2.0-mysql.sql@@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS `function_meta` (`schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',`function_type` VARCHAR(64) NOT NULL COMMENT 'function type',`deterministic` TINYINT(1) DEFAULT 1 COMMENT 'whether the function result is deterministic',- `return_type` TEXT NOT NULL COMMENT 'function return type',`function_current_version` INT UNSIGNED DEFAULT 1 COMMENT 'function current version',`function_latest_version` INT UNSIGNED DEFAULT 1 COMMENT 'function latest version',`audit_info` MEDIUMTEXT NOT NULL COMMENT 'function audit info',diff --git a/scripts/postgresql/schema-1.2.0-postgresql.sql b/scripts/postgresql/schema-1.2.0-postgresql.sqlindex 268b1f1c8c..6c2c189504 100644--- a/scripts/postgresql/schema-1.2.0-postgresql.sql+++ b/scripts/postgresql/schema-1.2.0-postgresql.sql@@ -782,7 +782,6 @@ CREATE TABLE IF NOT EXISTS function_meta (schema_id BIGINT NOT NULL,function_type VARCHAR(64) NOT NULL,deterministic SMALLINT DEFAULT 1,- return_type TEXT NOT NULL,function_current_version INT DEFAULT 1,function_latest_version INT DEFAULT 1,audit_info TEXT NOT NULL,@@ -801,7 +800,6 @@ COMMENT ON COLUMN function_meta.catalog_id IS 'catalog id';COMMENT ON COLUMN function_meta.schema_id IS 'schema id';COMMENT ON COLUMN function_meta.function_type IS 'function type';COMMENT ON COLUMN function_meta.deterministic IS 'whether the function result is deterministic';-COMMENT ON COLUMN function_meta.return_type IS 'function return type';COMMENT ON COLUMN function_meta.function_latest_version IS 'function latest version';COMMENT ON COLUMN function_meta.audit_info IS 'function audit info';COMMENT ON COLUMN function_meta.deleted_at IS 'function deleted at';diff --git a/scripts/postgresql/upgrade-1.1.0-to-1.2.0-postgresql.sql b/scripts/postgresql/upgrade-1.1.0-to-1.2.0-postgresql.sqlindex b04c0dcaa7..7aa6bda401 100644--- a/scripts/postgresql/upgrade-1.1.0-to-1.2.0-postgresql.sql+++ b/scripts/postgresql/upgrade-1.1.0-to-1.2.0-postgresql.sql@@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS function_meta (schema_id BIGINT NOT NULL,function_type VARCHAR(64) NOT NULL,deterministic SMALLINT DEFAULT 1,- return_type TEXT NOT NULL,function_current_version INT DEFAULT 1,function_latest_version INT DEFAULT 1,audit_info TEXT NOT NULL,@@ -44,7 +43,6 @@ COMMENT ON COLUMN function_meta.catalog_id IS 'catalog id';COMMENT ON COLUMN function_meta.schema_id IS 'schema id';COMMENT ON COLUMN function_meta.function_type IS 'function type';COMMENT ON COLUMN function_meta.deterministic IS 'whether the function result is deterministic';-COMMENT ON COLUMN function_meta.return_type IS 'function return type';COMMENT ON COLUMN function_meta.function_latest_version IS 'function latest version';COMMENT ON COLUMN function_meta.audit_info IS 'function audit info';COMMENT ON COLUMN function_meta.deleted_at IS 'function deleted at';diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/FunctionOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/FunctionOperations.javaindex 4330754314..da59cc238c 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/FunctionOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/FunctionOperations.java@@ -37,7 +37,6 @@ import javax.ws.rs.core.Response;import org.apache.gravitino.NameIdentifier;import org.apache.gravitino.Namespace;import org.apache.gravitino.catalog.FunctionDispatcher;-import org.apache.gravitino.dto.function.FunctionColumnDTO;import org.apache.gravitino.dto.function.FunctionDTO;import org.apache.gravitino.dto.function.FunctionDefinitionDTO;import org.apache.gravitino.dto.requests.FunctionRegisterRequest;@@ -50,11 +49,8 @@ import org.apache.gravitino.dto.responses.FunctionResponse;import org.apache.gravitino.dto.util.DTOConverters;import org.apache.gravitino.function.Function;import org.apache.gravitino.function.FunctionChange;-import org.apache.gravitino.function.FunctionColumn;import org.apache.gravitino.function.FunctionDefinition;-import org.apache.gravitino.function.FunctionType;import org.apache.gravitino.metrics.MetricNames;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.server.web.Utils;import org.apache.gravitino.utils.NameIdentifierUtil;import org.apache.gravitino.utils.NamespaceUtil;@@ -150,30 +146,13 @@ public class FunctionOperations {.map(FunctionDefinitionDTO::toFunctionDefinition).toArray(FunctionDefinition[]::new);- Function function;- if (request.getFunctionType() == FunctionType.TABLE) {- FunctionColumn[] returnColumns =- Arrays.stream(request.getReturnColumns())- .map(FunctionColumnDTO::toFunctionColumn)- .toArray(FunctionColumn[]::new);- function =- dispatcher.registerFunction(- ident,- request.getComment(),- request.isDeterministic(),- returnColumns,- definitions);- } else {- Type returnType = request.getReturnType();- function =- dispatcher.registerFunction(- ident,- request.getComment(),- request.getFunctionType(),- request.isDeterministic(),- returnType,- definitions);- }+ Function function =+ dispatcher.registerFunction(+ ident,+ request.getComment(),+ request.getFunctionType(),+ request.isDeterministic(),+ definitions);Response response = Utils.ok(new FunctionResponse(DTOConverters.toDTO(function)));LOG.info(diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestFunctionOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestFunctionOperations.javaindex 67a173270a..65cf114ab1 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestFunctionOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestFunctionOperations.java@@ -64,7 +64,6 @@ import org.apache.gravitino.function.FunctionParam;import org.apache.gravitino.function.FunctionParams;import org.apache.gravitino.function.FunctionType;import org.apache.gravitino.meta.AuditInfo;-import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;import org.apache.gravitino.rest.RESTUtils;import org.apache.gravitino.utils.NameIdentifierUtil;@@ -277,18 +276,16 @@ public class TestFunctionOperations extends BaseOperationsTest {anyString(),eq(FunctionType.SCALAR),anyBoolean(),- any(Type.class),any(FunctionDefinition[].class))).thenReturn(mockFunction);- FunctionDefinitionDTO[] definitionDTOs = createMockDefinitionDTOs();+ FunctionDefinitionDTO[] definitionDTOs = createMockScalarDefinitionDTOs();FunctionRegisterRequest req =FunctionRegisterRequest.builder().withName("func1").withComment("test comment").withFunctionType(FunctionType.SCALAR).withDeterministic(true)- .withReturnType(Types.IntegerType.get()).withDefinitions(definitionDTOs).build();@@ -313,7 +310,6 @@ public class TestFunctionOperations extends BaseOperationsTest {anyString(),eq(FunctionType.SCALAR),anyBoolean(),- any(Type.class),any(FunctionDefinition[].class));Response resp1 =@@ -336,7 +332,6 @@ public class TestFunctionOperations extends BaseOperationsTest {anyString(),eq(FunctionType.SCALAR),anyBoolean(),- any(Type.class),any(FunctionDefinition[].class));Response resp2 =@@ -360,7 +355,6 @@ public class TestFunctionOperations extends BaseOperationsTest {anyString(),eq(FunctionType.SCALAR),anyBoolean(),- any(Type.class),any(FunctionDefinition[].class));Response resp3 =@@ -385,8 +379,8 @@ public class TestFunctionOperations extends BaseOperationsTest {when(functionDispatcher.registerFunction(eq(funcId),anyString(),+ eq(FunctionType.TABLE),anyBoolean(),- any(FunctionColumn[].class),any(FunctionDefinition[].class))).thenReturn(mockFunction);@@ -396,8 +390,7 @@ public class TestFunctionOperations extends BaseOperationsTest {.withComment("test comment").withFunctionType(FunctionType.TABLE).withDeterministic(true)- .withReturnColumns(createMockReturnColumnDTOs())- .withDefinitions(createMockDefinitionDTOs())+ .withDefinitions(createMockTableDefinitionDTOs()).build();Response resp =@@ -501,7 +494,7 @@ public class TestFunctionOperations extends BaseOperationsTest {NameIdentifier funcId = NameIdentifierUtil.ofFunction(metalake, catalog, schema, "func1");Function mockFunction = mockFunction("func1", "comment", FunctionType.SCALAR);- FunctionDefinitionDTO newDef = createMockDefinitionDTOs()[0];+ FunctionDefinitionDTO newDef = createMockScalarDefinitionDTOs()[0];FunctionChange addDef = FunctionChange.addDefinition(newDef.toFunctionDefinition());when(functionDispatcher.alterFunction(funcId, addDef)).thenReturn(mockFunction);@@ -666,9 +659,7 @@ public class TestFunctionOperations extends BaseOperationsTest {when(mockFunction.comment()).thenReturn(comment);when(mockFunction.functionType()).thenReturn(functionType);when(mockFunction.deterministic()).thenReturn(true);- when(mockFunction.returnType()).thenReturn(Types.IntegerType.get());- when(mockFunction.returnColumns()).thenReturn(new FunctionColumn[0]);- when(mockFunction.definitions()).thenReturn(createMockDefinitions());+ when(mockFunction.definitions()).thenReturn(createMockScalarDefinitions());when(mockFunction.auditInfo()).thenReturn(testAuditInfo);return mockFunction;}@@ -679,27 +670,50 @@ public class TestFunctionOperations extends BaseOperationsTest {when(mockFunction.comment()).thenReturn(comment);when(mockFunction.functionType()).thenReturn(FunctionType.TABLE);when(mockFunction.deterministic()).thenReturn(true);- when(mockFunction.returnType()).thenReturn(null);- when(mockFunction.returnColumns()).thenReturn(createMockReturnColumns());- when(mockFunction.definitions()).thenReturn(createMockDefinitions());+ when(mockFunction.definitions()).thenReturn(createMockTableDefinitions());when(mockFunction.auditInfo()).thenReturn(testAuditInfo);return mockFunction;}- private FunctionDefinition[] createMockDefinitions() {+ private FunctionDefinition[] createMockScalarDefinitions() {FunctionParam[] params =new FunctionParam[] {FunctionParams.of("param1", Types.IntegerType.get())};FunctionImpl[] impls =new FunctionImpl[] {FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT param1 + 1")};- return new FunctionDefinition[] {FunctionDefinitions.of(params, impls)};+ return new FunctionDefinition[] {+ FunctionDefinitions.of(params, Types.IntegerType.get(), impls)+ };+ }++ private FunctionDefinition[] createMockTableDefinitions() {+ FunctionParam[] params =+ new FunctionParam[] {FunctionParams.of("param1", Types.IntegerType.get())};+ FunctionImpl[] impls =+ new FunctionImpl[] {+ FunctionImpls.ofSql(FunctionImpl.RuntimeType.SPARK, "SELECT param1 + 1")+ };+ return new FunctionDefinition[] {+ FunctionDefinitions.of(params, createMockReturnColumns(), impls)+ };+ }++ private FunctionDefinitionDTO[] createMockScalarDefinitionDTOs() {+ return new FunctionDefinitionDTO[] {+ FunctionDefinitionDTO.builder()+ .withParameters(createMockParamDTOs())+ .withReturnType(Types.IntegerType.get())+ .withImpls(new FunctionImplDTO[] {createMockSqlImplDTO()})+ .build()+ };}- private FunctionDefinitionDTO[] createMockDefinitionDTOs() {+ private FunctionDefinitionDTO[] createMockTableDefinitionDTOs() {return new FunctionDefinitionDTO[] {FunctionDefinitionDTO.builder().withParameters(createMockParamDTOs())+ .withReturnColumns(createMockReturnColumnDTOs()).withImpls(new FunctionImplDTO[] {createMockSqlImplDTO()}).build()};