Skip to content

Attach the SQL-facing arity from the CREATE FUNCTION signatures#31

Merged
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:feat/sql-arity
Jul 8, 2026
Merged

Attach the SQL-facing arity from the CREATE FUNCTION signatures#31
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:feat/sql-arity

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

The @sqlfn map gives each catalog function its MobilityDB SQL name, but the binding-facing arity is the SQL CREATE FUNCTION signature, not the wider C one. A SQL arg with a DEFAULT clause is optional, and a trailing C parameter absent from the SQL form is a C-only out-param (e.g. the size_t * of the *_as_hexwkb family). Without this a generator emits the raw C arity — trajectory(temporal, bool) instead of SQL trajectory(temporal), or asHexWKB(temporal, byte, <out>) instead of asHexWKB(temporal) — forcing every binding to hand-special-case the flag and out-params (which the codegen North Star forbids).

What

parser/sqlfn.py parses mobilitydb/sql/**/*.in.sql for CREATE FUNCTION name(args) ... AS 'MODULE_PATHNAME','<Wrapper>', keys by the wrapper (the @csqlfn target), and attaches per function:

  • sqlArity — required SQL args (no DEFAULT)
  • sqlArityMax — total SQL args (including DEFAULT)

so a generator derives: C params [0, sqlArity) required, [sqlArity, sqlArityMax) SQL-optional, [sqlArityMax, C-arity) out-params. run.py wires the mobilitydb/sql source root into the @sqlfn step.

On the current master surface: 2513 functions receive sqlArity/sqlArityMax; tpoint_trajectory → (1, 2), temporal_as_hexwkb → (1, 2) over its 3-param C signature (the size_out is the lone out-param).

Why now

The catalog previously lost this enrichment, so consumers that key UDF/binding arity off it regressed. Proven end-to-end: with this restored, MobilitySpark's generated trajectory UDF registers as the SQL-faithful UDF1 (was UDF2) and its suite goes green — with no hand special-case in the binding.

The @sqlfn map gives each catalog function its MobilityDB SQL name, but the
binding-facing ARITY is the SQL CREATE FUNCTION signature, not the wider C
one. A SQL arg with a DEFAULT clause is optional, and a trailing C parameter
absent from the SQL form is a C-only out-param (e.g. the size_t * of the
*_as_hexwkb family). Without this a generator emits the raw C arity —
trajectory(temporal, bool) instead of SQL trajectory(temporal), or
asHexWKB(temporal, byte, <out>) instead of asHexWKB(temporal) — forcing
every binding to hand-special-case the flag and out-params.

Parse mobilitydb/sql/**/*.in.sql for `CREATE FUNCTION name(args) ... AS
'MODULE_PATHNAME','<Wrapper>'`, key by the wrapper (the @csqlfn target), and
attach per function:
  sqlArity     -- required SQL args (no DEFAULT)
  sqlArityMax  -- total SQL args (including DEFAULT)
so a generator derives: C params [0, sqlArity) required, [sqlArity,
sqlArityMax) SQL-optional, [sqlArityMax, C-arity) out-params. 1977 wrappers
parsed, 185 with optional args; trajectory -> (1, 2), temporal_as_hexwkb ->
(1, 2) over a 3-param C signature (the size_out is the lone out-param).
@estebanzimanyi estebanzimanyi merged commit 5c38243 into MobilityDB:master Jul 8, 2026
2 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.

1 participant