You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "mchades (via GitHub)" <gi...@apache.org> on 2026/01/16 09:34:47 UTC
[PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
mchades opened a new pull request, #9737:
URL: https://github.com/apache/gravitino/pull/9737
### What changes were proposed in this pull request?
Implement the `alterFunction` method in `ManagedFunctionOperations` to support modifying registered UDFs. This includes:
- **UpdateComment**: Update the function's comment/description
- **AddDefinition**: Add a new function definition with arity overlap validation
- **RemoveDefinition**: Remove an existing definition (with guard against removing the only definition)
- **AddImpl**: Add a new implementation to a definition (with runtime uniqueness check)
- **UpdateImpl**: Update an existing implementation for a specific runtime
- **RemoveImpl**: Remove an implementation from a definition (with guard against removing the only implementation)
### Why are the changes needed?
Fix: #9561
This is part of the UDF management feature. After registering a function, users need the ability to modify it without dropping and recreating. The `alterFunction` API enables incremental updates to function metadata, definitions, and implementations.
### Does this PR introduce _any_ user-facing change?
Yes. Users can now use the `alterFunction` API to modify registered functions through various `FunctionChange` operations.
### How was this patch tested?
Added comprehensive unit tests in `TestManagedFunctionOperations`:
- Test updating comment
- Test adding/removing definitions with arity validation
- Test adding/updating/removing implementations
- Test error cases (non-existing function, non-existing runtime, removing only definition/impl)
- Test parameter order validation during alter operations
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2698474316
##########
core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.java:
##########
@@ -388,6 +477,263 @@ public void testOverlappingAritiesWithDifferentTypes() {
Assertions.assertEquals(2, func.definitions().length);
}
+ @Test
+ public void testAlterFunctionRemoveDefinition() {
+ NameIdentifier funcIdent = getFunctionIdent("func_remove_def");
+
+ // Create function with two definitions
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Remove one definition
+ Function updatedFunc =
+ functionOperations.alterFunction(funcIdent, FunctionChange.removeDefinition(params1));
+
+ Assertions.assertEquals(1, updatedFunc.definitions().length);
+ }
+
+ @Test
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to remove the only definition - should fail
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> functionOperations.alterFunction(funcIdent, FunctionChange.removeDefinition(params)));
+ }
+
+ @Test
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to remove a definition that doesn't exist
+ FunctionParam[] nonExistingParams =
+ new FunctionParam[] {FunctionParams.of("x", Types.StringType.get())};
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ functionOperations.alterFunction(
+ funcIdent, FunctionChange.removeDefinition(nonExistingParams)));
+ }
+
+ @Test
+ public void testAlterFunctionAddImpl() {
+ NameIdentifier funcIdent = getFunctionIdent("func_add_impl");
+ FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};
+ FunctionImpl sparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");
+ FunctionDefinition[] definitions =
+ new FunctionDefinition[] {
+ createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})
+ };
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Add Trino implementation
+ FunctionImpl trinoImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.TRINO, "com.example.TrinoUDF");
+ org.apache.gravitino.function.Function updatedFunc =
+ functionOperations.alterFunction(funcIdent, FunctionChange.addImpl(params, trinoImpl));
+
+ Assertions.assertEquals(2, updatedFunc.definitions()[0].impls().length);
+ }
+
+ @Test
+ public void testAlterFunctionAddImplDuplicateRuntime() {
+ NameIdentifier funcIdent = getFunctionIdent("func_add_impl_dup");
+ FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};
+ FunctionImpl sparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");
+ FunctionDefinition[] definitions =
+ new FunctionDefinition[] {
+ createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})
+ };
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to add another Spark implementation - should fail
+ FunctionImpl anotherSparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.AnotherSparkUDF");
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ functionOperations.alterFunction(
+ funcIdent, FunctionChange.addImpl(params, anotherSparkImpl)));
+ }
+
+ @Test
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to add impl to non-existing definition
+ FunctionParam[] nonExistingParams =
+ new FunctionParam[] {FunctionParams.of("x", Types.StringType.get())};
+ FunctionImpl impl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.TRINO, "com.example.TrinoUDF");
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ functionOperations.alterFunction(
+ funcIdent, FunctionChange.addImpl(nonExistingParams, impl)));
+ }
+
+ @Test
+ public void testAlterFunctionUpdateImpl() {
+ NameIdentifier funcIdent = getFunctionIdent("func_update_impl");
+ FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};
+ FunctionImpl sparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.OldSparkUDF");
+ FunctionDefinition[] definitions =
+ new FunctionDefinition[] {
+ createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})
+ };
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Update Spark implementation
+ FunctionImpl newSparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.NewSparkUDF");
+ org.apache.gravitino.function.Function updatedFunc =
+ functionOperations.alterFunction(
+ funcIdent,
+ FunctionChange.updateImpl(params, FunctionImpl.RuntimeType.SPARK, newSparkImpl));
+
+ Assertions.assertEquals(1, updatedFunc.definitions()[0].impls().length);
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2703121563
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -245,9 +260,111 @@ private void validateDefinitionsNoArityOverlap(FunctionDefinition[] definitions)
}
}
+ private FunctionEntity applyChanges(FunctionEntity oldEntity, FunctionChange... changes) {
+ String newComment = oldEntity.comment();
+ List<FunctionDefinition> newDefinitions =
+ new ArrayList<>(Arrays.asList(oldEntity.definitions()));
+
+ for (FunctionChange change : changes) {
+ if (change instanceof FunctionChange.UpdateComment) {
+ newComment = ((FunctionChange.UpdateComment) change).newComment();
+
+ } else if (change instanceof FunctionChange.AddDefinition) {
+ FunctionDefinition defToAdd = ((FunctionChange.AddDefinition) change).definition();
+ validateNoArityOverlap(newDefinitions, defToAdd);
+ newDefinitions.add(defToAdd);
+
+ } else if (change instanceof FunctionChange.RemoveDefinition) {
+ FunctionParam[] paramsToRemove = ((FunctionChange.RemoveDefinition) change).parameters();
+ validateRemoveDefinition(newDefinitions, paramsToRemove);
+ newDefinitions.removeIf(def -> parametersMatch(def.parameters(), paramsToRemove));
+
+ } else if (change instanceof FunctionChange.AddImpl) {
+ FunctionChange.AddImpl addImpl = (FunctionChange.AddImpl) change;
+ FunctionParam[] targetParams = addImpl.parameters();
+ FunctionImpl implToAdd = addImpl.implementation();
+ newDefinitions = addImplToDefinition(newDefinitions, targetParams, implToAdd);
Review Comment:
the validation logic is included in the method `addImplToDefinition`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2703122841
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -313,4 +430,168 @@ private boolean hasDefaultValue(FunctionParam param) {
Expression defaultValue = param.defaultValue();
return defaultValue != null && defaultValue != Column.DEFAULT_VALUE_NOT_SET;
}
+
+ /**
+ * Validates that a definition can be removed.
+ *
+ * @param definitions The current definitions.
+ * @param paramsToRemove The parameters identifying the definition to remove.
+ * @throws IllegalArgumentException If the definition doesn't exist or is the only one.
+ */
+ private void validateRemoveDefinition(
+ List<FunctionDefinition> definitions, FunctionParam[] paramsToRemove) {
+ boolean found = false;
+ for (FunctionDefinition def : definitions) {
+ if (parametersMatch(def.parameters(), paramsToRemove)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ throw new IllegalArgumentException(
+ "Cannot remove definition: no definition found with the specified parameters");
+ }
+
+ if (definitions.size() == 1) {
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2698467071
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -245,9 +260,110 @@ private void validateDefinitionsNoArityOverlap(FunctionDefinition[] definitions)
}
}
+ private FunctionEntity applyChanges(FunctionEntity oldEntity, FunctionChange... changes) {
+ String newComment = oldEntity.comment();
+ List<FunctionDefinition> newDefinitions =
+ new ArrayList<>(Arrays.asList(oldEntity.definitions()));
+
+ for (FunctionChange change : changes) {
+ if (change instanceof FunctionChange.UpdateComment) {
+ newComment = ((FunctionChange.UpdateComment) change).newComment();
+
+ } else if (change instanceof FunctionChange.AddDefinition) {
+ FunctionDefinition defToAdd = ((FunctionChange.AddDefinition) change).definition();
Review Comment:
The validation already happens via the existing call chain:
validateNoArityOverlap → computeArities → findFirstOptionalParamIndex.
Adding an explicit call would be redundant.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2697741922
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -245,9 +260,110 @@ private void validateDefinitionsNoArityOverlap(FunctionDefinition[] definitions)
}
}
+ private FunctionEntity applyChanges(FunctionEntity oldEntity, FunctionChange... changes) {
+ String newComment = oldEntity.comment();
+ List<FunctionDefinition> newDefinitions =
+ new ArrayList<>(Arrays.asList(oldEntity.definitions()));
+
+ for (FunctionChange change : changes) {
+ if (change instanceof FunctionChange.UpdateComment) {
+ newComment = ((FunctionChange.UpdateComment) change).newComment();
+
+ } else if (change instanceof FunctionChange.AddDefinition) {
+ FunctionDefinition defToAdd = ((FunctionChange.AddDefinition) change).definition();
Review Comment:
The parameter order validation (via `findFirstOptionalParamIndex` in `computeArities`) is only called when computing arities, but the new definition being added might have invalid parameter order that won't be caught until arity computation. The validation should be called explicitly before adding the definition to provide clearer error messages. Consider calling `computeArities(defToAdd)` explicitly before `validateNoArityOverlap` to ensure parameter validation happens for the new definition.
```suggestion
FunctionDefinition defToAdd = ((FunctionChange.AddDefinition) change).definition();
// Validate parameter ordering and compute arities for the new definition early
computeArities(defToAdd);
```
##########
core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.java:
##########
@@ -490,4 +859,51 @@ private FunctionDefinition createSimpleDefinition(FunctionParam[] params) {
FunctionImpl impl = FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.TestUDF");
return FunctionDefinitions.of(params, new FunctionImpl[] {impl});
}
+
+ @Test
+ public void testParameterOrderValidationInAlterFunction() {
Review Comment:
This test is placed after helper methods at the end of the class. Test methods should be grouped together with other test methods, not interspersed with helper methods. Consider moving this test method to be with the other alter function tests (after line 735, before the helper methods section that starts at line 737).
##########
core/src/test/java/org/apache/gravitino/catalog/TestManagedFunctionOperations.java:
##########
@@ -388,6 +477,263 @@ public void testOverlappingAritiesWithDifferentTypes() {
Assertions.assertEquals(2, func.definitions().length);
}
+ @Test
+ public void testAlterFunctionRemoveDefinition() {
+ NameIdentifier funcIdent = getFunctionIdent("func_remove_def");
+
+ // Create function with two definitions
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Remove one definition
+ Function updatedFunc =
+ functionOperations.alterFunction(funcIdent, FunctionChange.removeDefinition(params1));
+
+ Assertions.assertEquals(1, updatedFunc.definitions().length);
+ }
+
+ @Test
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to remove the only definition - should fail
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> functionOperations.alterFunction(funcIdent, FunctionChange.removeDefinition(params)));
+ }
+
+ @Test
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to remove a definition that doesn't exist
+ FunctionParam[] nonExistingParams =
+ new FunctionParam[] {FunctionParams.of("x", Types.StringType.get())};
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ functionOperations.alterFunction(
+ funcIdent, FunctionChange.removeDefinition(nonExistingParams)));
+ }
+
+ @Test
+ public void testAlterFunctionAddImpl() {
+ NameIdentifier funcIdent = getFunctionIdent("func_add_impl");
+ FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};
+ FunctionImpl sparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");
+ FunctionDefinition[] definitions =
+ new FunctionDefinition[] {
+ createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})
+ };
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Add Trino implementation
+ FunctionImpl trinoImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.TRINO, "com.example.TrinoUDF");
+ org.apache.gravitino.function.Function updatedFunc =
+ functionOperations.alterFunction(funcIdent, FunctionChange.addImpl(params, trinoImpl));
+
+ Assertions.assertEquals(2, updatedFunc.definitions()[0].impls().length);
+ }
+
+ @Test
+ public void testAlterFunctionAddImplDuplicateRuntime() {
+ NameIdentifier funcIdent = getFunctionIdent("func_add_impl_dup");
+ FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};
+ FunctionImpl sparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.SparkUDF");
+ FunctionDefinition[] definitions =
+ new FunctionDefinition[] {
+ createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})
+ };
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to add another Spark implementation - should fail
+ FunctionImpl anotherSparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.AnotherSparkUDF");
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ functionOperations.alterFunction(
+ funcIdent, FunctionChange.addImpl(params, anotherSparkImpl)));
+ }
+
+ @Test
+ 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)};
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Try to add impl to non-existing definition
+ FunctionParam[] nonExistingParams =
+ new FunctionParam[] {FunctionParams.of("x", Types.StringType.get())};
+ FunctionImpl impl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.TRINO, "com.example.TrinoUDF");
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ functionOperations.alterFunction(
+ funcIdent, FunctionChange.addImpl(nonExistingParams, impl)));
+ }
+
+ @Test
+ public void testAlterFunctionUpdateImpl() {
+ NameIdentifier funcIdent = getFunctionIdent("func_update_impl");
+ FunctionParam[] params = new FunctionParam[] {FunctionParams.of("a", Types.IntegerType.get())};
+ FunctionImpl sparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.OldSparkUDF");
+ FunctionDefinition[] definitions =
+ new FunctionDefinition[] {
+ createDefinitionWithImpls(params, new FunctionImpl[] {sparkImpl})
+ };
+
+ functionOperations.registerFunction(
+ funcIdent, "Test function", FunctionType.SCALAR, true, Types.StringType.get(), definitions);
+
+ // Update Spark implementation
+ FunctionImpl newSparkImpl =
+ FunctionImpls.ofJava(FunctionImpl.RuntimeType.SPARK, "com.example.NewSparkUDF");
+ org.apache.gravitino.function.Function updatedFunc =
+ functionOperations.alterFunction(
+ funcIdent,
+ FunctionChange.updateImpl(params, FunctionImpl.RuntimeType.SPARK, newSparkImpl));
+
+ Assertions.assertEquals(1, updatedFunc.definitions()[0].impls().length);
Review Comment:
The test verifies that there is still 1 implementation after update, but doesn't verify that the implementation was actually updated to the new one. Consider adding an assertion to check that the class name of the remaining implementation is "com.example.NewSparkUDF" rather than "com.example.OldSparkUDF".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2702984109
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -313,4 +430,168 @@ private boolean hasDefaultValue(FunctionParam param) {
Expression defaultValue = param.defaultValue();
return defaultValue != null && defaultValue != Column.DEFAULT_VALUE_NOT_SET;
}
+
+ /**
+ * Validates that a definition can be removed.
+ *
+ * @param definitions The current definitions.
+ * @param paramsToRemove The parameters identifying the definition to remove.
+ * @throws IllegalArgumentException If the definition doesn't exist or is the only one.
+ */
+ private void validateRemoveDefinition(
+ List<FunctionDefinition> definitions, FunctionParam[] paramsToRemove) {
+ boolean found = false;
+ for (FunctionDefinition def : definitions) {
+ if (parametersMatch(def.parameters(), paramsToRemove)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ throw new IllegalArgumentException(
+ "Cannot remove definition: no definition found with the specified parameters");
+ }
+
+ if (definitions.size() == 1) {
Review Comment:
We can check this before the loop, so that we don't have to execute the additional loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #9737:
URL: https://github.com/apache/gravitino/pull/9737#discussion_r2702986158
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -245,9 +260,111 @@ private void validateDefinitionsNoArityOverlap(FunctionDefinition[] definitions)
}
}
+ private FunctionEntity applyChanges(FunctionEntity oldEntity, FunctionChange... changes) {
+ String newComment = oldEntity.comment();
+ List<FunctionDefinition> newDefinitions =
+ new ArrayList<>(Arrays.asList(oldEntity.definitions()));
+
+ for (FunctionChange change : changes) {
+ if (change instanceof FunctionChange.UpdateComment) {
+ newComment = ((FunctionChange.UpdateComment) change).newComment();
+
+ } else if (change instanceof FunctionChange.AddDefinition) {
+ FunctionDefinition defToAdd = ((FunctionChange.AddDefinition) change).definition();
+ validateNoArityOverlap(newDefinitions, defToAdd);
+ newDefinitions.add(defToAdd);
+
+ } else if (change instanceof FunctionChange.RemoveDefinition) {
+ FunctionParam[] paramsToRemove = ((FunctionChange.RemoveDefinition) change).parameters();
+ validateRemoveDefinition(newDefinitions, paramsToRemove);
+ newDefinitions.removeIf(def -> parametersMatch(def.parameters(), paramsToRemove));
+
+ } else if (change instanceof FunctionChange.AddImpl) {
+ FunctionChange.AddImpl addImpl = (FunctionChange.AddImpl) change;
+ FunctionParam[] targetParams = addImpl.parameters();
+ FunctionImpl implToAdd = addImpl.implementation();
+ newDefinitions = addImplToDefinition(newDefinitions, targetParams, implToAdd);
Review Comment:
Should you validate the parameters when you add a new impl?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9561] feat(core): Implement alterFunction for managed UDF operations [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #9737:
URL: https://github.com/apache/gravitino/pull/9737
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org