Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,11 @@ jobs:
strategy:
fail-fast: false
matrix:
duckdb: [v1.5.6, v2.0-cyanoptera]
duckdb: [v1.5.6, v2.0.1]
env:
GEN: ninja
DUCKDB_VERSION: ${{ matrix.duckdb }}
SQLCTX_NATIVE_PEG: ${{ matrix.duckdb == 'v2.0-cyanoptera' && '1' || '' }}
SQLCTX_NATIVE_PEG: ${{ matrix.duckdb == 'v2.0.1' && '1' || '' }}

steps:
- uses: actions/checkout@v4
Expand Down
77 changes: 46 additions & 31 deletions .github/workflows/duckdb-extension-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
duckdb_version:
description: "Stable DuckDB release to package (v1.5.6); Cyanoptera is tested separately in CI"
description: "Stable DuckDB release to package (v1.5.6 or v2.0.1)"
required: true
default: "v1.5.6"
type: string
Expand Down Expand Up @@ -32,13 +32,38 @@ env:
MACOSX_DEPLOYMENT_TARGET: "11.0"

jobs:
versions:
name: Select stable DuckDB releases
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.duckdb.outputs.versions }}
steps:
- name: Resolve DuckDB versions
id: duckdb
env:
EVENT_NAME: ${{ github.event_name }}
REQUESTED_VERSION: ${{ inputs.duckdb_version }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
case "$REQUESTED_VERSION" in
v1.5.6|v2.0.1) ;;
*) echo "Unsupported DuckDB version" >&2; exit 1 ;;
esac
printf 'versions=["%s"]\n' "$REQUESTED_VERSION" >> "$GITHUB_OUTPUT"
else
echo 'versions=["v1.5.6","v2.0.1"]' >> "$GITHUB_OUTPUT"
fi

build:
name: Build ${{ matrix.platform }} extension package
name: Build ${{ matrix.duckdb_version }} ${{ matrix.platform }} extension package
needs: versions
runs-on: ${{ matrix.runner }}
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
duckdb_version: ${{ fromJSON(needs.versions.outputs.versions) }}
platform: [linux_amd64, linux_arm64, osx_amd64, osx_arm64]
include:
- platform: linux_amd64
runner: ubuntu-24.04
Expand Down Expand Up @@ -72,30 +97,10 @@ jobs:
with:
suffix: ${{ github.workflow }}-${{ github.job }}-${{ strategy.job-index || 0 }}

- name: Resolve DuckDB version
id: duckdb
env:
EVENT_NAME: ${{ github.event_name }}
REQUESTED_VERSION: ${{ inputs.duckdb_version }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
VERSION="$REQUESTED_VERSION"
else
VERSION="v1.5.6"
fi

# Publish stable artifacts only. CI separately tests the pinned PEG development build.
if [ "$VERSION" != "v1.5.6" ]; then
echo "Unsupported DuckDB version" >&2
exit 1
fi

echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Fetch DuckDB dependencies
working-directory: sqlctx-duckdb
env:
DUCKDB_VERSION: ${{ steps.duckdb.outputs.version }}
DUCKDB_VERSION: ${{ matrix.duckdb_version }}
run: make deps DUCKDB_VERSION="$DUCKDB_VERSION"

- name: Build extension
Expand All @@ -106,12 +111,19 @@ jobs:

- name: Run extension tests
working-directory: sqlctx-duckdb
run: make test
env:
SQLCTX_NATIVE_PEG: ${{ matrix.duckdb_version == 'v2.0.1' && '1' || '' }}
EXPECTED_VERSION: ${{ matrix.duckdb_version }}
run: |
VERSION=$(./build/release/duckdb -unsigned -csv -noheader :memory: -c \
"LOAD 'build/release/extension/sqlctx/sqlctx.duckdb_extension'; SELECT version();")
test "$VERSION" = "$EXPECTED_VERSION"
make test

- name: Package extension artifact
working-directory: sqlctx-duckdb
env:
DUCKDB_VERSION: ${{ steps.duckdb.outputs.version }}
DUCKDB_VERSION: ${{ matrix.duckdb_version }}
PLATFORM: ${{ matrix.platform }}
run: |
mkdir -p dist
Expand All @@ -128,7 +140,7 @@ jobs:
- name: Upload extension artifact
uses: actions/upload-artifact@v4
with:
name: sqlctx-duckdb-extension-${{ matrix.platform }}
name: sqlctx-duckdb-extension-${{ matrix.duckdb_version }}-${{ matrix.platform }}
path: sqlctx-duckdb/dist/*
if-no-files-found: error

Expand All @@ -140,7 +152,7 @@ jobs:

github-release:
name: Attach extension artifact to GitHub release
needs: build
needs: [versions, build]
if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.create_github_release == true) }}
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -181,6 +193,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.release.outputs.tag }}
RELEASE_COMMIT: ${{ github.sha }}
DUCKDB_VERSIONS: ${{ join(fromJSON(needs.versions.outputs.versions), ' ') }}
run: |
set -euo pipefail
# Checkout can create a lightweight local ref for an annotated tag.
Expand All @@ -191,10 +204,12 @@ jobs:
exit 1
fi
cd dist
for PLATFORM in linux_amd64 linux_arm64 osx_amd64 osx_arm64; do
ASSET="sqlctx-duckdb-1.5.6-${PLATFORM}.duckdb_extension"
test -s "$ASSET"
sha256sum --check "$ASSET.sha256"
for VERSION in $DUCKDB_VERSIONS; do
for PLATFORM in linux_amd64 linux_arm64 osx_amd64 osx_arm64; do
ASSET="sqlctx-duckdb-${VERSION#v}-${PLATFORM}.duckdb_extension"
test -s "$ASSET"
sha256sum --check "$ASSET.sha256"
done
done
cat *.sha256 > SHA256SUMS
cp ../LICENSE .
Expand Down
32 changes: 13 additions & 19 deletions docs/duckdb-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The sqlctx DuckDB extension embeds the Rust native runtime in DuckDB. It is a na

## Status

The extension is experimental and targets **DuckDB 1.5.6** only. It is **not** in the
The extension is experimental and targets **DuckDB 2.0.1 and 1.5.6**. It is **not** in the
DuckDB community extension registry, so `INSTALL sqlctx FROM community` fails.
Community publication is planned; once it lands, installation will be:

Expand All @@ -29,16 +29,14 @@ The extension build needs Rust, DuckDB extension build tooling, and Ninja.

```bash
cd sqlctx-duckdb
make deps DUCKDB_VERSION=v1.5.6
make deps DUCKDB_VERSION=v2.0.1
make
make test
SQLCTX_NATIVE_PEG=1 make test
```

`make deps` accepts only `DUCKDB_VERSION=v1.5.6` (the default) or `v2.0-cyanoptera`,
a pinned DuckDB development commit that CI uses to exercise the native PEG grammar.
Release artifacts are built for v1.5.6 only. The repository vendors a matching
`extension-ci-tools` checkout; update both together before building against a
different DuckDB tag.
For the DuckDB 1.5.6 compatibility frontend, use `make deps DUCKDB_VERSION=v1.5.6`
(the default), then `make` and `make test`. Build each host version in a separate
checkout or clean build directory. The repository vendors the extension build tools.

The local loadable extension is produced at:

Expand All @@ -49,12 +47,10 @@ sqlctx-duckdb/build/release/extension/sqlctx/sqlctx.duckdb_extension
Load it in the DuckDB shell built by the extension workflow:

```bash
./build/release/duckdb -unsigned
./build/release/duckdb -unsigned -cmd "LOAD '$PWD/build/release/extension/sqlctx/sqlctx.duckdb_extension';"
```

```sql
LOAD 'build/release/extension/sqlctx/sqlctx.duckdb_extension';
```
The official macOS CLI requires an absolute path when loading the extension.

For embedded clients, set DuckDB's `allow_unsigned_extensions` database configuration before opening the connection.

Expand Down Expand Up @@ -137,10 +133,10 @@ Use `.github/workflows/duckdb-extension-release.yml`.

The workflow:

- fetches DuckDB v1.5.6 with `make deps` and verifies the vendored `extension-ci-tools`,
- fetches each selected DuckDB release tag with `make deps` and verifies the vendored `extension-ci-tools`,
- builds the Rust-backed extension for `linux_amd64`, `linux_arm64`, `osx_amd64`, and `osx_arm64`,
- runs the DuckDB sqllogictests, including native YAML load, native SQL definition file load, relationship rewrite, semantic select, persistence, and invalid-version coverage,
- uploads the four extension artifacts with their checksums,
- uploads a separate extension artifact for each DuckDB version and platform with its checksum,
- on a `sqlctx-duckdb-v*` tag push (or a manual run with `create_github_release`), creates the GitHub release with the artifacts, `SHA256SUMS`, and `LICENSE`. It never overwrites an existing release.

It does not publish to the DuckDB community extension registry.
Expand All @@ -152,13 +148,11 @@ It does not publish to the DuckDB community extension registry.
| Native format | `1` |
| Rust runtime crate | `0.1.0` |
| DuckDB extension release | `0.1.0` |
| DuckDB version | `1.5.6` |
| DuckDB version | `2.0.1` or `1.5.6` |

DuckDB extension artifacts are ABI-sensitive. Rebuild the extension when changing the DuckDB target version or the Rust native runtime version.

The extension loads only into DuckDB 1.5.6. DuckDB 1.5.6 cannot open database files
written by DuckDB 2.x (`Trying to read a database file with version number 69`), so
a file created by a newer DuckDB, for example through a Python environment that
resolved `duckdb` 2.x, cannot be used with this extension.
For a database file written in DuckDB 2.0 storage format, open it with DuckDB
2.0.1 and load the matching 2.0.1 extension.

The extension should accept the same native YAML and native SQL definition contract as the Rust runtime. If extension-only syntax is added, it should either be aligned with the Rust SQL loader or documented as DuckDB-only.
2 changes: 1 addition & 1 deletion docs/rust-native-runtime-packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Python remains the default engine; installing the Rust bindings does not promote
Workflow files live in `.github/workflows/`. Rust crate and wheel versions must
match; package metadata tests enforce this. Root Python and WASM versions are
separate. The DuckDB extension is tied to the DuckDB build version, currently
`v1.5.6`. Do not use a release intended for a different DuckDB ABI.
`v2.0.1` or `v1.5.6`. Select the artifact matching the host version and platform.

## Install from a checkout or downloaded artifact

Expand Down
21 changes: 18 additions & 3 deletions sqlctx-duckdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ function(sqlctx_detect_apis)
parser/expression/columnref_expression.hpp parser/tableref/basetableref.hpp
parser/parser_options.hpp parser/expression/constant_expression.hpp
parser/statement/insert_statement.hpp
parser/grammar_extension.hpp parser/peg/compiled_grammar.hpp
planner/operator/logical_get.hpp)
parser/grammar_extension.hpp parser/peg/compiled_grammar.hpp parser/peg/transformer/peg_transformer.hpp
planner/operator/logical_get.hpp main/client_config.hpp)
if(EXISTS "${CMAKE_SOURCE_DIR}/src/include/duckdb/${header}")
file(SHA256 "${CMAKE_SOURCE_DIR}/src/include/duckdb/${header}" header_hash)
string(APPEND host_api ";${header_hash}")
endif()
endforeach()
if(NOT SQLCTX_HOST_API STREQUAL host_api)
foreach(api TOKEN_PARSE_FN NEW_IDENTIFIER_API NEW_EXPRESSION_API QUALIFIED_TABLE_API BUILTIN_PARSER_OPTIONS LITERAL_API GRAMMAR_EXTENSION INSERT_QUERY_NODE BOUND_TABLE_FUNCTION GRAMMAR_EXTENSION_LIST)
foreach(api TOKEN_PARSE_FN NEW_IDENTIFIER_API NEW_EXPRESSION_API QUALIFIED_TABLE_API BUILTIN_PARSER_OPTIONS LITERAL_API GRAMMAR_EXTENSION INSERT_QUERY_NODE BOUND_TABLE_FUNCTION GRAMMAR_EXTENSION_LIST ARENA_TRANSFORM SHELL_GRAMMAR_CONTEXT)
unset(SQLCTX_${api} CACHE)
endforeach()
set(SQLCTX_HOST_API "${host_api}" CACHE INTERNAL "DuckDB headers used for compatibility probes" FORCE)
Expand Down Expand Up @@ -87,6 +87,21 @@ function(sqlctx_detect_apis)
duckdb::CompiledGrammar::Create(duckdb::vector<duckdb::reference<duckdb::GrammarExtension>> {extension});
}
" SQLCTX_GRAMMAR_EXTENSION_LIST)
check_cxx_source_compiles("
#include <duckdb/parser/peg/transformer/peg_transformer.hpp>
void probe(duckdb::PEGTransformer &transformer) { transformer.MakeResult<bool>(true); }
" SQLCTX_ARENA_TRANSFORM)
check_cxx_source_compiles("
#include <duckdb/main/client_config.hpp>
#include <duckdb/parser/parser_options.hpp>
#include <duckdb/parser/peg/compiled_grammar.hpp>
using namespace duckdb;
void probe(ParserOptions &options) {
auto &config = ClientConfig::GetConfig(*options.context);
if (!config.current_dialect && !config.connected_grammar)
CompiledGrammar::Create(*options.context, vector<string>{\"shell\", \"sqlctx\"});
}
" SQLCTX_SHELL_GRAMMAR_CONTEXT)
configure_file(src/include/sqlctx_compat.hpp.in sqlctx_compat.hpp)
cmake_pop_check_state()
endfunction()
Expand Down
12 changes: 8 additions & 4 deletions sqlctx-duckdb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
EXT_NAME=sqlctx
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
SUPPORTED_DUCKDB_VERSION := v1.5.6
SUPPORTED_DUCKDB_2 := v2.0.1
SUPPORTED_DUCKDB_NEXT := v2.0-cyanoptera
# Pin the moving development branch to the native PEG API exercised by CI.
DUCKDB_NEXT_COMMIT := 80e17fc252edd6d9e9b090ae00a1100daef4876a
DUCKDB_VERSION ?= $(SUPPORTED_DUCKDB_VERSION)
# DuckDB 2.0 derives a development ABI from the commit count unless the
# release version is supplied. Use the tag on the source being compiled.
OVERRIDE_GIT_DESCRIBE ?= $(filter $(SUPPORTED_DUCKDB_2),$(shell git -C $(DUCKDB_SRCDIR) tag --points-at HEAD 2>/dev/null))
# Exercise coexistence with the parser override preloaded by packaged shells.
DEFAULT_TEST_EXTENSION_DEPS := autocomplete

.PHONY: deps
deps:
@if [ "$(DUCKDB_VERSION)" != "$(SUPPORTED_DUCKDB_VERSION)" ] && [ "$(DUCKDB_VERSION)" != "$(SUPPORTED_DUCKDB_NEXT)" ]; then \
echo "Use DUCKDB_VERSION=$(SUPPORTED_DUCKDB_VERSION) or $(SUPPORTED_DUCKDB_NEXT)."; \
exit 1; \
fi
@case "$(DUCKDB_VERSION)" in \
$(SUPPORTED_DUCKDB_VERSION)|$(SUPPORTED_DUCKDB_2)|$(SUPPORTED_DUCKDB_NEXT)) ;; \
*) echo "Use DUCKDB_VERSION=$(SUPPORTED_DUCKDB_VERSION), $(SUPPORTED_DUCKDB_2), or $(SUPPORTED_DUCKDB_NEXT)."; exit 1 ;; \
esac
@if [ ! -d duckdb/.git ]; then \
rm -rf duckdb; \
git clone --depth 1 --branch $(DUCKDB_VERSION) https://github.com/duckdb/duckdb.git duckdb; \
Expand Down
34 changes: 13 additions & 21 deletions sqlctx-duckdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ A DuckDB extension that adds a SQL-first semantic layer. Define metrics and dime
- **Transactional Definitions**: Commit and roll back model changes with DuckDB transactions
- **Catalog Discovery**: Inspect definitions, metadata, relationships and compatible dimensions with SQL
- **SQL Containers**: Use semantic queries in views, `CREATE TABLE AS`, and `INSERT ... SELECT`
- **Native PEG Grammar**: Composable grammar on the pinned Cyanoptera development build, with a DuckDB 1.5.6 compatibility frontend
- **Native PEG Grammar**: Composable grammar on DuckDB 2.0.1, with a DuckDB 1.5.6 compatibility frontend

## Installation

Build locally against DuckDB 1.5.6:
Build locally against DuckDB 2.0.1:

```bash
make deps DUCKDB_VERSION=v1.5.6
make deps DUCKDB_VERSION=v2.0.1
make
make test
./build/release/duckdb -unsigned
```

```sql
LOAD 'build/release/extension/sqlctx/sqlctx.duckdb_extension';
SQLCTX_NATIVE_PEG=1 make test
./build/release/duckdb -unsigned -cmd "LOAD '$PWD/build/release/extension/sqlctx/sqlctx.duckdb_extension';"
```

For embedded clients, set DuckDB's `allow_unsigned_extensions` database configuration before opening the connection. Community extension installation is planned, but this repository does not yet publish the signed multi-platform artifacts required for `INSTALL sqlctx FROM community`.

The release workflow builds unsigned DuckDB 1.5.6 packages for Linux and macOS
The release workflow builds unsigned DuckDB 2.0.1 and 1.5.6 packages for Linux and macOS
on AMD64 and ARM64. Linux builds use a glibc 2.28 baseline. When installing a
release artifact, verify it against `SHA256SUMS` and give it the filename
`sqlctx.duckdb_extension` before loading it.
Expand Down Expand Up @@ -333,7 +329,7 @@ files raise errors when the semantic catalog is accessed.

## Native PEG frontend

DuckDB 1.5.6 uses the compatibility frontend. The pinned `v2.0-cyanoptera` build
DuckDB 1.5.6 uses the compatibility frontend. DuckDB 2.0.1
registers a `sqlctx` grammar extension for definitions, discovery, removal,
import/export and explicit semantic queries, including nested `PREPARE` and `EXPLAIN`. Definition properties
still use the shared Rust configuration parser; semantic query compilation still
Expand Down Expand Up @@ -586,8 +582,8 @@ rows, including equal-valued metrics on distinct customers.
use `sqlctx_compile_semantic_input` and execute its returned SQL. A scalar projection such as
`SEMANTIC SELECT events.retention FROM events` is rejected. These contracts
do not establish full parity with every Python adapter or API.
- DuckDB 1.5.6 uses the compatibility frontend. Native PEG support is tested against
the pinned 2.x commit, not an arbitrary future 2.x build. Rust still parses model
- DuckDB 1.5.6 uses the compatibility frontend. Native PEG support targets
the released DuckDB 2.0.1 host. Rust parses model
properties and compiles semantic queries.
- The release workflow packages unsigned Linux and macOS builds on AMD64 and ARM64.
Signed community installation is not yet provided by this repository.
Expand Down Expand Up @@ -626,8 +622,7 @@ SELECT sqlctx_rewrite_sql('SELECT orders.revenue FROM orders');
# From this repository checkout
cd sqlctx-duckdb

# Fetch the DuckDB source version used by CI.
# Stable builds and release artifacts target v1.5.6.
# Build the compatibility frontend for DuckDB 1.5.6.
make deps DUCKDB_VERSION=v1.5.6

# Build the extension. CMake builds the sibling sqlctx-rs static library automatically.
Expand All @@ -640,12 +635,9 @@ make test
./build/release/duckdb -unsigned
```

CI also builds `make deps DUCKDB_VERSION=v2.0-cyanoptera`, pinned in the Makefile to
commit `80e17fc252edd6d9e9b090ae00a1100daef4876a`. Run its tests with
`SQLCTX_NATIVE_PEG=1 make test`. Use separate build directories/checkouts when
switching DuckDB versions. CMake probes host APIs rather than assuming C++ ABI
compatibility across releases. Release packaging targets unsigned Linux and macOS
builds for 1.5.6; development-version CI does not publish stable artifacts.
CI builds both released hosts. For 2.0.1, use `make deps DUCKDB_VERSION=v2.0.1`,
`make`, and `SQLCTX_NATIVE_PEG=1 make test`. Use separate build directories/checkouts
when switching DuckDB versions. Each loadable binary targets its host's C++ ABI.

A preview artifact for a published 2.0 alpha runtime must be built from that
runtime's exact commit and carry its version string, because the C++ extension
Expand Down
Loading
Loading