Documentation
¶
Overview ¶
Package vectorsql implements the VectorSQL language surface of spec 12: a hand-written recursive-descent lexer and parser over the formal grammar (§15), the AST the parser emits (§17.2), the strict error model (§14), and a binder that resolves a parsed statement against the catalog and lowers a kNN SELECT to the planner's BoundQuery. VectorSQL is a strict SQL subset: no JOIN, no CTE, one FROM table per query, with first-class vector distance operators and a FUSION clause for hybrid search.
Index ¶
- func BindCreateTable(st *CreateTableStmt) (*catalog.Schema, error)
- func ParseVectorLiteral(s string) ([]float32, error)
- type AlterTableStmt
- type Assignment
- type BetweenExpr
- type BinaryExpr
- type BoolLit
- type BoundSelect
- type CaseExpr
- type CastExpr
- type ColumnRef
- type ColumnSpec
- type CopyStmt
- type CreateIndexStmt
- type CreateTableStmt
- type DeallocateStmt
- type DeleteStmt
- type DistanceExpr
- type DistanceOp
- type DropStmt
- type ExecuteStmt
- type ExplainStmt
- type Expr
- type ExprAlias
- type FloatLit
- type FuncCall
- type FusionClause
- type FusionStream
- type InExpr
- type InsertStmt
- type IntLit
- type IsNullExpr
- type JSONExpr
- type LikeExpr
- type NullLit
- type OnConflict
- type OrderItem
- type ParamRef
- type PragmaStmt
- type PrepareStmt
- type ProfileStmt
- type SelectStmt
- type SetStmt
- type Star
- type Stmt
- type StringLit
- type Token
- type TxnStmt
- type TypeRef
- type UnaryExpr
- type UpdateStmt
- type VecError
- type WhenClause
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindCreateTable ¶
func BindCreateTable(st *CreateTableStmt) (*catalog.Schema, error)
BindCreateTable lowers a parsed CREATE TABLE to a catalog.Schema (spec 12 §3.1). It maps each SQL column type to the catalog's vector or metadata column kind, applies the implicit primary key rule, and rejects more than one vector column per the index SPI contract.
func ParseVectorLiteral ¶
ParseVectorLiteral parses the textual vector form `[x, y, z]` into a float32 slice (spec 12 §2.6). Whitespace around brackets and commas is tolerated; an empty vector and a non-numeric element are both errors.
Types ¶
type AlterTableStmt ¶
type AlterTableStmt struct {
Table string
Action string // "add_column" | "drop_column" | "rename_table" | "rename_column"
Column *ColumnSpec
DropCol string
NewName string
OldColumn string
}
AlterTableStmt is ALTER TABLE (spec 12 §3.4).
type Assignment ¶
Assignment is one `col = expr` of an UPDATE SET or ON CONFLICT DO UPDATE.
type BetweenExpr ¶
BetweenExpr is `expr [NOT] BETWEEN lo AND hi`.
type BinaryExpr ¶
BinaryExpr is an infix operator (logical, comparison, arithmetic, concat, or array containment); Op holds the canonical operator text.
type BoundSelect ¶
type BoundSelect struct {
BoundQuery query.BoundQuery
IsKNN bool
// VectorParam names the parameter supplying the query vector, or is empty when the
// vector is a literal already placed in BoundQuery.Vector.
VectorParam ParamRef
HasParam bool
// Projections are the metadata column names the select list requests.
Projections []string
}
BoundSelect is the result of binding a SELECT (spec 12 §17.3). For a kNN query it carries the planner's BoundQuery and, when the query vector is a literal, the resolved vector. When the vector rides in a parameter, Query holds nil and the db layer ([14]) substitutes the bound value before planning.
func BindSelect ¶
func BindSelect(st *SelectStmt, coll *catalog.Collection) (*BoundSelect, error)
BindSelect resolves a SELECT against a collection and detects the kNN plan shape of spec 12 §17.3: exactly one ORDER BY item that is a distance operator on the vector column, plus a bounded LIMIT. A matching query lowers to a query.BoundQuery; the WHERE clause lowers to a storage.Predicate. A non-kNN SELECT is reported as unsupported in M6 because the planner only serves kNN and point lookups.
type CaseExpr ¶
type CaseExpr struct {
Operand Expr // nil for a searched CASE
Whens []WhenClause
Else Expr
}
CaseExpr is a searched or simple CASE expression (spec 12 §19.13).
type ColumnSpec ¶
type ColumnSpec struct {
Name string
Type *TypeRef
NotNull bool
Nullable bool
PrimaryKey bool
Unique bool
Default Expr
}
ColumnSpec is one column definition of a CREATE TABLE (spec 12 §3.1).
type CopyStmt ¶
type CopyStmt struct {
Table string
Columns []string
Source string // file path, or "" for STDIN
Stdin bool
Format string // "jsonl" | "csv" | "binary"
Options map[string]Expr
}
CopyStmt is COPY ... FROM (spec 12 §4.5).
type CreateIndexStmt ¶
type CreateIndexStmt struct {
Unique bool
IfNotExists bool
Name string
Table string
IndexType string // hnsw | ivfflat | ivfpq | diskann | flat | fts5
Column string
Opclass string
Options map[string]Expr
Where Expr
}
CreateIndexStmt is CREATE INDEX (spec 12 §3.2, §17.2).
type CreateTableStmt ¶
type CreateTableStmt struct {
IfNotExists bool
Name string
Columns []ColumnSpec
PrimaryKey []string // table-level PRIMARY KEY columns
Uniques [][]string
Checks []Expr
}
CreateTableStmt is CREATE TABLE (spec 12 §3.1).
type DeallocateStmt ¶
DeallocateStmt is DEALLOCATE (spec 12 §9.2).
type DeleteStmt ¶
DeleteStmt is DELETE (spec 12 §4.3).
type DistanceExpr ¶
type DistanceExpr struct {
Op DistanceOp
Left Expr
Right Expr
}
DistanceExpr is the kNN-defining operator: column DistanceOp query (spec 12 §17.2).
type DistanceOp ¶
type DistanceOp uint8
DistanceOp identifies a vector distance operator (spec 12 §17.2). The values match the four operators of the grammar.
const ( OpL2Distance DistanceOp = iota // <-> OpCosineDistance // <=> OpNegInnerProd // <#> OpL1Distance // <+> )
func (DistanceOp) String ¶
func (o DistanceOp) String() string
String renders the operator's source token.
type DropStmt ¶
type DropStmt struct {
Index bool // false = TABLE, true = INDEX
IfExists bool
Name string
OnTable string // for DROP INDEX ON table(col)
OnColumn string
}
DropStmt is DROP TABLE or DROP INDEX (spec 12 §3.3).
type ExecuteStmt ¶
ExecuteStmt is EXECUTE (spec 12 §9.2).
type ExplainStmt ¶
ExplainStmt is EXPLAIN / EXPLAIN ANALYZE (spec 12 §10).
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr is the marker interface for an expression node.
type ExprAlias ¶
ExprAlias is one select-list or RETURNING item: an expression with an optional AS alias (spec 12 §5.2).
type FuncCall ¶
type FuncCall struct {
Name string
Args []Expr
Star bool // count(*)
Distinct bool
Filter Expr // FILTER (WHERE expr), nil if absent
Offset int
}
FuncCall is a function application, optionally with DISTINCT args or a FILTER clause (spec 12 §8.1).
type FusionClause ¶
type FusionClause struct {
Streams []FusionStream
Options map[string]Expr
}
FusionClause is the hybrid-search FUSION clause (spec 12 §7.2).
type FusionStream ¶
type FusionStream struct {
Keyword bool // false = VECTOR stream, true = KEYWORD stream
// VECTOR stream: column DistanceOp query.
Column string
Op DistanceOp
Query Expr
// KEYWORD stream: MATCH (cols) AGAINST (query).
MatchCols []string
Against Expr
Options map[string]Expr
}
FusionStream is one input to a FUSION: a dense vector kNN stream or a keyword match stream (spec 12 §7.2, §7.4).
type InExpr ¶
type InExpr struct {
Expr Expr
List []Expr
Sub *SelectStmt
Not bool
}
InExpr is `expr [NOT] IN (list)`. Sub is a subquery alternative; List is the value list form. Exactly one is set.
type InsertStmt ¶
type InsertStmt struct {
Table string
Columns []string
Rows [][]Expr
OnConflict *OnConflict
Returning []ExprAlias
ReturnAll bool
}
InsertStmt is INSERT or UPSERT (spec 12 §4.1, §4.2).
type OnConflict ¶
type OnConflict struct {
Columns []string
DoNothing bool
Assigns []Assignment
}
OnConflict is the ON CONFLICT clause of an upsert (spec 12 §4.2).
type OrderItem ¶
type OrderItem struct {
Expr Expr
Desc bool
NullsFirst bool
NullsSet bool // whether NULLS FIRST/LAST was given explicitly
}
OrderItem is one ORDER BY term (spec 12 §5.4).
type ParamRef ¶
type ParamRef struct {
Name string // for :name; "" for positional
Pos int // for $N, 1-based; 0 for named
Offset int
}
ParamRef is a named (:name) or positional ($N) parameter (spec 12 §2.6).
type PragmaStmt ¶
type PragmaStmt struct {
Scope string // qualifier before the dot, "" if none
Name string
Value Expr // for `= value` or `(value)`; nil for a bare read
}
PragmaStmt is PRAGMA (spec 12 §12).
type PrepareStmt ¶
PrepareStmt is PREPARE (spec 12 §9.2).
type SelectStmt ¶
type SelectStmt struct {
Distinct bool
DistinctOn []Expr
Columns []ExprAlias // empty means SELECT *
Star bool
From string
FromAlias string
Where Expr
GroupBy []Expr
Having Expr
Fusion *FusionClause
OrderBy []OrderItem
Limit Expr
Offset Expr
}
SelectStmt is a SELECT (spec 12 §5.1, §17.2).
type SetStmt ¶
type SetStmt struct {
Local bool
Session bool
Name string
Default bool // SET x = DEFAULT
Value Expr
}
SetStmt is SET (spec 12 §11.4).
type Stmt ¶
type Stmt interface {
// contains filtered or unexported methods
}
Stmt is the marker interface for a top-level statement.
type StringLit ¶
StringLit is a decoded string literal; it may later coerce to a vector, sparse, or multivec value at bind time (spec 12 §2.5.3 through §2.5.6).
type Token ¶
type Token struct {
Kind tokenKind
Text string // the canonical text: lowercased keyword/ident, raw literal value
Offset int // byte offset of the token start in the source
// Param fields, set when Kind == tokParam.
ParamName string // for :name
ParamPos int // for $N, 1-based; 0 for named params
}
Token is one lexical unit with its source byte offset for error reporting.
type TxnStmt ¶
type TxnStmt struct {
Kind string // "begin" | "commit" | "rollback" | "savepoint" | "release" | "rollback_to"
Isolation string // for begin
Name string // savepoint/release/rollback-to name
}
TxnStmt is a transaction-control statement (spec 12 §11.1).
type TypeRef ¶
TypeRef is a column type with its optional dimension or length argument (spec 12 §3.1.1). Name is the canonical lowercased type keyword; Arg is the parenthesized integer for VECTOR/SPARSEVEC/MULTIVEC/VARCHAR.
type UpdateStmt ¶
type UpdateStmt struct {
Table string
Assigns []Assignment
Where Expr
Returning []ExprAlias
ReturnAll bool
}
UpdateStmt is UPDATE (spec 12 §4.4).
type VecError ¶
type VecError struct {
Code string // symbolic code, e.g. "E_PARSE"
Numeric int // numeric code, e.g. 1000
Message string // human-readable description
Detail string // optional context (column name, expected dimension, spec reference)
Offset int // byte offset within the statement text; -1 when not positional
}
VecError is every error the VectorSQL frontend raises (spec 12 §14.4). It carries a stable symbolic code, a numeric code for programmatic dispatch, a human message, an optional detail string, and, for parse errors, the byte offset in the source.
type WhenClause ¶
WhenClause is one WHEN/THEN arm of a CASE.