Skip to content

About

Embeddable columnar SQL query engine in Go with vectorized batch execution, a rule-based optimizer, CSV tables and three-valued NULL logic

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

Repository files navigation

columnar-sql-engine

License: MIT CI

Embeddable columnar SQL query engine in Go with vectorized batch execution, a rule-based optimizer, CSV tables and three-valued NULL logic.

Problem

Go services that need ad-hoc SQL over CSV exports or in-memory tables (filters, joins, GROUP BY reports) usually load the data into SQLite through cgo or start an external database. This library is a pure-Go, embeddable engine: register a CSV with a typed schema and run SELECT queries that execute over column batches, with standard three-valued NULL logic and memory and scan-size limits. It is meant for embedded analytics on moderate data sizes, not as a replacement for a database server.

Install

go get github.com/Trysac/u409-columnar-sql-engine

Requires Go 1.23 or newer. No dependencies outside the standard library.

Usage

package main

import (
	"context"
	"fmt"
	"log"
	"strings"

	columnarsqlengine "github.com/Trysac/u409-columnar-sql-engine"
)

func main() {
	eng := columnarsqlengine.New()
	defer eng.Close()

	csv := "region,amount,discount\nnorth,120,10\nsouth,80,\nnorth,45,2\nsouth,200,15\n"
	schema := []columnarsqlengine.DataType{
		columnarsqlengine.TypeVarChar,
		columnarsqlengine.TypeInt64,
		columnarsqlengine.TypeInt64,
	}
	if err := eng.RegisterCSV("sales", strings.NewReader(csv), schema); err != nil {
		log.Fatal(err)
	}

	rows, err := eng.Query(context.Background(),
		"SELECT region, SUM(amount) AS total FROM sales WHERE discount > 5 GROUP BY region ORDER BY region")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	// Prints "north 120" and "south 200": the empty discount is NULL, so the row with
	// amount 80 is UNKNOWN under "discount > 5" and filtered out.
	for rows.Next() {
		var region string
		var total int64
		if err := rows.Scan(&region, &total); err != nil {
			log.Fatal(err)
		}
		fmt.Println(region, total)
	}

	nulls, err := eng.Query(context.Background(), "SELECT region FROM sales WHERE discount IS NULL")
	if err != nil {
		log.Fatal(err)
	}
	defer nulls.Close()
	for nulls.Next() {
		var region string
		if err := nulls.Scan(&region); err != nil {
			log.Fatal(err)
		}
		fmt.Println("no discount:", region) // no discount: south
	}
}

This program is the package's runnable Example, so go test checks that its output stays as documented. Engine.Explain(ctx, sql, true) returns the optimized physical plan with the rows, batches and time each operator observed.

Documentation

License

MIT (c) 2026 Miguel Gomez

About

Embeddable columnar SQL query engine in Go with vectorized batch execution, a rule-based optimizer, CSV tables and three-valued NULL logic

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages