Implementation:Duckdb Duckdb Generate Settings
Overview
Concrete tool for generating DuckDB configuration settings code and storage version constants from JSON specifications. This implementation comprises two entry-point scripts (generate_settings.py and generate_storage_info.py) along with supporting modules that read declarative JSON inputs and produce the C++ headers and source files consumed by the DuckDB engine.
Code Reference
| Script / Module | Source Location | Lines |
|---|---|---|
generate_settings.py |
scripts/generate_settings.py |
L1-10 |
config.py (settings logic) |
scripts/settings_scripts/config.py |
L1-216 |
__init__.py (settings package) |
scripts/settings_scripts/__init__.py |
L1-5 |
generate_storage_info.py |
scripts/generate_storage_info.py |
L1-77 |
generate_settings.py
The entry point for settings generation. This thin wrapper delegates to scripts/settings_scripts/config.py, which contains the core logic for reading the settings JSON and producing C++ output.
settings_scripts/config.py
The main settings generation engine. It parses src/common/settings.json, where each setting is declared with the following fields:
- name -- The setting identifier
- description -- Human-readable description
- sql_type -- The SQL type of the setting value
- scope -- Whether the setting is global, local, or both
- default_value -- The default value applied when not explicitly set
From these declarations, the module generates three C++ output files covering the header declarations, implementation logic, and scope registrations.
generate_storage_info.py
Reads src/storage/version_map.json and produces a C++ header containing storage version constants. These constants are used by the storage layer to verify format compatibility when reading or writing database files.
I/O Contract
Inputs
| Input | Description | Consumed By |
|---|---|---|
src/common/settings.json |
JSON file declaring all database settings (name, description, sql_type, scope, default_value) | generate_settings.py / config.py
|
src/storage/version_map.json |
JSON file mapping storage format version identifiers to version numbers | generate_storage_info.py
|
Outputs
| Output File | Description | Produced By |
|---|---|---|
src/include/duckdb/main/settings.hpp |
C++ header declaring settings classes and interfaces | generate_settings.py
|
src/main/settings/autogenerated_settings.cpp |
C++ source implementing autogenerated settings logic | generate_settings.py
|
src/main/config.cpp |
C++ source containing scope registration entries for each setting | generate_settings.py
|
src/include/duckdb/common/enums/storage_info.hpp |
C++ header defining storage version constants | generate_storage_info.py
|
External Dependencies
- python3 -- Both scripts require a Python 3 interpreter.
Usage Examples
Generating configuration settings code:
python3 scripts/generate_settings.py
This reads src/common/settings.json and writes the generated C++ code to the three output files: settings.hpp, autogenerated_settings.cpp, and config.cpp.
Generating storage version constants:
python3 scripts/generate_storage_info.py
This reads src/storage/version_map.json and writes the generated header to src/include/duckdb/common/enums/storage_info.hpp.
Example settings JSON entry:
{
"name": "threads",
"description": "The number of total threads used by the system",
"sql_type": "BIGINT",
"scope": "global",
"default_value": "autodetect"
}
Typical build integration:
# Regenerate settings and storage info artifacts
python3 scripts/generate_settings.py
python3 scripts/generate_storage_info.py