This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
OneSparse is a PostgreSQL extension that provides sparse linear algebra and graph algorithm capabilities by binding the SuiteSparse:GraphBLAS library. It exposes GraphBLAS functionality as PostgreSQL types, functions, and operators.
make clean
make install# Format code using pgindent (PostgreSQL code style)
pgindent <files># Full test suite in Docker (preferred method)
./test.sh
# Direct PostgreSQL regression tests (requires PostgreSQL running)
make installcheckThe test.sh script:
- Removes any previous test container
- Builds the
onesparse/testDocker image fromDockerfile-debug - Starts a PostgreSQL container with OneSparse installed
- Runs
make installcheckinside the container - Cleans up the container
Individual test files are located in sql/ with expected outputs in expected/.
# Run a specific test file
make installcheck REGRESS=test_name
# Example: run only the matrix I/O header tests
make installcheck REGRESS=test_io_header# Generate documentation (uses doctestify.py to convert SQL tests to markdown)
python generate.py
# Build and serve documentation site
mkdocs build
mkdocs serveOneSparse implements PostgreSQL "expanded object" types for GraphBLAS objects:
- Matrix (
os_Matrix): Sparse 2D arrays backed byGrB_Matrix - Vector (
os_Vector): Sparse 1D arrays backed byGrB_Vector - Scalar (
os_Scalar): Single values backed byGrB_Scalar - Type (
os_Type): Type descriptors wrappingGrB_Type - Descriptor (
os_Descriptor): Operation modifiers wrappingGrB_Descriptor - Graph (
os_Graph): Graph structures with optional adjacency matrix
Each type has:
- Flat representation: Serialized form for storage (TOAST-able)
- Expanded representation: In-memory form holding GraphBLAS objects
- Conversion functions between representations
src/onesparse.h: Main header with macros, common definitions, GraphBLAS includessrc/onesparse.c: Extension initialization, type promotion, lookup tablessrc/guc.c: PostgreSQL configuration parameters (GUCs)src/*/: Per-type subdirectories (matrix, vector, scalar, etc.)*_in.c,*_out.c: Text I/O functions*.h: Type-specific headers and function declarations*_*.c: Type-specific operations
src/graph/: LAGraph algorithm wrappers (BFS, PageRank, betweenness, etc.)src/jit/: JIT type system for dynamic code generation
OneSparse uses template-based code generation via generate.py:
- Templates in
templates/define SQL and C code patterns generate.pyreads GraphBLAS metadata using pyclibrary- Generates SQL files in
sql/andonesparse/directories doctestify.pyconverts SQL tests to markdown documentation
To regenerate code after template changes:
python generate.pyError Handling:
OS_CHECK(method, obj, msg): Check GraphBLAS calls, report errorsLA_CHECK(method): Check LAGraph callsERRORIF(condition, msg): Conditional error reportingERRORNULL(arg): Check for NULL arguments
Object Property Extraction:
OS_MTYPE(type, matrix): Get matrix typeOS_MNROWS(nrows, matrix): Get row countOS_MNCOLS(ncols, matrix): Get column countOS_MNVALS(nvals, matrix): Get number of values- Similar macros exist for vectors (
OS_V*) and scalars (OS_S*)
Debugging:
OS_DEBUGenables debug outputOS_START_BENCH()/OS_END_BENCH(): Performance timingLOGF(): Function entry logging
Debugging Commands:
# Enable debug output (set before building)
export OS_DEBUG=1
# Run tests in debug Docker container with interactive access
docker run -it --entrypoint /bin/bash onesparse/test
# Attach to running test container for debugging
docker exec -it onesparse-test-db bash_PG_init() in src/onesparse.c initializes:
- GraphBLAS library (
GrB_init()) - Type lookup tables
- Descriptor, operator, monoid, semiring tables
- GUC parameters
- Custom burble handler for GraphBLAS diagnostics
OneSparse uses PostgreSQL's expanded object framework:
- Flat objects are stored in TOAST when large
- Expanded objects live in PostgreSQL memory contexts
DatumGetMatrix(),DatumGetVector(), etc. handle expansion- Support functions enable in-place modification for performance
- Links against libgraphblas, liblagraph, liblagraphx
- Header:
/usr/local/include/suitesparse/GraphBLAS.h - Libraries:
-lgraphblas -llagraph -llagraphx -lpq - Compiler flags:
-std=c11 -Wfatal-errors
- Modify templates in
templates/for generated code changes - Run
generate.pyto regenerate SQL and C files - Rebuild extension:
make clean && make install - Run tests:
./test.shormake installcheck - Update documentation:
python generate.pyregenerates markdown from SQL tests - Build docs site:
mkdocs buildto verify documentation
Multiple Dockerfiles for different purposes:
Dockerfile: Basic buildDockerfile-debug: Development with debugging toolsDockerfile-demo: Demo container with sample dataDockerfile-slim: Minimal production imageDockerfile-tests: Test harnessDockerfile-pgrouting: Integration with pgRouting
onesparse.control: Extension metadataonesparse/*.sql: Schema migration files (version-specific)- Generated by
generate.pyfrom templates
The repository uses GitHub Actions to automate releases when version tags are pushed.
Workflow: .github/workflows/release.yml
Trigger: Push tags matching v*.*.* (e.g., v1.2.3, v2.0.0-beta.1)
Process:
- Test Job: Runs
./test.shto verify all tests pass - Docker Job: Builds and pushes
onesparse/onesparse-slimimage to Docker Hub - Release Job: Creates GitHub release with auto-generated release notes
Creating a Release:
# Ensure main branch is up to date
git checkout main
git pull
# Create version tag
git tag v1.2.3
# Push tag to trigger workflow
git push origin v1.2.3Monitor: Check GitHub Actions tab for workflow progress
Verify: Check Releases page for new release and Docker Hub for published image
Requirements: Repository must have DOCKERHUB_USERNAME and DOCKERHUB_TOKEN secrets configured
See docs/plans/2025-11-13-github-release-workflow-design.md for detailed design and usage.