examples/hello_cpp/README.md
A minimal Daft native extension written in pure C++ using the Apache Arrow C++ library.
This is the C++ counterpart of the hello Rust example. It implements a single greet_cpp scalar function that prepends "Hello, " to every string in a column.
macOS (Homebrew):
brew install apache-arrow
Ubuntu / Debian:
sudo apt install -y libarrow-dev
Conda:
conda install -c conda-forge arrow-cpp
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build
The CMAKE_EXPORT_COMPILE_COMMANDS flag generates build/compile_commands.json for clangd / LSP support. Symlink it to the project root if your editor needs it:
ln -sf build/compile_commands.json .
uv pip install -e .
This uses scikit-build-core to build the C++ library and install it into the Python package.
pytest -v tests/
import daft
import hello_cpp
from hello_cpp import greet
from daft import col
from daft.session import Session
sess = Session()
sess.load_extension(hello_cpp)
df = daft.from_pydict({"name": ["John", "Paul", "George", None]})
with sess:
df.select(greet(col("name"))).show()
# ╭──────────────────╮
# │ greet_cpp │
# │ --- │
# │ Utf8 │
# ╞══════════════════╡
# │ Hello, John! │
# ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │ Hello, Paul! │
# ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │ Hello, George! │
# ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │ None │
# ╰──────────────────╯