Implementation:Duckdb Duckdb Generate Functions
Overview
Concrete tool for generating DuckDB function registration code and extension function lookup tables. This implementation comprises two Python scripts: generate_functions.py (which produces C++ registration code for built-in functions) and generate_extensions_function.py (which scans extension source trees and builds lookup tables mapping function names to their owning extensions).
Code Reference
| Script | Source Location | Lines |
|---|---|---|
generate_functions.py |
scripts/generate_functions.py |
L1-259 |
generate_extensions_function.py |
scripts/generate_extensions_function.py |
L1-977 |
generate_functions.py
This script reads function registration JSON files and generates C++ source code that registers each declared function with the DuckDB catalog. The generated code contains the complete list of built-in functions (scalar, aggregate, table, pragma) along with their signatures and metadata.
generate_extensions_function.py
This script scans extension source directories, identifies which functions each extension provides, and builds lookup tables that map function names to their owning extension. These tables allow DuckDB to suggest or auto-load the correct extension when a user references a function that is not currently loaded.
I/O Contract
Inputs
| Input | Description | Consumed By |
|---|---|---|
| Function definition JSON files | Declarative specifications of built-in functions (name, type, signatures) | generate_functions.py
|
| Extension source directories | Source trees of DuckDB extensions containing function implementations | generate_extensions_function.py
|
Outputs
| Output File | Description | Produced By |
|---|---|---|
src/function/function_list.cpp |
C++ source registering all built-in functions | generate_functions.py
|
src/include/duckdb/main/extension_entries.hpp |
C++ header containing extension-to-function lookup tables | generate_extensions_function.py
|
External Dependencies
- python3 -- Both scripts require a Python 3 interpreter.
Usage Examples
Generating built-in function registration code:
python3 scripts/generate_functions.py
This reads the function definition JSON inputs and writes the generated C++ registration code to src/function/function_list.cpp.
Generating extension function lookup tables:
python3 scripts/generate_extensions_function.py
This scans the extension source trees and writes the generated lookup tables to src/include/duckdb/main/extension_entries.hpp.
Typical build integration:
Both scripts are invoked as part of the DuckDB code generation pipeline. When adding a new built-in function, update the corresponding JSON definition file and re-run generate_functions.py. When adding functions to an extension, re-run generate_extensions_function.py to update the lookup tables.
# Regenerate both artifacts
python3 scripts/generate_functions.py
python3 scripts/generate_extensions_function.py