Skip to content

feat(ibis): introduce the api to get the details of specfic function#1374

Merged
douenergy merged 1 commit intoCanner:mainfrom
goldmedal:feat/function-detail-api
Dec 8, 2025
Merged

feat(ibis): introduce the api to get the details of specfic function#1374
douenergy merged 1 commit intoCanner:mainfrom
goldmedal:feat/function-detail-api

Conversation

@goldmedal
Copy link
Copy Markdown
Contributor

@goldmedal goldmedal commented Nov 14, 2025

This PR introduces an API to get the details of the specific function. The information will include the parameter types and their name if defined.

API Endpoint

/v3/connector/{data_source}/function/{function_name}

Response

/v3/connector/postgres/function/div
-------

  {
    "function_type": "scalar",
    "name": "div",
    "return_type": "Decimal(38, 10)",
    "param_names": null,
    "param_types": "Decimal(38, 10),Decimal(38, 10)",
    "description": "trunc(x/y)"
  }
]

Summary by CodeRabbit

  • New Features
    • Added a v3 GET endpoint that returns metadata for a named function (parameter names, parameter types, and return type) as JSON to aid client discovery.
  • Tests
    • Added automated test coverage validating the endpoint response and exact payload structure for a sample function.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added ibis python Pull requests that update Python code labels Nov 14, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

Adds a v3 API endpoint to fetch metadata for a named function and a corresponding test, plus a new public PySessionContext API that queries information_schema to return function details mapped to PyRemoteFunction.

Changes

Cohort / File(s) Summary
API Endpoint Addition
ibis-server/app/routers/v3/connector.py
Adds GET /{data_source}/function/{function_name} handler that starts a tracing span, obtains headers via dependency, calls session_context.get_available_function(function_name), and returns JSON.
Endpoint Test
ibis-server/tests/routers/v3/connector/postgres/test_functions.py
Adds test_get_function which issues GET /function/div, expects 200, and asserts exact JSON payload for the div function.
Core Function Lookup (Rust)
wren-core-py/src/context.rs
Adds get_available_function(&self, function_name) public method, internal async get_registered_function(function_name, ctx) that queries information_schema for function metadata, helper to_string_vec, and imports/types to handle DB array/string types and map results to PyRemoteFunction.

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as API Endpoint (v3/connector)
    participant Session as PySessionContext
    participant DB as information_schema

    Client->>API: GET /{data_source}/function/{function_name}
    API->>API: start tracing span
    API->>Session: get_available_function(function_name)
    Session->>DB: SQL query on information_schema for function metadata
    DB-->>Session: rows (name, param_names, param_types, return_type, description)
    Session->>Session: map rows -> PyRemoteFunction list
    Session-->>API: Vec<PyRemoteFunction>
    API-->>Client: 200 OK + JSON payload
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay close attention to wren-core-py/src/context.rs for:
    • SQL construction and correctness against target information_schema (columns, array handling).
    • Safe/accurate conversions from DB array types to Rust Vec<Option<String>> (to_string_vec).
    • Async bridging and PyO3 PyResult/type mapping to PyRemoteFunction.
  • Review ibis-server/app/routers/v3/connector.py for correct header dependency usage, tracing/span semantics, and error handling when session returns no results.
  • Validate ibis-server/tests/.../test_functions.py for deterministic assertions and fixture compatibility with test DB state.

Suggested labels

rust

Suggested reviewers

  • douenergy

Poem

🐰 I hopped through schemas, rows in a line,
I fetched every param, each type and design,
From DB to endpoint, the metadata sings—
A rabbit's small hop makes the function take wing! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new API to retrieve details for a specific function, which aligns with the PR's core objective of introducing the /v3/connector/{data_source}/function/{function_name} endpoint.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
ibis-server/tests/routers/v3/connector/postgres/test_functions.py (1)

73-86: Good coverage; consider loosening assertion if metadata format may evolve

The test correctly exercises the new /function/div endpoint and validates the expected payload. If you expect the underlying type formatting or description strings to evolve, you might want to assert on a subset of fields (e.g., name, function_type, key parts of param_types) instead of strict equality on the full object to reduce brittleness; otherwise this is fine as-is.

ibis-server/app/routers/v3/connector.py (1)

445-465: Align endpoint description and behavior with /functions semantics

The verification confirms all three concerns:

  1. Description mismatch: The description says "get the available function list…" but should reflect that this endpoint returns details for a specific function.

  2. Whitelist inconsistency (confirmed): The /functions endpoint (lines 420–443) checks is_white_list and either reads the CSV whitelist or calls session_context.get_available_functions(). However, the /function/{name} endpoint (lines 445–465) always calls session_context.get_available_function() and ignores the whitelist configuration entirely. If the whitelist is meant to gate which functions are exposed, consider:

    • Enforcing the same whitelist check here (e.g., returning 404 or 403 for non-whitelisted functions), or
    • Documenting that /function/{name} always reflects the underlying information_schema, independent of whitelist configuration.
  3. Not-found semantics: An unknown function_name currently returns 200 with an empty list. Consider returning 404 if API consumers expect a "not found" signal.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c53150e and d4c0c15.

📒 Files selected for processing (3)
  • ibis-server/app/routers/v3/connector.py (1 hunks)
  • ibis-server/tests/routers/v3/connector/postgres/test_functions.py (1 hunks)
  • wren-core-py/src/context.rs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
wren-core-py/src/context.rs (3)
wren-core/core/src/mdl/function/remote_function.rs (11)
  • from (188-198)
  • from (272-281)
  • from (335-344)
  • name (226-228)
  • name (289-291)
  • name (352-354)
  • param_types (55-58)
  • return_type (234-236)
  • return_type (297-299)
  • from_str (88-95)
  • from_str (128-138)
wren-core-py/src/remote_functions.rs (2)
  • from (65-99)
  • from (103-139)
wren-core-py/src/errors.rs (10)
  • from (25-27)
  • from (31-33)
  • from (37-39)
  • from (43-45)
  • from (49-51)
  • from (55-64)
  • from (68-70)
  • from (74-76)
  • from (80-82)
  • from (86-88)
ibis-server/app/routers/v3/connector.py (7)
ibis-server/app/model/data_source.py (1)
  • DataSource (60-214)
ibis-server/app/dependencies.py (1)
  • get_wren_headers (26-34)
ibis-server/app/util.py (2)
  • build_context (142-145)
  • set_attribute (148-155)
ibis-server/app/config.py (1)
  • get_remote_function_list_path (61-70)
ibis-server/app/mdl/core.py (1)
  • get_session_context (7-10)
wren-core-py/src/remote_functions.rs (1)
  • to_dict (47-61)
wren-core-py/src/context.rs (1)
  • get_available_function (238-253)
ibis-server/tests/routers/v3/connector/postgres/test_functions.py (1)
ibis-server/tests/conftest.py (1)
  • client (18-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ci
  • GitHub Check: ci
  • GitHub Check: test

@goldmedal goldmedal requested a review from douenergy November 18, 2025 02:20
@goldmedal goldmedal force-pushed the feat/function-detail-api branch from d4c0c15 to 5602189 Compare December 5, 2025 09:17
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
wren-core-py/src/context.rs (1)

243-255: SQL injection vulnerability already flagged.

The function_name parameter flows into get_registered_function where it is directly interpolated into SQL (line 457). This was already flagged in a previous review.

Minor: Consider simplifying .map(|f| PyRemoteFunction::from(f)) to .map(Into::into) for consistency with the existing pattern at line 238.

🧹 Nitpick comments (1)
ibis-server/tests/routers/v3/connector/postgres/test_functions.py (1)

73-87: Test covers the happy path correctly.

The test validates the expected response structure for the new endpoint. Consider adding a test for a non-existent function name to verify the endpoint returns an empty list (or appropriate error) in that case.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4c0c15 and 5602189.

📒 Files selected for processing (3)
  • ibis-server/app/routers/v3/connector.py (1 hunks)
  • ibis-server/tests/routers/v3/connector/postgres/test_functions.py (1 hunks)
  • wren-core-py/src/context.rs (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-05T02:27:29.829Z
Learnt from: goldmedal
Repo: Canner/wren-engine PR: 1161
File: ibis-server/app/routers/v3/connector.py:78-83
Timestamp: 2025-05-05T02:27:29.829Z
Learning: The row-level access control implementation in Wren Engine filters headers with the prefix `X_WREN_VARIABLE_PREFIX` in `EmbeddedEngineRewriter.get_session_properties` and validates session property expressions in `access_control.rs` to ensure they only contain literal values, preventing SQL injection.

Applied to files:

  • wren-core-py/src/context.rs
🧬 Code graph analysis (3)
ibis-server/tests/routers/v3/connector/postgres/test_functions.py (1)
ibis-server/tests/conftest.py (1)
  • client (18-23)
wren-core-py/src/context.rs (2)
wren-core-py/src/errors.rs (11)
  • from (26-28)
  • from (32-34)
  • from (38-40)
  • from (44-46)
  • from (50-52)
  • from (56-65)
  • from (69-71)
  • from (75-77)
  • from (81-83)
  • from (87-89)
  • from (93-95)
wren-core-py/src/remote_functions.rs (2)
  • from (65-99)
  • from (103-139)
ibis-server/app/routers/v3/connector.py (5)
ibis-server/app/dependencies.py (1)
  • get_wren_headers (26-34)
ibis-server/app/util.py (2)
  • build_context (142-145)
  • set_attribute (148-155)
ibis-server/app/config.py (2)
  • get_config (103-104)
  • get_remote_function_list_path (61-75)
wren-core-py/src/remote_functions.rs (1)
  • to_dict (47-61)
wren-core-py/src/context.rs (1)
  • get_available_function (243-255)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ci
  • GitHub Check: ci
  • GitHub Check: test
🔇 Additional comments (3)
wren-core-py/src/context.rs (2)

32-34: LGTM!

The new imports for GenericByteArray and GenericStringType are correctly added to support the array handling in to_string_vec.


501-508: LGTM!

The to_string_vec helper correctly converts the Arrow string array to Vec<Option<String>>, properly handling null values via the iterator's Option return.

ibis-server/app/routers/v3/connector.py (1)

450-465: Implementation follows existing patterns correctly.

The endpoint correctly initializes the session context and retrieves function details. The return type (list) appropriately handles potential function overloads with the same name but different signatures.

Consider whether a 404 response is needed when the function is not found (currently returns empty list []). If the current behavior is intentional, a brief inline comment would help clarify.

@douenergy douenergy merged commit 7c05af5 into Canner:main Dec 8, 2025
6 of 7 checks passed
@goldmedal goldmedal deleted the feat/function-detail-api branch December 30, 2025 02:19
nhaluc1005 pushed a commit to nhaluc1005/text2sql-practice that referenced this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ibis python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants