sqlcore

package
v0.0.0-...-cedafa4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sqlcore holds the duckgres-internal SQL/result interfaces that span the wire-protocol/server layer and the Arrow Flight client. It also hosts a couple of small helpers (IsEmptyQuery, OTELGRPCClientHandler) shared between those layers.

The package has no dependency on github.com/duckdb/duckdb-go, so any caller that wants to operate against duckgres without linking libduckdb (notably the Flight client and a future control-plane-only binary) can import this package without dragging the DuckDB driver in.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatalogFromSearchPath

func CatalogFromSearchPath(searchPath string) string

CatalogFromSearchPath returns the catalog from the first search_path entry, or "" when the first entry is an unqualified schema.

func IsEmptyQuery

func IsEmptyQuery(query string) bool

IsEmptyQuery checks if a query contains only semicolons, whitespace, and/or SQL comments. PostgreSQL returns EmptyQueryResponse for queries like ";", "-- ping", "/* */", etc.

func OTELGRPCClientHandler

func OTELGRPCClientHandler() grpc.DialOption

OTELGRPCClientHandler returns a gRPC StatsHandler that creates spans only for query-related Flight SQL RPCs (GetFlightInfo, DoGet, DoPut), filtering out noisy control-plane calls (DoAction for health checks, session management). DoPut covers ExecuteUpdate (non-result-returning queries: CTAS, INSERT, UPDATE, DELETE, DDL) — without it those queries had no Flight wall-time visibility in traces.

func ParseQualifiedIdentifier

func ParseQualifiedIdentifier(ref string) ([]string, bool)

ParseQualifiedIdentifier splits a one-or-more-part SQL identifier, preserving quoted identifier case and lowercasing unquoted identifiers.

func QuoteIdentifier

func QuoteIdentifier(s string) string

func StripLeadingComments

func StripLeadingComments(query string) string

StripLeadingComments removes leading SQL comments from a query. Handles both block comments /* ... */ and line comments -- ...

Types

type ColumnTyper

type ColumnTyper interface {
	DatabaseTypeName() string
}

ColumnTyper provides type name information for a database column. *sql.ColumnType satisfies this interface.

type CopyFromStdinExecutor

type CopyFromStdinExecutor interface {
	CopyFromStdin(ctx context.Context, copySQLTemplate string, csv io.Reader) (rowCount int64, err error)
}

CopyFromStdinExecutor is an optional capability implemented by executors that need the CSV bytes shipped to a different filesystem than the one the COPY FROM STDIN handler is running on. The remote (Flight) executor implements this to spool the bytes onto the worker pod, where the worker can then run COPY FROM <path>. Local executors do not need to implement it; the standard local-tempfile path works for them since the executor and the COPY FROM SQL run in the same process / host.

copySQLTemplate must contain a path placeholder that the receiver substitutes with the destination spool path before executing. The placeholder string is defined alongside the implementation (flightclient.CopyFromStdinPathPlaceholder).

type ExecResult

type ExecResult interface {
	RowsAffected() (int64, error)
}

ExecResult represents the result of a non-query execution.

type QueryExecutor

type QueryExecutor interface {
	QueryContext(ctx context.Context, query string, args ...any) (RowSet, error)
	ExecContext(ctx context.Context, query string, args ...any) (ExecResult, error)
	Query(query string, args ...any) (RowSet, error)
	Exec(query string, args ...any) (ExecResult, error)
	ConnContext(ctx context.Context) (RawConn, error)
	PingContext(ctx context.Context) error
	Close() error

	// LastProfilingOutput returns the JSON profiling output from the last
	// executed query, or "" if profiling is not enabled or not available
	// (e.g. Flight SQL mode where the query ran on a remote worker).
	LastProfilingOutput() string
}

QueryExecutor abstracts database query execution, allowing both local (*sql.DB) and remote (Arrow Flight SQL) backends.

type RawConn

type RawConn interface {
	Raw(func(any) error) error
	Close() error
}

RawConn provides access to the underlying driver connection. *sql.Conn satisfies this interface.

type RowSet

type RowSet interface {
	Columns() ([]string, error)
	ColumnTypes() ([]ColumnTyper, error)
	Next() bool
	Scan(dest ...any) error
	Close() error
	Err() error
}

RowSet represents a set of rows from a query result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL