Skip to content

feat(core): support table functions - #1468

Draft
Adam-Alani wants to merge 6 commits into
substrait-io:mainfrom
Adam-Alani:adam.alani/table-functions
Draft

Adam-Alani wants to merge 6 commits into
substrait-io:mainfrom
Adam-Alani:adam.alani/table-functions

Conversation

@Adam-Alani

Copy link
Copy Markdown
Contributor

Why

Substrait v0.109.0 adds table functions, which produce zero or more rows per call. An extension declares them under table_functions, with an optional schema in place of a return type, and a TableFunctionRel calls one as a leaf relation. Its arguments may reference outer rows, so on the right of a lateral join it produces rows for each left row, for example generate_series(1, n, 1) for each n. substrait-java could neither load these declarations nor read or write the relation.

What

  • The extension model reads table_functions, and the default catalog loads functions_table.yaml, which declares generate_series.
  • A new TableFunction relation, built with SubstraitBuilder.tableFunction, converts to and from TableFunctionRel, and the copy-on-write visitor rewrites its arguments.
  • A dialect can declare the TABLE_FUNCTION relation and supported_table_functions.
  • Isthmus and Spark do not convert table functions to or from Calcite and Spark plans yet.

How

A table function implementation is modeled as a SimpleExtension.TableFunctionVariant: a Function whose return type is the YAML schema, so argument conversion, function anchors and the extension collector work unchanged. When an implementation omits the schema the producer determines it, so resolving the output type from the declaration throws. The relation always carries the concrete, non-nullable schema from the plan, and converting a TableFunctionRel without one is rejected. ExtensionLookup.getTableFunction is a default method, so existing lookup implementations keep compiling.

The tests round-trip both generate_series signatures, a lateral join whose table function arguments reference the left row, and the spec's lateral_generate_series example as a whole plan. They also cover the rejection of a nullable or missing schema and of a reference to a function that is not a table function, and how a schema is resolved from a declaration.

alexandrefimov and others added 6 commits November 11, 2026 05:50
Apply the read filter before selecting columns, and apply emit to the projected schema. Preserve the field order of the mask on named tables, virtual tables and local files.

BREAKING CHANGE: Spark now applies whole-column read masks in selection order and rejects unsupported nested read masks.
Read and write detached relations without losing opaque references. Accept named-lambda capability declarations and report unsupported plan definitions. Supply the execution timezone for calendar arithmetic on zoned timestamps and match each overload against its argument count.

BREAKING CHANGE: Replace the removed subtract:ptstz_iyear overload with subtract:ptstz_iyear_str and supply an IANA timezone or the current_timezone expression.
The datetime mapper runs before default matching. It claimed year/month arithmetic on a zoned
timestamp even when another extension declares the two operands, and replaced that call with the
standard three-argument function.

The mapper now leaves a call to default matching when a declaration matches the operand types
exactly. In the other direction, a standard call keeps its current_timezone argument when the two
remaining operands would convert to that declaration.
… operands

The check that decides whether an aggregate needs a carried binding took the first declaration with
a matching signature. Conversion from Calcite prefers a later declaration when the first one does
not bind the operands. The check now applies the same operand test, so the binding stays in that
case.
Spec v0.109.0 requires a UUID literal to be exactly 16 bytes in network
byte order. Java already encoded and decoded big-endian, but decoding
read the first 16 bytes of a longer value and failed with a
BufferUnderflowException on a shorter one. It now rejects any other
length with an IllegalArgumentException.

The release also adds table functions, whose functions_table.yaml the
extension model cannot read yet, so the default catalog leaves it out
until they are modeled.

BREAKING CHANGE: converting a UUID literal whose bytes are not exactly
16 long now throws IllegalArgumentException instead of decoding the
first 16 bytes.
Substrait v0.109.0 adds table functions. An extension declares them
under table_functions, with an optional schema in place of a return
type, and a TableFunctionRel calls one to produce zero or more rows.
Its arguments may reference outer rows, so on the right of a lateral
join it produces rows for each left row.

The extension model now reads table_functions, and the default catalog
loads functions_table.yaml, which declares generate_series. A new
TableFunction relation converts to and from TableFunctionRel, and a
dialect can declare the TABLE_FUNCTION relation and
supported_table_functions. Isthmus and Spark do not convert table
functions yet.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Adam-Alani

Copy link
Copy Markdown
Contributor Author

This builds on #1453 and #1467, so the diff also shows their commits. Only 6a56af1 is new here. I'll rebase as they land.

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.

3 participants