Documentation
¶
Overview ¶
Package server provides a DuckDB-backed Arrow Flight SQL server built on top of the upstream flightsql routing layer (fsql.NewFlightServer).
Design invariants
The flightsql framework (fsql.NewFlightServer) owns all protocol routing. This file implements only the subset of the flightsql.Server interface that this server actively supports; every other method falls back to the "unimplemented" stubs in fsql.BaseServer.
Handle tiers are flat. - queryHandles one-shot, created by GetFlightInfoStatement, consumed by DoGetStatement. - preparedStmts persistent, created by CreatePreparedStatement, deleted by ClosePreparedStatement. GetFlightInfoPreparedStatement encodes the prepared handle directly into a CommandPreparedStatementQuery ticket so the framework routes DoGet to DoGetPreparedStatement — no intermediate exec handle.
All handle maps are TTL-bounded. A background goroutine evicts stale entries to prevent unbounded growth under long-lived servers.
Parameter binding is real. DoPutPreparedStatementQuery stores a retained RecordBatch; DoGetPreparedStatement uses stmt.Prepare + stmt.Bind before executing. Reference counts are tracked explicitly.
Index ¶
- type Server
- func (s *Server) AsFlightServer() flight.FlightServer
- func (s *Server) Close() error
- func (s *Server) ClosePreparedStatement(_ context.Context, req fsql.ActionClosePreparedStatementRequest) error
- func (s *Server) CreatePreparedStatement(ctx context.Context, req fsql.ActionCreatePreparedStatementRequest) (fsql.ActionCreatePreparedStatementResult, error)
- func (s *Server) DoExchange(ctx context.Context, stream flight.FlightService_DoExchangeServer) (err error)
- func (s *Server) DoGetPreparedStatement(ctx context.Context, cmd fsql.PreparedStatementQuery) (*arrow.Schema, <-chan flight.StreamChunk, error)
- func (s *Server) DoGetStatement(ctx context.Context, ticket fsql.StatementQueryTicket) (*arrow.Schema, <-chan flight.StreamChunk, error)
- func (s *Server) DoPutCommandStatementUpdate(ctx context.Context, cmd fsql.StatementUpdate) (int64, error)
- func (s *Server) DoPutPreparedStatementQuery(_ context.Context, cmd fsql.PreparedStatementQuery, ...) ([]byte, error)
- func (s *Server) GetFlightInfoPreparedStatement(ctx context.Context, cmd fsql.PreparedStatementQuery, ...) (*flight.FlightInfo, error)
- func (s *Server) GetFlightInfoStatement(ctx context.Context, cmd fsql.StatementQuery, desc *flight.FlightDescriptor) (*flight.FlightInfo, error)
- func (s *Server) GetSchemaPreparedStatement(ctx context.Context, cmd fsql.PreparedStatementQuery, ...) (*flight.SchemaResult, error)
- func (s *Server) GetSchemaStatement(ctx context.Context, cmd fsql.StatementQuery, _ *flight.FlightDescriptor) (*flight.SchemaResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
fsql.BaseServer
// contains filtered or unexported fields
}
Server is a DuckDB-backed FlightSQL server. It embeds fsql.BaseServer to satisfy the full flightsql.Server interface via "unimplemented" stubs, then overrides only the methods this server actually provides.
func NewServer ¶
NewServer opens a DuckDB database at dbPath ("" or ":memory:" for in-memory) and starts a background goroutine that evicts expired handles.
func (*Server) AsFlightServer ¶
func (s *Server) AsFlightServer() flight.FlightServer
AsFlightServer wraps this server with the fsql routing layer for gRPC registration:
flight.RegisterFlightServiceServer(grpcSrv, srv.AsFlightServer())
func (*Server) Close ¶
Close stops the GC goroutine, releases all retained parameter batches, and shuts down the database connection.
func (*Server) ClosePreparedStatement ¶
func (s *Server) ClosePreparedStatement( _ context.Context, req fsql.ActionClosePreparedStatementRequest, ) error
ClosePreparedStatement removes the prepared entry and releases its parameter batch (if any). Idempotent: closing an already-closed handle is a no-op.
func (*Server) CreatePreparedStatement ¶
func (s *Server) CreatePreparedStatement( ctx context.Context, req fsql.ActionCreatePreparedStatementRequest, ) (fsql.ActionCreatePreparedStatementResult, error)
CreatePreparedStatement stores the SQL under a random TTL-bounded handle, derives the dataset schema, and returns both to the client so it can introspect columns before binding parameters.
func (*Server) DoExchange ¶
func (*Server) DoGetPreparedStatement ¶
func (s *Server) DoGetPreparedStatement( ctx context.Context, cmd fsql.PreparedStatementQuery, ) (*arrow.Schema, <-chan flight.StreamChunk, error)
DoGetPreparedStatement streams query results for a prepared statement, applying any parameter batch set by a prior DoPutPreparedStatementQuery.
Reference counting: we Retain the stored batch before dropping the lock. Ownership of that extra reference is transferred to startStreamWithParams, which releases it exactly once through its cleanup closure.
func (*Server) DoGetStatement ¶
func (s *Server) DoGetStatement( ctx context.Context, ticket fsql.StatementQueryTicket, ) (*arrow.Schema, <-chan flight.StreamChunk, error)
DoGetStatement streams the result set for a one-shot statement handle. The handle is deleted on first claim; subsequent calls with the same handle return NotFound.
func (*Server) DoPutCommandStatementUpdate ¶
func (s *Server) DoPutCommandStatementUpdate( ctx context.Context, cmd fsql.StatementUpdate, ) (int64, error)
DoPutCommandStatementUpdate executes a DML or DDL statement (INSERT, UPDATE, DELETE, CREATE TABLE, …) and returns the number of affected rows.
func (*Server) DoPutPreparedStatementQuery ¶
func (s *Server) DoPutPreparedStatementQuery( _ context.Context, cmd fsql.PreparedStatementQuery, reader flight.MessageReader, _ flight.MetadataWriter, ) ([]byte, error)
DoPutPreparedStatementQuery receives parameter bindings from the client and atomically replaces the stored batch on the prepared entry. The old batch is released after the lock is dropped. The new batch is Retained before storage so its lifetime is tied to the entry, not the MessageReader.
func (*Server) GetFlightInfoPreparedStatement ¶
func (s *Server) GetFlightInfoPreparedStatement( ctx context.Context, cmd fsql.PreparedStatementQuery, desc *flight.FlightDescriptor, ) (*flight.FlightInfo, error)
GetFlightInfoPreparedStatement returns a FlightInfo for an existing prepared statement. The ticket is encoded as a CommandPreparedStatementQuery so the framework routes the subsequent DoGet directly to DoGetPreparedStatement — no intermediate exec handle is created.
func (*Server) GetFlightInfoStatement ¶
func (s *Server) GetFlightInfoStatement( ctx context.Context, cmd fsql.StatementQuery, desc *flight.FlightDescriptor, ) (*flight.FlightInfo, error)
GetFlightInfoStatement handles GetFlightInfo for a plain SQL query. It derives the schema eagerly, stores the SQL in a TTL-bounded one-shot handle, and returns a TicketStatementQuery that the framework routes to DoGetStatement.
func (*Server) GetSchemaPreparedStatement ¶
func (s *Server) GetSchemaPreparedStatement( ctx context.Context, cmd fsql.PreparedStatementQuery, _ *flight.FlightDescriptor, ) (*flight.SchemaResult, error)
GetSchemaPreparedStatement returns the dataset schema for a prepared statement.
func (*Server) GetSchemaStatement ¶
func (s *Server) GetSchemaStatement( ctx context.Context, cmd fsql.StatementQuery, _ *flight.FlightDescriptor, ) (*flight.SchemaResult, error)
GetSchemaStatement returns the Arrow schema for a SQL query without executing it. This is the cheapest schema-only introspection path.