duckdbservice

package
v0.0.0-...-a19b83b Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendValue

func AppendValue(builder array.Builder, val interface{})

AppendValue appends a value to an Arrow array builder with type coercion.

func BearerTokenStreamInterceptor

func BearerTokenStreamInterceptor(expectedToken string) grpc.StreamServerInterceptor

BearerTokenStreamInterceptor returns a gRPC stream interceptor that validates the bearer token from the "authorization" metadata header. If expectedToken is empty, no authentication is enforced.

func BearerTokenUnaryInterceptor

func BearerTokenUnaryInterceptor(expectedToken string) grpc.UnaryServerInterceptor

BearerTokenUnaryInterceptor returns a gRPC unary interceptor that validates the bearer token from the "authorization" metadata header. If expectedToken is empty, no authentication is enforced.

func DuckDBTypeToArrow

func DuckDBTypeToArrow(dbType string) arrow.DataType

DuckDBTypeToArrow maps a DuckDB type name to an Arrow DataType.

func GetQuerySchema

func GetQuerySchema(ctx context.Context, db contextQueryer, query string, tx contextQueryer) (*arrow.Schema, error)

GetQuerySchema executes a query with LIMIT 0 to discover the result schema.

func ParseListenAddr

func ParseListenAddr(addr string) (network, listenAddr string, err error)

ParseListenAddr parses ListenAddr into a network and address for net.Listen. Supports "unix:///path/to/sock" and TCP addresses like ":8816" or "host:port".

func QualifyTableName

func QualifyTableName(catalog, schema sql.NullString, table string) string

QualifyTableName builds a qualified table name from nullable catalog/schema and table name.

func QuoteIdent

func QuoteIdent(ident string) string

QuoteIdent quotes a SQL identifier to prevent injection.

func RowsToRecord

func RowsToRecord(alloc memory.Allocator, rows *sql.Rows, schema *arrow.Schema, batchSize int) (arrow.RecordBatch, error)

RowsToRecord converts sql.Rows into an Arrow RecordBatch of up to batchSize rows. Returns nil when there are no more rows.

func Run

func Run(cfg ServiceConfig)

Run starts the DuckDB service, blocking until shutdown.

Types

type DuckDBService

type DuckDBService struct {
	// contains filtered or unexported fields
}

DuckDBService is a standalone Arrow Flight SQL service backed by DuckDB.

func NewDuckDBService

func NewDuckDBService(cfg ServiceConfig) *DuckDBService

NewDuckDBService creates a new DuckDB service with the given config.

func (*DuckDBService) Serve

func (svc *DuckDBService) Serve(listener net.Listener) error

Serve starts serving on the given listener.

func (*DuckDBService) Shutdown

func (svc *DuckDBService) Shutdown()

Shutdown gracefully stops the service.

type FlightSQLHandler

type FlightSQLHandler struct {
	flightsql.BaseServer
	// contains filtered or unexported fields
}

FlightSQLHandler implements Arrow Flight SQL for multiple sessions. Sessions are identified by the "x-duckgres-session" gRPC metadata header.

func NewFlightSQLHandler

func NewFlightSQLHandler(pool *SessionPool) *FlightSQLHandler

NewFlightSQLHandler creates a new multi-session Flight SQL handler.

func (*FlightSQLHandler) BeginTransaction

func (*FlightSQLHandler) ClosePreparedStatement

func (*FlightSQLHandler) DoGetDBSchemas

func (h *FlightSQLHandler) DoGetDBSchemas(ctx context.Context, cmd flightsql.GetDBSchemas) (*arrow.Schema,
	<-chan flight.StreamChunk, error)

func (*FlightSQLHandler) DoGetPreparedStatement

func (h *FlightSQLHandler) DoGetPreparedStatement(ctx context.Context,
	cmd flightsql.PreparedStatementQuery) (*arrow.Schema, <-chan flight.StreamChunk, error)

func (*FlightSQLHandler) DoGetStatement

func (*FlightSQLHandler) DoGetTables

func (h *FlightSQLHandler) DoGetTables(ctx context.Context, cmd flightsql.GetTables) (*arrow.Schema,
	<-chan flight.StreamChunk, error)

func (*FlightSQLHandler) DoPutCommandStatementUpdate

func (h *FlightSQLHandler) DoPutCommandStatementUpdate(ctx context.Context,
	cmd flightsql.StatementUpdate) (int64, error)

func (*FlightSQLHandler) EndTransaction

func (*FlightSQLHandler) GetFlightInfoPreparedStatement

func (h *FlightSQLHandler) GetFlightInfoPreparedStatement(ctx context.Context, cmd flightsql.PreparedStatementQuery,
	desc *flight.FlightDescriptor) (*flight.FlightInfo, error)

func (*FlightSQLHandler) GetFlightInfoSchemas

func (h *FlightSQLHandler) GetFlightInfoSchemas(ctx context.Context, cmd flightsql.GetDBSchemas,
	desc *flight.FlightDescriptor) (*flight.FlightInfo, error)

func (*FlightSQLHandler) GetFlightInfoStatement

func (h *FlightSQLHandler) GetFlightInfoStatement(ctx context.Context, cmd flightsql.StatementQuery,
	desc *flight.FlightDescriptor) (*flight.FlightInfo, error)

func (*FlightSQLHandler) GetFlightInfoTables

func (h *FlightSQLHandler) GetFlightInfoTables(ctx context.Context, cmd flightsql.GetTables,
	desc *flight.FlightDescriptor) (*flight.FlightInfo, error)

type QueryHandle

type QueryHandle struct {
	Query  string
	Schema *arrow.Schema
	TxnID  string
}

QueryHandle stores a prepared or ad-hoc query for later execution.

type ServiceConfig

type ServiceConfig struct {
	// ListenAddr is the address to listen on.
	// Formats: "unix:///var/run/duckgres/duckdb.sock" or ":8816" or "0.0.0.0:8816"
	ListenAddr string

	// ListenFD is an inherited file descriptor for a pre-bound listener.
	// When > 0, the service uses this FD instead of creating a new socket.
	// This is used by the control plane to pass a pre-bound Unix socket to
	// worker processes, avoiding EROFS errors under ProtectSystem=strict.
	ListenFD int

	// ServerConfig is reused for CreateDBConnection (data_dir, extensions, DuckLake).
	ServerConfig server.Config

	// BearerToken is the authentication token for gRPC requests.
	// If empty, no authentication is required.
	BearerToken string

	// MaxSessions limits the number of concurrent sessions. 0 means unlimited.
	MaxSessions int
}

ServiceConfig configures the standalone DuckDB Arrow Flight SQL service.

type Session

type Session struct {
	ID        string
	DB        *sql.DB
	Conn      *sql.Conn // Dedicated connection for this session
	Username  string
	CreatedAt time.Time
	// contains filtered or unexported fields
}

Session represents a single DuckDB session.

type SessionPool

type SessionPool struct {
	// contains filtered or unexported fields
}

SessionPool manages multiple DuckDB sessions keyed by session token.

func (*SessionPool) ActiveSessions

func (p *SessionPool) ActiveSessions() int

ActiveSessions returns the number of active sessions.

func (*SessionPool) CloseAll

func (p *SessionPool) CloseAll()

CloseAll closes all sessions.

func (*SessionPool) CreateSession

func (p *SessionPool) CreateSession(username, memoryLimit string, threads int) (*Session, error)

CreateSession creates a new DuckDB session for the given username.

func (*SessionPool) DestroySession

func (p *SessionPool) DestroySession(token string) error

DestroySession closes and removes a session.

func (*SessionPool) GetSession

func (p *SessionPool) GetSession(token string) (*Session, bool)

GetSession returns a session by token.

func (*SessionPool) Warmup

func (p *SessionPool) Warmup() error

Warmup performs one-time initialization of the shared DuckDB instance. This loads extensions and attaches catalogs so that subsequent session creations are nearly instantaneous.

Jump to

Keyboard shortcuts

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