Skip to content

Conversation

@mchades
Copy link
Contributor

@mchades mchades commented Dec 26, 2025

What changes were proposed in this pull request?

This PR implements the server-side REST API for User-Defined Functions (UDFs), including:

  • DTO classes: FunctionDTO, FunctionDefinitionDTO, FunctionParamDTO, FunctionColumnDTO, FunctionImplDTO (with JavaImplDTO, PythonImplDTO, SQLImplDTO subclasses), FunctionResourcesDTO
  • Request/Response classes: FunctionRegisterRequest, FunctionUpdateRequest, FunctionUpdatesRequest, FunctionResponse

Why are the changes needed?

To provide server-side REST API support for managing UDFs in Gravitino.

Fix: #9529

Does this PR introduce any user-facing change?

No

How was this patch tested?

  • Added comprehensive unit tests for all DTO classes (TestFunctionDTO)

@mchades mchades marked this pull request as draft December 26, 2025 01:23
@mchades mchades force-pushed the pr-udf-rest branch 3 times, most recently from bf67ede to 0b4f14c Compare December 30, 2025 14:31
@mchades mchades force-pushed the pr-udf-rest branch 2 times, most recently from 00f0661 to 50f2504 Compare January 21, 2026 02:05
…sponse classes

Add the DTO (Data Transfer Object) layer for Function support in the REST API. This includes:

**Function DTOs:**
- `FunctionDTO`: Main DTO representing a function
- `FunctionDefinitionDTO`: DTO for function definition with parameters and return type
- `FunctionParamDTO`: DTO for function parameters
- `FunctionColumnDTO`: DTO for function return columns (for table functions)
- `FunctionImplDTO`: Base DTO for function implementation
- `SQLImplDTO`, `JavaImplDTO`, `PythonImplDTO`: Implementation-specific DTOs
- `FunctionResourcesDTO`: DTO for external resources

**REST API Request/Response classes:**
- `FunctionRegisterRequest`: Request for registering a new function
- `FunctionUpdateRequest`: Request for updating function properties
- `FunctionUpdatesRequest`: Request for batch function updates
- `FunctionResponse`: Response containing a single function
- `FunctionListResponse`: Response containing a list of functions

Fix: apache#9561

These DTOs and request/response classes are essential for exposing Function management capabilities through the REST API. They enable serialization/deserialization between the API layer and the Function domain model.

Yes. This adds the foundation for Function REST API endpoints.

Added unit tests in `TestFunctionDTO` covering:
- Serialization/deserialization of FunctionDTO and nested DTOs
- Builder pattern usage
- JSON format validation
@mchades mchades self-assigned this Jan 21, 2026
@mchades mchades marked this pull request as ready for review January 21, 2026 02:36
@mchades mchades requested a review from jerryshao January 21, 2026 02:37
@mchades mchades changed the title [#9529] feat(server): Add server-side REST interface for UDFs [#9529] feat(server): Add server-side REST interface for UDFs (part-1) Jan 21, 2026
@mchades
Copy link
Contributor Author

mchades commented Jan 21, 2026

@jerryshao could you plz help to review this PR when you have time? thx

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the server-side REST API infrastructure for User-Defined Functions (UDFs) in Apache Gravitino. The implementation includes comprehensive DTO classes for representing functions, their definitions, parameters, implementations (Java, Python, SQL), and resources, along with Request/Response classes for function registration and updates.

Changes:

  • Added complete DTO hierarchy for UDF representation including FunctionDTO, FunctionDefinitionDTO, FunctionParamDTO, FunctionColumnDTO, and implementation classes (JavaImplDTO, PythonImplDTO, SQLImplDTO)
  • Implemented REST API request/response classes for function registration (FunctionRegisterRequest), updates (FunctionUpdateRequest, FunctionUpdatesRequest), and responses (FunctionResponse, FunctionListResponse)
  • Extended DTOConverters with Function to FunctionDTO conversion support

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
TestFunctionDTO.java Comprehensive serialization/deserialization tests for all DTO classes including scalar and table functions
DTOConverters.java Added toDTO method for converting Function entities to FunctionDTO with proper handling of return columns and definitions
FunctionResponse.java Response wrapper for single function operations with validation for required fields
FunctionListResponse.java Response wrapper for listing multiple functions with null validation
FunctionUpdatesRequest.java Request class for batch function updates with update list validation
FunctionUpdateRequest.java Interface and implementations for various function update operations (comment, definition, implementation changes)
FunctionRegisterRequest.java Request class for function registration with validation for function type-specific requirements
SQLImplDTO.java DTO for SQL-based function implementations with runtime, resources, and SQL expression
PythonImplDTO.java DTO for Python function implementations with handler and code block support
JavaImplDTO.java DTO for Java function implementations with class name specification
FunctionResourcesDTO.java DTO for function resources (jars, files, archives) with builder pattern
FunctionParamDTO.java DTO for function parameters with support for default values and type information
FunctionImplDTO.java Abstract base DTO for function implementations with polymorphic deserialization support
FunctionDefinitionDTO.java DTO for function definitions pairing parameters with implementations
FunctionDTO.java Main DTO representing complete function metadata implementing Function interface
FunctionColumnDTO.java DTO for table function return columns with name, type, and comment

}

/** Builder for {@link FunctionColumnDTO}. */
public static class Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use Lombok's builder annotation to auto-generate the builder class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adopted

}

/** Builder for {@link FunctionParamDTO}. */
public static class Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this Builder class here and above? Since we already have fromXXX help method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, fromXXX also wrap the the default value converter logic

Assertions.assertEquals("input", deserialized.parameters()[0].name());
Assertions.assertEquals(1, deserialized.impls().length);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also add tests for request and response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@mchades mchades requested a review from jerryshao January 22, 2026 13:50
.withName("table_func")
.withFunctionType(FunctionType.TABLE)
.withDeterministic(false)
.withReturnColumns(new org.apache.gravitino.dto.function.FunctionColumnDTO[] {col})
Copy link
Contributor

Choose a reason for hiding this comment

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

LLM tends to use full qualified class name, you should avoid this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. I opened a new issue to track this #9789

@jerryshao jerryshao merged commit 904fd7f into apache:main Jan 23, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask] Add server-side REST interface for UDFs

2 participants