Skip to content

Commit 76bc8eb

Browse files
Add a duckdb extension to vortex (#2610)
Initial duckdb extension package. This copies the `https://github.com/duckdb/extension-template` into our tree, there will be a `vortex-duckdb` crate to interface with this extension.
1 parent 7590726 commit 76bc8eb

21 files changed

+486
-0
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "duckdb"]
2+
path = duckdb/duckdb
3+
url = https://github.com/duckdb/duckdb
4+
[submodule "extension-ci-tools"]
5+
path = duckdb/extension-ci-tools
6+
url = https://github.com/duckdb/extension-ci-tools

duckdb-vortex/.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.clang-format

duckdb-vortex/.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.clang-tidy

duckdb-vortex/.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.editorconfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# This workflow calls the main distribution pipeline from DuckDB to build, test and (optionally) release the extension
3+
#
4+
name: Main Extension Distribution Pipeline
5+
on:
6+
push:
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
duckdb-next-build:
16+
name: Build extension binaries
17+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
18+
with:
19+
duckdb_version: main
20+
ci_tools_version: main
21+
extension_name: vortex_duckdb
22+
23+
duckdb-stable-build:
24+
name: Build extension binaries
25+
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
26+
with:
27+
duckdb_version: v1.2.0
28+
ci_tools_version: v1.2.0
29+
extension_name: vortex_duckdb

duckdb-vortex/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
build
2+
.idea
3+
cmake-build-debug
4+
duckdb_unittest_tempdir/
5+
.DS_Store
6+
testext
7+
test/python/__pycache__/
8+
.Rhistory
9+
10+
# Keep CMAKE
11+
12+
!CMakeLists.txt

duckdb-vortex/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
# Set extension name here
4+
set(TARGET_NAME vortex_duckdb)
5+
6+
# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
7+
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
8+
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it..
9+
find_package(OpenSSL REQUIRED)
10+
11+
set(EXTENSION_NAME ${TARGET_NAME}_extension)
12+
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
13+
14+
project(${TARGET_NAME})
15+
include_directories(src/include)
16+
17+
set(EXTENSION_SOURCES src/vortex_duckdb_extension.cpp)
18+
19+
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
20+
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
21+
22+
# Link OpenSSL in both the static library as the loadable extension
23+
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
24+
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
25+
26+
install(
27+
TARGETS ${EXTENSION_NAME}
28+
EXPORT "${DUCKDB_EXPORT_SET}"
29+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
30+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")

duckdb-vortex/LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2018-2025 Stichting DuckDB Foundation
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

duckdb-vortex/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2+
3+
# Configuration of extension
4+
EXT_NAME=vortex_duckdb
5+
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
6+
7+
# Include the Makefile from extension-ci-tools
8+
include extension-ci-tools/makefiles/duckdb_extension.Makefile

duckdb-vortex/README.md

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# VortexDuckdb
2+
3+
This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship
4+
your own DuckDB extension.
5+
6+
---
7+
8+
This extension, VortexDuckdb, allow you to ... <extension_goal>.
9+
10+
## Building
11+
12+
### Install required system dependencies
13+
14+
#### MacOS
15+
16+
```shell
17+
brew install pkg-config
18+
```
19+
20+
### Managing dependencies
21+
22+
DuckDB extensions uses VCPKG for dependency management. Enabling VCPKG is very simple: follow
23+
the [installation instructions](https://vcpkg.io/en/getting-started) or just run the following:
24+
25+
```shell
26+
git clone https://github.com/Microsoft/vcpkg.git
27+
./vcpkg/bootstrap-vcpkg.sh
28+
export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake
29+
```
30+
31+
Note: VCPKG is only required for extensions that want to rely on it for dependency management. If you want to develop an
32+
extension without dependencies, or want to do your own dependency management, just skip this step. Note that the example
33+
extension uses VCPKG to build with a dependency for instructive purposes, so when skipping this step the build may not
34+
work without removing the dependency.
35+
36+
### Build steps
37+
38+
Now to build the extension, run:
39+
40+
```sh
41+
make
42+
```
43+
44+
The main binaries that will be built are:
45+
46+
```sh
47+
./build/release/duckdb
48+
./build/release/test/unittest
49+
./build/release/extension/vortex_duckdb/vortex_duckdb.duckdb_extension
50+
```
51+
52+
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded.
53+
- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary.
54+
- `vortex_duckdb.duckdb_extension` is the loadable binary as it would be distributed.
55+
56+
## Running the extension
57+
58+
To run the extension code, simply start the shell with `./build/release/duckdb`.
59+
60+
Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function
61+
`vortex_duckdb()` that takes a string arguments and returns a string:
62+
63+
```
64+
D select vortex_duckdb('Jane') as result;
65+
┌───────────────┐
66+
│ result │
67+
│ varchar │
68+
├───────────────┤
69+
│ VortexDuckdb Jane 🐥 │
70+
└───────────────┘
71+
```
72+
73+
## Running the tests
74+
75+
Different tests can be created for DuckDB extensions. The primary way of testing DuckDB extensions should be the SQL
76+
tests in `./test/sql`. These SQL tests can be run using:
77+
78+
```sh
79+
make test
80+
```
81+
82+
### Installing the deployed binaries
83+
84+
To install your extension binaries from S3, you will need to do two things. Firstly, DuckDB should be launched with the
85+
`allow_unsigned_extensions` option set to true. How to set this will depend on the client you're using. Some examples:
86+
87+
CLI:
88+
89+
```shell
90+
duckdb -unsigned
91+
```
92+
93+
Python:
94+
95+
```python
96+
con = duckdb.connect(':memory:', config={'allow_unsigned_extensions': 'true'})
97+
```
98+
99+
NodeJS:
100+
101+
```js
102+
db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"});
103+
```
104+
105+
Secondly, you will need to set the repository endpoint in DuckDB to the HTTP url of your bucket + version of the
106+
extension
107+
you want to install. To do this run the following SQL query in DuckDB:
108+
109+
```sql
110+
SET
111+
custom_extension_repository='bucket.s3.eu-west-1.amazonaws.com/<your_extension_name>/latest';
112+
```
113+
114+
Note that the `/latest` path will allow you to install the latest extension version available for your current version
115+
of
116+
DuckDB. To specify a specific version, you can pass the version instead.
117+
118+
After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB:
119+
120+
```sql
121+
INSTALL
122+
vortex_duckdb
123+
LOAD vortex_duckdb
124+
```

duckdb-vortex/docs/UPDATING.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Extension updating
2+
When cloning this template, the target version of DuckDB should be the latest stable release of DuckDB. However, there
3+
will inevitably come a time when a new DuckDB is released and the extension repository needs updating. This process goes
4+
as follows:
5+
6+
- Bump submodules
7+
- `./duckdb` should be set to latest tagged release
8+
- `./extension-ci-tools` should be set to updated branch corresponding to latest DuckDB release. So if you're building for DuckDB `v1.1.0` there will be a branch in `extension-ci-tools` named `v1.1.0` to which you should check out.
9+
- Bump versions in `./github/workflows`
10+
- `duckdb_version` input in `duckdb-stable-build` job in `MainDistributionPipeline.yml` should be set to latest tagged release
11+
- `duckdb_version` input in `duckdb-stable-deploy` job in `MainDistributionPipeline.yml` should be set to latest tagged release
12+
- the reusable workflow `duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml` for the `duckdb-stable-build` job should be set to latest tagged release
13+
14+
# API changes
15+
DuckDB extensions built with this extension template are built against the internal C++ API of DuckDB. This API is not guaranteed to be stable.
16+
What this means for extension development is that when updating your extensions DuckDB target version using the above steps, you may run into the fact that your extension no longer builds properly.
17+
18+
Currently, DuckDB does not (yet) provide a specific change log for these API changes, but it is generally not too hard to figure out what has changed.
19+
20+
For figuring out how and why the C++ API changed, we recommend using the following resources:
21+
- DuckDB's [Release Notes](https://github.com/duckdb/duckdb/releases)
22+
- DuckDB's history of [Core extension patches](https://github.com/duckdb/duckdb/commits/main/.github/patches/extensions)
23+
- The git history of the relevant C++ Header file of the API that has changed

duckdb-vortex/duckdb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5f5512b827df6397afd31daedb4bbdee76520019

duckdb-vortex/extension-ci-tools

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 58970c538d35919db875096460c05806056f4de0

duckdb-vortex/extension_config.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is included by DuckDB's build system. It specifies which extension to load
2+
3+
# Extension from this repo
4+
duckdb_extension_load(vortex_duckdb
5+
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
6+
LOAD_TESTS
7+
)
8+
9+
# Any extra extensions that should be built
10+
# e.g.: duckdb_extension_load(json)
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# Extension upload script
4+
5+
# Usage: ./extension-upload.sh <name> <extension_version> <duckdb_version> <architecture> <s3_bucket> <copy_to_latest> <copy_to_versioned>
6+
# <name> : Name of the extension
7+
# <extension_version> : Version (commit / version tag) of the extension
8+
# <duckdb_version> : Version (commit / version tag) of DuckDB
9+
# <architecture> : Architecture target of the extension binary
10+
# <s3_bucket> : S3 bucket to upload to
11+
# <copy_to_latest> : Set this as the latest version ("true" / "false", default: "false")
12+
# <copy_to_versioned> : Set this as a versioned version that will prevent its deletion
13+
14+
set -e
15+
16+
if [[ $4 == wasm* ]]; then
17+
ext="/tmp/extension/$1.duckdb_extension.wasm"
18+
else
19+
ext="/tmp/extension/$1.duckdb_extension"
20+
fi
21+
22+
echo $ext
23+
24+
script_dir="$(dirname "$(readlink -f "$0")")"
25+
26+
# calculate SHA256 hash of extension binary
27+
cat $ext > $ext.append
28+
29+
if [[ $4 == wasm* ]]; then
30+
# 0 for custom section
31+
# 113 in hex = 275 in decimal, total lenght of what follows (1 + 16 + 2 + 256)
32+
# [1(continuation) + 0010011(payload) = \x93, 0(continuation) + 10(payload) = \x02]
33+
echo -n -e '\x00' >> $ext.append
34+
echo -n -e '\x93\x02' >> $ext.append
35+
# 10 in hex = 16 in decimal, lenght of name, 1 byte
36+
echo -n -e '\x10' >> $ext.append
37+
echo -n -e 'duckdb_signature' >> $ext.append
38+
# the name of the WebAssembly custom section, 16 bytes
39+
# 100 in hex, 256 in decimal
40+
# [1(continuation) + 0000000(payload) = ff, 0(continuation) + 10(payload)],
41+
# for a grand total of 2 bytes
42+
echo -n -e '\x80\x02' >> $ext.append
43+
fi
44+
45+
# (Optionally) Sign binary
46+
if [ "$DUCKDB_EXTENSION_SIGNING_PK" != "" ]; then
47+
echo "$DUCKDB_EXTENSION_SIGNING_PK" > private.pem
48+
$script_dir/../duckdb/scripts/compute-extension-hash.sh $ext.append > $ext.hash
49+
openssl pkeyutl -sign -in $ext.hash -inkey private.pem -pkeyopt digest:sha256 -out $ext.sign
50+
rm -f private.pem
51+
fi
52+
53+
# Signature is always there, potentially defaulting to 256 zeros
54+
truncate -s 256 $ext.sign
55+
56+
# append signature to extension binary
57+
cat $ext.sign >> $ext.append
58+
59+
# compress extension binary
60+
if [[ $4 == wasm_* ]]; then
61+
brotli < $ext.append > "$ext.compressed"
62+
else
63+
gzip < $ext.append > "$ext.compressed"
64+
fi
65+
66+
set -e
67+
68+
# Abort if AWS key is not set
69+
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
70+
echo "No AWS key found, skipping.."
71+
exit 0
72+
fi
73+
74+
# upload versioned version
75+
if [[ $7 = 'true' ]]; then
76+
if [[ $4 == wasm* ]]; then
77+
aws s3 cp $ext.compressed s3://$5/$1/$2/$3/$4/$1.duckdb_extension.wasm --acl public-read --content-encoding br --content-type="application/wasm"
78+
else
79+
aws s3 cp $ext.compressed s3://$5/$1/$2/$3/$4/$1.duckdb_extension.gz --acl public-read
80+
fi
81+
fi
82+
83+
# upload to latest version
84+
if [[ $6 = 'true' ]]; then
85+
if [[ $4 == wasm* ]]; then
86+
aws s3 cp $ext.compressed s3://$5/$3/$4/$1.duckdb_extension.wasm --acl public-read --content-encoding br --content-type="application/wasm"
87+
else
88+
aws s3 cp $ext.compressed s3://$5/$3/$4/$1.duckdb_extension.gz --acl public-read
89+
fi
90+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# This is an example script that can be used to install additional toolchain dependencies. Feel free to remove this script
4+
# if no additional toolchains are required
5+
6+
# To enable this script, set the `custom_toolchain_script` option to true when calling the reusable workflow
7+
# `.github/workflows/_extension_distribution.yml` from `https://github.com/duckdb/extension-ci-tools`
8+
9+
# note that the $DUCKDB_PLATFORM environment variable can be used to discern between the platforms
10+
echo "This is the sample custom toolchain script running for architecture '$DUCKDB_PLATFORM' for the vortex_duckdb extension."
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "duckdb.hpp"
4+
5+
namespace duckdb {
6+
7+
class VortexDuckdbExtension : public Extension {
8+
public:
9+
void Load(DuckDB &db) override;
10+
std::string Name() override;
11+
std::string Version() const override;
12+
};
13+
14+
} // namespace duckdb

0 commit comments

Comments
 (0)