[#9533] feat(trino-connector): Add UDF adaptation for Trino connector#10494
[#9533] feat(trino-connector): Add UDF adaptation for Trino connector#10494diqiu50 merged 2 commits intoapache:mainfrom
Conversation
Code Coverage Report
Files
|
There was a problem hiding this comment.
Pull request overview
Adds Trino connector support for consuming Gravitino function metadata by adapting Gravitino SQL UDFs (runtime = TRINO) into Trino LanguageFunction objects, with unit tests validating the behavior.
Changes:
- Extend
CatalogConnectorMetadatawith optionalFunctionCatalogsupport, including graceful fallback when functions aren’t supported. - Implement
listLanguageFunctions()andgetLanguageFunctions()inGravitinoMetadata, converting Gravitino function definitions/impls into TrinoLanguageFunctioninstances. - Add unit tests for function-catalog detection/listing/retrieval and for language-function conversion/filtering/signature-token behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java | Adds function-catalog discovery plus list/get function helpers with fallback when unsupported. |
| trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java | Adds Trino LanguageFunction listing/getting by converting Gravitino TRINO SQL impls. |
| trino-connector/trino-connector/src/test/java/org/apache/gravitino/trino/connector/catalog/TestCatalogConnectorMetadataFunction.java | Tests catalog function support detection, listing, retrieval, and error handling. |
| trino-connector/trino-connector/src/test/java/org/apache/gravitino/trino/connector/TestGravitinoMetadataFunction.java | Tests conversion/filtering of Gravitino functions to Trino LanguageFunction, including signature token cases. |
…nector Add support for consuming Gravitino function metadata in the Trino connector by mapping SQL functions with RuntimeType.TRINO to Trino's built-in LanguageFunction API. Changes: - CatalogConnectorMetadata: Add FunctionCatalog support with graceful fallback when catalog does not support functions. Add methods to list and retrieve functions from Gravitino server. - GravitinoMetadata: Implement listLanguageFunctions() and getLanguageFunctions() to convert Gravitino SQL functions with TRINO runtime to Trino LanguageFunction instances. - TestGravitinoMetadataFunction: 8 unit tests covering listing, filtering, multiple definitions, signature tokens, and edge cases. - TestCatalogConnectorMetadataFunction: 7 unit tests covering function catalog support detection, listing, retrieval, and error handling. Fixes apache#9533
1974402 to
3d88499
Compare
|
@diqiu50 addressed the bot's comments/ |
aeebb2e to
5f4239f
Compare
|
Please update the PR description to match our format. |
|
Done, I used some closed PR as a reference. |
5f4239f to
aed4474
Compare
|
Created TrinoUDFIT.java with 4 integration tests tagged
|
diqiu50
left a comment
There was a problem hiding this comment.
I noticed you added integration tests—why not include test scripts as well, like those in trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets?
Can Trino create functions in Gravitino via SQL?
| } | ||
| return Arrays.stream(catalogConnectorMetadata.listFunctionInfos(schemaName)) | ||
| .flatMap(function -> toLanguageFunctions(function).stream()) | ||
| .collect(Collectors.toList()); |
There was a problem hiding this comment.
flatMap(XX).toList() is OK
| Types.IntegerType.get(), | ||
| FunctionImpls.of( | ||
| FunctionImpls.ofSql(FunctionImpl.RuntimeType.TRINO, "RETURN x + 1"))))); | ||
| Assertions.assertNotNull(function); |
There was a problem hiding this comment.
Add comments for this function definition
aed4474 to
f9d5505
Compare
|
This PR only implements the read path 'listLanguageFunctions'/'getLanguageFunctions'. Trino cannot create functions in Gravitino via SQL yet; the write path (CREATE FUNCTION) is not implemented in this PR. Because of that, the SQL testset approach doesn't work here since we need to register functions via the Gravitino Java client first, then verify them from the Trino side. SQL testsets would be a great fit once the CREATE FUNCTION write path is added in a follow-up. |
| import org.apache.gravitino.SupportsSchemas; | ||
| import org.apache.gravitino.client.GravitinoMetalake; | ||
| import org.apache.gravitino.exceptions.NoSuchCatalogException; | ||
| import org.apache.gravitino.exceptions.NoSuchFunctionException; |
There was a problem hiding this comment.
The import for NoSuchFunctionException is unused (it’s only referenced in JavaDoc). Spotless is configured with removeUnusedImports(), so this will fail formatting checks unless removed or referenced in code/JavaDoc using FQN without importing.
| import org.apache.gravitino.exceptions.NoSuchFunctionException; |
| /** | ||
| * Lists all functions with details in the specified schema. | ||
| * | ||
| * @param schemaName the name of the schema | ||
| * @return an array of functions, or an empty array if functions are not supported | ||
| */ | ||
| public Function[] listFunctionInfos(String schemaName) { | ||
| if (!supportsFunctions()) { | ||
| throw new UnsupportedOperationException("Catalog does not support functions"); | ||
| } |
There was a problem hiding this comment.
JavaDoc for listFunctionInfos says it returns an empty array when functions are not supported, but the method currently throws UnsupportedOperationException in that case. Please align the JavaDoc with the actual behavior (or change the method to match the documented contract).
| } catch (Exception e) { | ||
| LOG.warn( | ||
| "Failed to build signature token for function {}: {}", | ||
| function.name(), | ||
| e.getMessage()); |
There was a problem hiding this comment.
toLanguageFunctions catches a generic Exception and logs only e.getMessage(), which can hide the root cause and stack trace (and the repo guidelines discourage catch (Exception e)). Catch the specific expected exceptions (e.g., unsupported type conversion) and include the exception in the log call so failures are diagnosable.
| } catch (Exception e) { | |
| LOG.warn( | |
| "Failed to build signature token for function {}: {}", | |
| function.name(), | |
| e.getMessage()); | |
| } catch (IllegalArgumentException | UnsupportedOperationException e) { | |
| LOG.warn( | |
| "Failed to build signature token for function {}", | |
| function.name(), | |
| e); |
| LOG.warn( | ||
| "Failed to build signature token for function {}: {}", | ||
| function.name(), | ||
| e.getMessage()); |
| * Lists all functions with details in the specified schema. | ||
| * | ||
| * @param schemaName the name of the schema | ||
| * @return an array of functions, or an empty array if functions are not supported |
| LOG.info("SHOW FUNCTIONS for empty schema: {}", result); | ||
| // For an empty schema, the result should not contain any custom function names | ||
| Assertions.assertFalse( | ||
| result.contains("udf_"), "Expected no UDFs in empty schema. Got: " + result); |
There was a problem hiding this comment.
Can you clarify the criteria here? udf_ is too vague.
|
|
||
| LOG.info("SELECT result: {}", result); | ||
| Assertions.assertTrue( | ||
| result.contains("10"), "Expected SELECT test_add_five(5) to return 10. Got: " + result); |
| metadata.getLanguageFunctions( | ||
| session, new SchemaFunctionName("test_schema", "no_such_func")); | ||
| assertTrue(functions.isEmpty()); | ||
| } |
There was a problem hiding this comment.
Add some tests for supportsFunctions=false
|
Can you add some docs for the UDF |
f9d5505 to
5d6d107
Compare
|
Done, created 'udf-support.md' |
|
@laserninja Please leave a comment on the issue #9533—I can’t assign it to you. |
|
Commented, thanks. |
…nector (apache#10494) ### What changes were proposed in this pull request? Add support for consuming Gravitino function metadata in the Trino connector by mapping SQL functions with RuntimeType.TRINO to Trino's built-in LanguageFunction API. ### Why are the changes needed? - CatalogConnectorMetadata: Add FunctionCatalog support with graceful fallback when catalog does not support functions. Add methods to list and retrieve functions from Gravitino server. - GravitinoMetadata: Implement listLanguageFunctions() and getLanguageFunctions() to convert Gravitino SQL functions with TRINO runtime to Trino LanguageFunction instances. - TestGravitinoMetadataFunction: 8 unit tests covering listing, filtering, multiple definitions, signature tokens, and edge cases. - TestCatalogConnectorMetadataFunction: 7 unit tests covering function catalog support detection, listing, retrieval, and error handling. Fix apache#9533 ### Does this PR introduce any user-facing change? No. ### How was this patch tested? Added test cases.
…rino connector (apache#10494)" This reverts commit 7fce6aa.
…rino connector (apache#10494)" This reverts commit 7fce6aa.
What changes were proposed in this pull request?
Add support for consuming Gravitino function metadata in the Trino connector by mapping SQL functions with RuntimeType.TRINO to Trino's built-in LanguageFunction API.
Why are the changes needed?
Fix #9533
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added test cases.