Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ duckdb_unittest_tempdir/
testext
test/python/__pycache__/
.Rhistory
*.csv
vcpkg/
resources/*
duckdb/
temp_dir/
mydb.duckdb
plans/
*.json
archived_tests/*
queries/synthetic_query/*.csv
queries/synthetic_query/*.db
*.zip
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set extension name here
set(TARGET_NAME cactusdb)
Expand All @@ -7,8 +9,16 @@ set(TARGET_NAME cactusdb)
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it..



find_package(OpenSSL REQUIRED)
find_package(Eigen3 REQUIRED)
if(DEFINED ENV{LIBTORCH_DIR})
set(Torch_DIR "$ENV{LIBTORCH_DIR}/share/cmake/Torch")
elseif(DEFINED LIBTORCH_DIR)
set(Torch_DIR "${LIBTORCH_DIR}/share/cmake/Torch")
endif()
find_package(Torch REQUIRED)

set(EXTENSION_NAME ${TARGET_NAME}_extension)

Expand All @@ -19,18 +29,21 @@ set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
project(${TARGET_NAME})
include_directories(src/include)
include_directories(${EIGEN3_INCLUDE_DIR})
include_directories(${TORCH_INCLUDE_DIRS})

set(EXTENSION_SOURCES src/cactusdb_extension.cpp)
add_subdirectory(src/ml_functions)
add_subdirectory(src/util)
add_subdirectory(src/optimization)
add_subdirectory(src/cost_model)
message(STATUS "EXTENSION_SOURCES include ${EXTENSION_SOURCES}")

build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})

# Link OpenSSL in both the static library as the loadable extension
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto Eigen3::Eigen)
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto Eigen3::Eigen)
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto Eigen3::Eigen ${TORCH_LIBRARIES})
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto Eigen3::Eigen ${TORCH_LIBRARIES})

install(
TARGETS ${EXTENSION_NAME}
Expand Down
56 changes: 48 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
# OPTBench
# OPTBench

This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship your own DuckDB extension.

---

This extension, OPTBench, allows you to ... <extension_goal>.
This extension, OPTBench, is a DuckDB extension for benchmarking query optimizers.


## Building
### Managing dependencies
DuckDB extensions use VCPKG for dependency management. Enabling VCPKG is very simple: follow the [installation instructions](https://vcpkg.io/en/getting-started) or just run the following:
```shell
git clone https://github.com/Microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh
export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake
### Prerequisites
Install the following system dependencies before building:

```sh
# Ubuntu / Debian
sudo apt install libssl-dev libeigen3-dev
```

### Clone with submodules
This repo uses git submodules (`duckdb` and `extension-ci-tools`). Always clone with:

```sh
git clone --recurse-submodules <repo-url>
```

If you already cloned without submodules, run:

```sh
git submodule update --init --recursive
```

### LibTorch dependency
This project requires LibTorch (the C++ PyTorch distribution). If you do not have CUDA available, download the CPU-only build:

```sh
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.1.2%2Bcpu.zip
unzip libtorch-cxx11-abi-shared-with-deps-2.1.2+cpu.zip -d ~/
```
Note: VCPKG is only required for extensions that want to rely on it for dependency management. If you want to develop an extension without dependencies or want to do your own dependency management, just skip this step. Note that the example extension uses VCPKG to build with a dependency for instructive purposes, so when skipping this step, the build may not work without removing the dependency.

> **Note:** LibTorch 2.7.x prebuilt CPU binaries have internal header inconsistencies and will fail to compile. Use 2.1.2.

Then set `LIBTORCH_DIR` before building:

```sh
export LIBTORCH_DIR=~/libtorch
```

Alternatively, pass it directly to `make`:
```sh
LIBTORCH_DIR=~/libtorch make
```

> **Note:** If you switch `LIBTORCH_DIR` after a previous build, clear the CMake cache first to avoid picking up stale paths:
> ```sh
> rm -rf build/release/CMakeCache.txt build/release/CMakeFiles
> ```

### Build steps
Now to build the extension, run:
Expand All @@ -35,6 +74,7 @@ The main binaries that will be built are:
## Running the extension
To run the extension code, simply start the shell with `./build/release/duckdb`.

Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function `cactusdb()` that takes a string argument and returns a string:
Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function `cactusdb()` that takes a string argument and returns a string:
```
D select cactusdb('Jane') as result;
Expand Down
26 changes: 26 additions & 0 deletions archived_tests/one_hot_encoder_rewrite_rule.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# name: test/sql/replace_binding_rule.test
# group: [sql]
require cactusdb

statement ok
LOAD cactusdb;

statement ok
PRAGMA disable_optimizer;

# If you want to assert a value, use a query block with expected output:
# (adjust the expected list to match your CSV)
query I
SELECT one_hot_encode('red', '/home/local/ASUAD/jrtandel/cactusdb-duckdb-extension/test/resources/month.csv', TRUE) AS y;
----
[1.0, 0.0, 0.0, 0.0]

statement ok
PRAGMA enable_optimizer;

query I
SELECT one_hot_encode('red', '/home/local/ASUAD/jrtandel/cactusdb-duckdb-extension/test/resources/month.csv', TRUE) AS y;
----
[0.0, 0.0, 0.0, 1.0]


Loading
Loading