|
| 1 | +# **RFC-0021 for Presto** |
| 2 | + |
| 3 | +## [Title] Support custom schemas in native sidecar function registry |
| 4 | + |
| 5 | +## Summary |
| 6 | +This feature enables namespace separation for C++ functions in Presto by allowing registration and querying of functions under different catalogs and schemas. It brings the native sidecar registry to feature parity with Java function namespace managers. |
| 7 | + |
| 8 | +## [Related Issues] |
| 9 | +- https://github.com/prestodb/presto/issues/25429 |
| 10 | + |
| 11 | +## Background |
| 12 | +Currently, all functions (built-in and custom) were bundled together, preventing proper isolation and organization. Users could not namespace custom C++ functions separately from built-ins. |
| 13 | + |
| 14 | +## Design & Architecture |
| 15 | +The solution introduces catalog-based filtering: |
| 16 | +```mermaid |
| 17 | +graph TD |
| 18 | + Coordinator[Presto Coordinator] |
| 19 | + NamespaceManager1[NativeFunctionNamespaceManager - Catalog: mycatalog] |
| 20 | + NamespaceManager2[NativeFunctionNamespaceManager - Catalog: native] |
| 21 | + EndpointCatalog["GET /v1/functions/{catalog}"] |
| 22 | + FilterCatalog["getFunctionsMetadata(catalog)"] |
| 23 | + Registry[Velox Function Registry] |
| 24 | + Coordinator --> NamespaceManager1 |
| 25 | + Coordinator --> NamespaceManager2 |
| 26 | + NamespaceManager1 -->|"/v1/functions/mycatalog"| EndpointCatalog |
| 27 | + NamespaceManager2 -->|"/v1/functions/native"| EndpointCatalog |
| 28 | + EndpointCatalog --> FilterCatalog |
| 29 | + FilterCatalog --> Registry |
| 30 | +``` |
| 31 | +- **C++ Backend:** Adds `/v1/functions/{catalog}` endpoint in `PrestoServer.cpp` that delegates to `getFunctionsMetadata(catalog)`. |
| 32 | +- **Filtering Logic:** In `FunctionMetadata.cpp`, functions are filtered by catalog prefix (from fully qualified name: `catalog.schema.function_name`). |
| 33 | +- **Java Plugin:** Each `NativeFunctionNamespaceManager` instance is bound to a catalog and queries only its catalog's functions from the sidecar. |
| 34 | + |
| 35 | +## API Specification |
| 36 | +- **GET /v1/functions**: Returns all functions (unfiltered). |
| 37 | +- **GET /v1/functions/{catalog}**: Returns only functions from the specified catalog. |
| 38 | + |
| 39 | +Example response for `/v1/functions/mycatalog`: |
| 40 | +```json |
| 41 | +{ |
| 42 | + "my_custom_function": [ |
| 43 | + { |
| 44 | + "outputType": "varchar", |
| 45 | + "paramTypes": ["varchar"], |
| 46 | + "schema": "myschema", |
| 47 | + "functionKind": "SCALAR", |
| 48 | + "routineCharacteristics": { |
| 49 | + "language": {"languageName": "CPP"}, |
| 50 | + "determinism": "DETERMINISTIC", |
| 51 | + "nullCallClause": "RETURNS_NULL_ON_NULL_INPUT" |
| 52 | + } |
| 53 | + } |
| 54 | + ] |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Implementation Details |
| 59 | +- Functions are registered in Velox as `catalog.schema.function_name`. |
| 60 | +- Filtering is performed by splitting the function name and matching the catalog. |
| 61 | + |
| 62 | +## Usage Example |
| 63 | +Configure multiple function namespace managers: |
| 64 | +```properties |
| 65 | +# etc/function-namespace/mycatalog.properties |
| 66 | +function-namespace-manager.name=native |
| 67 | +function-implementation-type=CPP |
| 68 | +supported-function-languages=CPP |
| 69 | +``` |
0 commit comments