Skip to content

Improve DuckDB::ScalarFunction C API coverage #1122

@suketa

Description

@suketa

Overview

DuckDB::ScalarFunction is missing several features from the DuckDB C API. This issue tracks the full list.


Missing API methods

DuckDB::ScalarFunction

  • set_varargs(logical_type) — wrap duckdb_scalar_function_set_varargs. Allows accepting a variable number of arguments of a given type.
  • set_special_handling — wrap duckdb_scalar_function_set_special_handling. Marks the function to receive NULL inputs.
  • set_bind(&block) — wrap duckdb_scalar_function_set_bind. Enables dynamic return type resolution based on input types at bind time.

DuckDB::FunctionInfo

  • get_bind_data — wrap duckdb_scalar_function_get_bind_data. Allows the execute callback to retrieve data stored at bind time.
  • set_error (scalar-specific) — wrap duckdb_scalar_function_set_error. Currently only the generic duckdb_function_set_error is wrapped.

New class: DuckDB::ScalarFunctionBindInfo

The bind callback receives a duckdb_bind_info. Scalar-function-specific methods not yet wrapped:

  • set_bind_data(data, destroy_callback)duckdb_scalar_function_set_bind_data
  • set_bind_data_copy(copy_callback)duckdb_scalar_function_set_bind_data_copy
  • set_error(message)duckdb_scalar_function_bind_set_error
  • get_extra_infoduckdb_scalar_function_bind_get_extra_info
  • argument_countduckdb_scalar_function_bind_get_argument_count
  • get_argument(index)duckdb_scalar_function_bind_get_argument
  • get_client_contextduckdb_scalar_function_get_client_context

New class: DuckDB::ScalarFunctionSet

Enables registering multiple type overloads under the same function name:

  • DuckDB::ScalarFunctionSet.new(name)duckdb_create_scalar_function_set
  • #add(scalar_function)duckdb_add_scalar_function_to_set
  • Connection#register_scalar_function_set(set)duckdb_register_scalar_function_set

Missing type support in input/output handling

Currently handled: BOOLEAN, TINYINT, UTINYINT, SMALLINT, USMALLINT, INTEGER, UINTEGER, BIGINT, UBIGINT, FLOAT, DOUBLE, VARCHAR, BLOB, TIMESTAMP, DATE, TIME

Missing scalar types (straightforward)

  • HUGEINT, UHUGEINT — use duckdb_hugeint / duckdb_uhugeint struct → Ruby Integer
  • TIMESTAMP_S, TIMESTAMP_MS, TIMESTAMP_NS, TIMESTAMP_TZ — same pattern as TIMESTAMP
  • TIME_TZ, TIME_NS — same pattern as TIME
  • INTERVAL — map to/from DuckDB::Interval
  • UUID — stored as hugeint internally, expose as String
  • DECIMAL — needs width/scale metadata from logical type

Missing complex types (harder, lower priority)

  • LIST, STRUCT, MAP, ARRAY, UNION, ENUM — require recursive child vector handling

Note: the same type gaps also exist in DuckDB::DataChunk#set_value used by the table function adapter, so fixing these would benefit both APIs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions