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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.clang-format

duckdb-vortex/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.clang-tidy

duckdb-vortex/.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.editorconfig
Lines changed: 29 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 30 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 124 additions & 0 deletions
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+
```

0 commit comments

Comments
 (0)