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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Add vectorized execution operators, expressions evaluator, three-valued logic, hash aggregation and join
- Add SQL lexer and recursive descent parser for SELECT queries, expressions, JOINs, and aggregations.
- feat(storage): implement CSV scanning, batch slicing into typed column vectors, table catalog, and MaxScanBytes limits
- Initial project structure from the factory utility template.
17 changes: 17 additions & 0 deletions docs/PROJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ Total: $0.5031. Prices: Anthropic list prices.
| audit | gemini-3.1-flash-lite | no | 35828 | 147 | 0 | 18268 | 0.0096 |

Total: $0.1137. Prices: Anthropic list prices.

## Factory run columnar-sql-engine-vector-exec (measured from API usage)

| Phase | Model | Batch | Input | Output | Cache write | Cache read | Cost (USD) |
|---|---|---|---|---|---|---|---|
| generation | gemini-3.8-flash | yes | 8348 | 32599 | 0 | 0 | 0.0643 |
| fix-1 | gemini-3.8-flash | no | 104575 | 920 | 0 | 1094166 | 0.1639 |
| fix-2 | gemini-3.8-flash | no | 133658 | 923 | 0 | 1089837 | 0.1854 |
| fix-3 | gemini-3.8-flash | no | 128032 | 122 | 0 | 3020 | 0.0967 |
| fix-1 | gemini-3.8-flash | no | 104196 | 1382 | 0 | 1122574 | 0.1675 |
| fix-2 | gemini-3.8-flash | no | 34467 | 98 | 0 | 30249 | 0.0285 |
| fix-3 | gemini-3.8-flash | no | 101659 | 1246 | 0 | 1081490 | 0.1620 |
| fix-4 | gemini-3.8-flash | no | 108112 | 10915 | 0 | 1191661 | 0.2114 |
| fix-5 | gemini-3.8-flash | no | 61448 | 475 | 0 | 373007 | 0.0758 |
| audit | gemini-3.1-flash-lite | no | 56402 | 144 | 0 | 75549 | 0.0162 |

Total: $1.1718. Prices: Anthropic list prices.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Vectorized Execution Operators and Three-Valued Logic Engine

Status: accepted (generated, pending human review)

## Context

The columnar SQL engine requires high-performance vectorized physical operators, SQL standard three-valued boolean logic, hash-based grouping and equijoins, and deterministic sorting with NULLS FIRST / NULLS LAST support.

## Decision

Implement VectorEvaluator and core physical operators (Scan, Values, Projection, Filter, HashAggregate, HashJoin, Sort, Limit) operating directly on typed ColumnVector and RecordBatch slices, preserving null bitmasks and ANSI SQL three-valued logic rules.

## Consequences

Executes SQL query plans in vectorized batches without per-row object allocations, correctly handles equijoins and grouping with nulls, and fulfills all acceptance criteria.
53 changes: 53 additions & 0 deletions internal/exec/engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package exec

import (
"context"
"fmt"

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

// ExecutionEngine implements interfaces.ExecutionEngine.
type ExecutionEngine struct {
evaluator interfaces.VectorEvaluator
batchSize int
maxMemory int64
}

// NewExecutionEngine creates a new execution engine.
func NewExecutionEngine(batchSize int, maxMemory int64) *ExecutionEngine {
if batchSize <= 0 {
batchSize = 1024
}
if maxMemory <= 0 {
maxMemory = 256 * 1024 * 1024
}
return &ExecutionEngine{
evaluator: NewEvaluator(),
batchSize: batchSize,
maxMemory: maxMemory,
}
}

// Evaluator returns the VectorEvaluator used by this engine.
func (e *ExecutionEngine) Evaluator() interfaces.VectorEvaluator {
return e.evaluator
}

// Execute creates an operator pipeline from a physical plan node.
func (e *ExecutionEngine) Execute(ctx context.Context, plan interfaces.PhysicalPlanNode) (interfaces.Operator, error) {
if plan == nil {
return nil, &interfaces.EngineError{
Code: interfaces.ErrSyntaxError,
Message: "nil physical plan",
}
}
// If plan is already an Operator, return it.
if op, ok := plan.(interfaces.Operator); ok {
return op, nil
}
return nil, &interfaces.EngineError{
Code: interfaces.ErrSyntaxError,
Message: fmt.Sprintf("cannot execute physical plan node %T", plan),
}
}
Loading
Loading