Skip to content

Expand DuckLake scalar and table macros - #436

Open
faysou wants to merge 3 commits into
datafusion-contrib:mainfrom
faysou:ducklake-macros-pr
Open

faysou wants to merge 3 commits into
datafusion-contrib:mainfrom
faysou:ducklake-macros-pr

Conversation

@faysou

@faysou faysou commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Use register_ducklake_macros to register snapshot-visible scalar and table macros in
DataFusion. The catalog provider loads implementations and parameters. DataFusion binds defaults
in parameter order and resolves table-macro SQL in the registered DuckLake catalog. It reports
a planning error for macro SQL it cannot run.

Macro registration and expansion

flowchart LR
    Snapshot["Catalog snapshot"] --> Rows["Read visible definitions and ordered parameters"]
    Rows --> Register["Register scalar and table macros"]
    Register --> Bind["Bind call arguments and defaults"]
    Bind --> Plan["Plan scalar expression or catalog-scoped table query"]
Loading

Verification

  • All-feature Clippy and all three macro tests pass with all features enabled.

  • duckdb_macros_match_scalar_and_table_oracles compares scalar and table calls, including
    defaults and schema-qualified calls, with DuckDB.

  • duckdb_writer_initializes_macro_tables and sqlite_writer_initializes_macro_tables
    exercise catalog initialization on both backends.

  • The integration test target compiles with the macOS CI feature set. DuckDB writer
    initialization requires write-duckdb. The macro oracle and SQLite initialization
    compile with DuckDB metadata reads and SQLite writes enabled.

Specification proof

DuckLake rule Implementation invariant Discriminating proof
Macro metadata records snapshot visibility. Use the selected catalog snapshot to load visible definitions. The DuckDB oracle registers seeded scalar and table definitions.
Macro implementations stores SQL, dialect, and macro kind. Plan the registered body as a scalar expression or table query. The oracle compares scalar values and table results with DuckDB.
Macro parameters records argument order and defaults. Sort by the stored parameter positions and bind omitted arguments from defaults. Oracle calls omit optional arguments and compare the resulting values.

Reference implementation

DuckDB's DuckLake extension resolves the same catalog rows before building scalar and table
macros. DataFusion handles SQL expansion in this PR and reports planning errors for SQL it
cannot run. Macro catalog query,
Implementation and parameter loading,
Macro reconstruction.

Read snapshot-visible scalar and table macro definitions from every metadata provider. Expand typed and defaulted parameters during DataFusion planning, and report stored-SQL errors with the macro name and dialect. Add DuckDB oracle coverage for scalar, table, schema-qualified, defaulted, and unsupported macro forms.
Start a new CI run after the hosted macOS job was canceled.
The macOS feature set enables DuckDB metadata reads and SQLite writes.
Compile the DuckDB writer fixture only when write-duckdb is enabled.

This branch has not been deployed

No deployments
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