driverbase

package module
v0.0.0-...-9982c03 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 36 Imported by: 1

README

Go Driver Framework

This is derived from upstream Arrow ADBC which is under the Apache license.

Documentation

Overview

Package driverbase provides a framework for implementing ADBC drivers in Go. It intends to reduce boilerplate for common functionality and managing state transitions.

Index

Constants

View Source
const (
	ConnectionMessageOptionUnknown              = "Unknown connection option"
	ConnectionMessageOptionUnsupported          = "Unsupported connection option"
	ConnectionMessageCannotCommit               = "Cannot commit when autocommit is enabled"
	ConnectionMessageCannotRollback             = "Cannot rollback when autocommit is enabled"
	ConnectionMessageTraceParentIncorrectFormat = "Incorrect or unsupported trace parent format"
)
View Source
const (
	TraceExporterNone traceExporterType = iota
	TraceExporterOtlp
	TraceExporterConsole
	TraceExporterAdbcFile
)
View Source
const (
	DatabaseMessageOptionUnknown                   = "Unknown database option"
	DatabaseMessageOtelTracesExporterOptionUnknown = "Unknown " + otelTracesExporter + " option"
	DatabaseMessageNoOtelTracesExporters           = "No trace exporters added"
)
View Source
const (
	UnknownVersion               = "(unknown or development build)"
	DefaultInfoDriverADBCVersion = adbc.AdbcVersion1_1_0
)
View Source
const (
	Check      = "CHECK"
	ForeignKey = "FOREIGN KEY"
	PrimaryKey = "PRIMARY KEY"
	Unique     = "UNIQUE"
)

Constants for names of constraint types

View Source
const (
	COLUMN_NAME                 = "COLUMN_NAME"
	ORDINAL_POSITION            = "ORDINAL_POSITION"
	REMARKS                     = "REMARKS"
	XDBC_DATA_TYPE              = "XDBC_DATA_TYPE"
	XDBC_TYPE_NAME              = "XDBC_TYPE_NAME"
	XDBC_COLUMN_SIZE            = "XDBC_COLUMN_SIZE"
	XDBC_DECIMAL_DIGITS         = "XDBC_DECIMAL_DIGITS"
	XDBC_NUM_PREC_RADIX         = "XDBC_NUM_PREC_RADIX"
	XDBC_NULLABLE               = "XDBC_NULLABLE"
	XDBC_COLUMN_DEF             = "XDBC_COLUMN_DEF"
	XDBC_SQL_DATA_TYPE          = "XDBC_SQL_DATA_TYPE"
	XDBC_DATETIME_SUB           = "XDBC_DATETIME_SUB"
	XDBC_CHAR_OCTET_LENGTH      = "XDBC_CHAR_OCTET_LENGTH"
	XDBC_IS_NULLABLE            = "XDBC_IS_NULLABLE"
	XDBC_SCOPE_CATALOG          = "XDBC_SCOPE_CATALOG"
	XDBC_SCOPE_SCHEMA           = "XDBC_SCOPE_SCHEMA"
	XDBC_SCOPE_TABLE            = "XDBC_SCOPE_TABLE"
	XDBC_IS_AUTOINCREMENT       = "XDBC_IS_AUTOINCREMENT"
	XDBC_IS_AUTOGENERATEDCOLUMN = "XDBC_IS_AUTOGENERATEDCOLUMN"
)
View Source
const (
	StatementMessageOptionUnknown              = "Unknown statement option"
	StatementMessageOptionUnsupported          = "Unsupported statement option"
	StatementMessageTraceParentIncorrectFormat = "Incorrect or unsupported trace parent format"
)
View Source
const (
	XdbcDataTypeArray                 int16 = 2003
	XdbcDataTypeBigint                int16 = -5
	XdbcDataTypeBinary                int16 = -2
	XdbcDataTypeBit                   int16 = -7
	XdbcDataTypeBlob                  int16 = 2004
	XdbcDataTypeBoolean               int16 = 16
	XdbcDataTypeChar                  int16 = 1
	XdbcDataTypeClob                  int16 = 2005
	XdbcDataTypeDatalink              int16 = 70
	XdbcDataTypeDate                  int16 = 91
	XdbcDataTypeDecimal               int16 = 3
	XdbcDataTypeDistinct              int16 = 2001
	XdbcDataTypeDouble                int16 = 8
	XdbcDataTypeFloat                 int16 = 6
	XdbcDataTypeInteger               int16 = 4
	XdbcDataTypeJavaObject            int16 = 2000
	XdbcDataTypeLongNVarChar          int16 = -16
	XdbcDataTypeLongVarBinary         int16 = -4
	XdbcDataTypeLongVarChar           int16 = -1
	XdbcDataTypeNChar                 int16 = -15
	XdbcDataTypeNClob                 int16 = 2011
	XdbcDataTypeNull                  int16 = 0
	XdbcDataTypeNumeric               int16 = 2
	XdbcDataTypeNVarChar              int16 = -9
	XdbcDataTypeOther                 int16 = 1111
	XdbcDataTypeReal                  int16 = 7
	XdbcDataTypeRef                   int16 = 2006
	XdbcDataTypeRefCursor             int16 = 2012
	XdbcDataTypeRowId                 int16 = -8
	XdbcDataTypeSmallint              int16 = 5
	XdbcDataTypeSqlXml                int16 = 2009
	XdbcDataTypeStruct                int16 = 2002
	XdbcDataTypeTime                  int16 = 92
	XdbcDataTypeTimeWithTimezone      int16 = 2013
	XdbcDataTypeTimestamp             int16 = 93
	XdbcDataTypeTimestampWithTimezone int16 = 2014
	XdbcDataTypeTinyint               int16 = -6
	XdbcDataTypeVarBinary             int16 = -3
	XdbcDataTypeVarChar               int16 = 12
)
View Source
const (
	XdbcColumnNoNulls         int16 = 0
	XdbcColumnNullable        int16 = 1
	XdbcColumnNullableUnknown int16 = 2
)

Variables

View Source
var (
	AcceptAll = regexp.MustCompile(".*")
)
View Source
var ErrOverflow = errors.New("driverbase: value overflow")

Functions

func BuildGetObjectsRecordReader

func BuildGetObjectsRecordReader(mem memory.Allocator, in <-chan GetObjectsInfo, errCh <-chan error) (array.RecordReader, error)

BuildGetObjectsRecordReader constructs a RecordReader for the GetObjects ADBC method. It accepts a channel of GetObjectsInfo to allow concurrent retrieval of metadata and serialization to Arrow record.

func DebugAssert

func DebugAssert(cond bool, msg any)

func EndSpan

func EndSpan(span trace.Span, err error, options ...trace.SpanEndOption)

Ends the given span. If err is not nil, then the error is recorded and the status is set appropriately. Otherwise, the status is set to Ok.

func NewRotatingFileWriter

func NewRotatingFileWriter(options ...rotatingFileWriterOption) (*rotatingFileWriterImpl, error)

Creates a new RotatingFileWriter from the given options

func NullInt16ToPtr

func NullInt16ToPtr(i sql.NullInt16) *int16

NullInt16ToPtr converts a sql.NullInt16 to a *int16.

func NullInt32ToPtr

func NullInt32ToPtr(i sql.NullInt32) *int32

NullInt32ToPtr converts a sql.NullInt32 to a *int32.

func NullStringToPtr

func NullStringToPtr(s sql.NullString) *string

NullStringToPtr converts a sql.NullString to a *string.

func Nullable

func Nullable[T any](val T) *T

Nullable wraps a value and returns a pointer to the value, which is how nullable values are represented for purposes of JSON serialization.

func PatternToNamedArg

func PatternToNamedArg(name string, pattern *string) sql.NamedArg

func PatternToRegexp

func PatternToRegexp(pattern *string) (*regexp.Regexp, error)

Helper function that compiles a SQL-style pattern (%, _) to a regex

func RequiredList

func RequiredList[T any](vals []T) requiredList[T]

RequiredList is a wrapper for a slice of values that is not considered "nullable" for serialization purposes. When marshaling JSON, the empty value is serialized as "[]" instead of "null".

func SetOTelDriverInfoAttributes

func SetOTelDriverInfoAttributes(driverInfo *DriverInfo, span trace.Span)

func StartSpan

func StartSpan(ctx context.Context, spanName string, tracing adbc.OTelTracing, opts ...trace.SpanStartOption) (context.Context, trace.Span)

Starts a trace.Span with the given spanName for the tracing object with the given ctx context.

func ToPtr

func ToPtr[T any](i T) *T

func ValueOrZero

func ValueOrZero[T any](val *T) T

ValueOrZero safely dereferences a pointer, returning the zero-value of the underlying type in the case of a nil pointer.

func WithFileCountMax

func WithFileCountMax(fileCountMax int) rotatingFileWriterOption

Adds the FileCountMax option

func WithFileSizeMaxKb

func WithFileSizeMaxKb(fileSizeMaxKb int64) rotatingFileWriterOption

Adds the FileSizeMaxKb option

func WithLogNamePrefix

func WithLogNamePrefix(logNamePrefix string) rotatingFileWriterOption

Adds the LogNamePrefix option

func WithShared

func WithShared[T, R any](sh *Shared[T], closure func(*T) (R, error)) (R, error)

func WithTracingFolderPath

func WithTracingFolderPath(tracingFolderPath string) rotatingFileWriterOption

Adds the TracingFolderPath option

Types

type AutocommitSetter

type AutocommitSetter interface {
	SetAutocommit(enabled bool) error
}

AutocommitSetter is an interface that drivers may implement to simplify the implementation of autocommit state management. There is no need to implement this for backends that do not support autocommit, as this is already the default behavior. SetAutocommit should only attempt to update the autocommit state in the backend. Local driver state is automatically updated if the result of this call does not produce an error. (Get/Set)Options implementations are provided automatically as well/

type BaseRecordReader

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

BaseRecordReader is an array.RecordReader based on a row-wise interface. It manages ADBC requirements like re-issuing queries multiple times for each row of a bind parameter set.

func (*BaseRecordReader) Close

func (rr *BaseRecordReader) Close()

func (*BaseRecordReader) Err

func (rr *BaseRecordReader) Err() error

func (*BaseRecordReader) Init

Init initializes the state for the record reader.

func (*BaseRecordReader) Next

func (rr *BaseRecordReader) Next() bool

func (*BaseRecordReader) Record

func (rr *BaseRecordReader) Record() arrow.RecordBatch

func (*BaseRecordReader) RecordBatch

func (rr *BaseRecordReader) RecordBatch() arrow.RecordBatch

func (*BaseRecordReader) Release

func (rr *BaseRecordReader) Release()

func (*BaseRecordReader) Retain

func (rr *BaseRecordReader) Retain()

func (*BaseRecordReader) Schema

func (rr *BaseRecordReader) Schema() *arrow.Schema

type BaseRecordReaderOptions

type BaseRecordReaderOptions struct {
	BatchByteLimit int64
	BatchRowLimit  int64
}

type BufferBulkIngestSink

type BufferBulkIngestSink struct {
	bytes.Buffer
}

func (*BufferBulkIngestSink) Close

func (*BufferBulkIngestSink) Close() error

func (*BufferBulkIngestSink) Sink

func (sink *BufferBulkIngestSink) Sink() io.Writer

type BulkIngestImpl

type BulkIngestImpl interface {
	Copy(ctx context.Context, chunk BulkIngestPendingCopy) error
	CreateSink(ctx context.Context, options *BulkIngestOptions) (BulkIngestSink, error)
	CreateTable(ctx context.Context, schema *arrow.Schema, ifTableExists BulkIngestTableExistsBehavior, ifTableMissing BulkIngestTableMissingBehavior) error
	Delete(ctx context.Context, chunk BulkIngestPendingCopy) error
	Upload(ctx context.Context, chunk BulkIngestPendingUpload) (BulkIngestPendingCopy, error)
}

type BulkIngestManager

type BulkIngestManager struct {
	Impl        BulkIngestImpl
	ErrorHelper *ErrorHelper
	Logger      *slog.Logger
	Alloc       memory.Allocator
	Ctx         context.Context
	Options     BulkIngestOptions
	Data        array.RecordReader
	// contains filtered or unexported fields
}

func (*BulkIngestManager) Close

func (bi *BulkIngestManager) Close()

func (*BulkIngestManager) ExecuteIngest

func (bi *BulkIngestManager) ExecuteIngest() (int64, error)

func (*BulkIngestManager) Init

func (bi *BulkIngestManager) Init() error

type BulkIngestOptions

type BulkIngestOptions struct {
	// The table to ingest data into.
	TableName   string
	SchemaName  string
	CatalogName string
	// If true, use a temporary table.  The catalog/schema, if specified,
	// will be ignored (as temporary tables generally get implemented via
	// a special catalog/schema).
	Temporary bool
	// The ingest mode.
	Mode string
	// How far to read ahead on the data source
	ReadDepth int
	// How many parallel writers to use
	WriterParallelism int
	// How many parallel uploaders to use
	UploaderParallelism int
	// How many buffers to queue at once
	MaxPendingBuffers int
	WriterProps       WriterProps
}

func NewBulkIngestOptions

func NewBulkIngestOptions() BulkIngestOptions

func (*BulkIngestOptions) Clear

func (options *BulkIngestOptions) Clear()

Clear resets the destination options.

func (*BulkIngestOptions) IsSet

func (options *BulkIngestOptions) IsSet() bool

IsSet returns true if the user has set a table name to ingest into.

func (*BulkIngestOptions) SetOption

func (options *BulkIngestOptions) SetOption(eh *ErrorHelper, key, val string) (bool, error)

type BulkIngestPendingCopy

type BulkIngestPendingCopy interface {
	fmt.Stringer
	Rows() int64
}

BulkIngestPendingCopy is a file that was uploaded to the staging area and is ready to be copied into the target table.

type BulkIngestPendingUpload

type BulkIngestPendingUpload struct {
	Data BulkIngestSink
	Rows int64
}

BulkIngestPendingUpload is a set of rows serialized to Parquet, ready to be uploaded or written to the staging area.

type BulkIngestSink

type BulkIngestSink interface {
	io.Closer
	Sink() io.Writer
}

BulkIngestSink is a buffer, ready for Parquet data to be written to it. It can be an in-memory buffer, or it could be an open file handle.

type BulkIngestTableExistsBehavior

type BulkIngestTableExistsBehavior int
const (
	BulkIngestTableExistsError BulkIngestTableExistsBehavior = iota
	BulkIngestTableExistsIgnore
	BulkIngestTableExistsDrop
)

type BulkIngestTableMissingBehavior

type BulkIngestTableMissingBehavior int
const (
	BulkIngestTableMissingError BulkIngestTableMissingBehavior = iota
	BulkIngestTableMissingCreate
)

type ColumnInfo

type ColumnInfo struct {
	ColumnName            string  `json:"column_name"`
	OrdinalPosition       *int32  `json:"ordinal_position,omitempty"`
	Remarks               *string `json:"remarks,omitempty"`
	XdbcDataType          *int16  `json:"xdbc_data_type,omitempty"`
	XdbcTypeName          *string `json:"xdbc_type_name,omitempty"`
	XdbcColumnSize        *int32  `json:"xdbc_column_size,omitempty"`
	XdbcDecimalDigits     *int16  `json:"xdbc_decimal_digits,omitempty"`
	XdbcNumPrecRadix      *int16  `json:"xdbc_num_prec_radix,omitempty"`
	XdbcNullable          *int16  `json:"xdbc_nullable,omitempty"`
	XdbcColumnDef         *string `json:"xdbc_column_def,omitempty"`
	XdbcSqlDataType       *int16  `json:"xdbc_sql_data_type,omitempty"`
	XdbcDatetimeSub       *int16  `json:"xdbc_datetime_sub,omitempty"`
	XdbcCharOctetLength   *int32  `json:"xdbc_char_octet_length,omitempty"`
	XdbcIsNullable        *string `json:"xdbc_is_nullable,omitempty"`
	XdbcScopeCatalog      *string `json:"xdbc_scope_catalog,omitempty"`
	XdbcScopeSchema       *string `json:"xdbc_scope_schema,omitempty"`
	XdbcScopeTable        *string `json:"xdbc_scope_table,omitempty"`
	XdbcIsAutoincrement   *bool   `json:"xdbc_is_autoincrement,omitempty"`
	XdbcIsGeneratedcolumn *bool   `json:"xdbc_is_generatedcolumn,omitempty"`
}

ColumnInfo is a structured representation of adbc.ColumnSchema

type Connection

type Connection interface {
	adbc.Connection
	adbc.GetSetOptions
}

Connection is the interface satisfied by the result of the NewConnection constructor, given that an input is provided satisfying the ConnectionImpl interface.

type ConnectionBuilder

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

func NewConnectionBuilder

func NewConnectionBuilder(impl ConnectionImpl) *ConnectionBuilder

func (*ConnectionBuilder) Connection

func (b *ConnectionBuilder) Connection() Connection

func (*ConnectionBuilder) WithAutocommitSetter

func (b *ConnectionBuilder) WithAutocommitSetter(helper AutocommitSetter) *ConnectionBuilder

func (*ConnectionBuilder) WithConcurrency

func (b *ConnectionBuilder) WithConcurrency(concurrency int) *ConnectionBuilder

func (*ConnectionBuilder) WithCurrentNamespacer

func (b *ConnectionBuilder) WithCurrentNamespacer(helper CurrentNamespacer) *ConnectionBuilder

func (*ConnectionBuilder) WithDbObjectsEnumerator

func (b *ConnectionBuilder) WithDbObjectsEnumerator(helper DbObjectsEnumerator) *ConnectionBuilder

func (*ConnectionBuilder) WithDbObjectsEnumeratorFactory

func (b *ConnectionBuilder) WithDbObjectsEnumeratorFactory(helper DbObjectsEnumeratorFactory) *ConnectionBuilder

func (*ConnectionBuilder) WithDriverInfoPreparer

func (b *ConnectionBuilder) WithDriverInfoPreparer(helper DriverInfoPreparer) *ConnectionBuilder

func (*ConnectionBuilder) WithTableTypeLister

func (b *ConnectionBuilder) WithTableTypeLister(helper TableTypeLister) *ConnectionBuilder

type ConnectionImpl

type ConnectionImpl interface {
	adbc.Connection
	adbc.GetSetOptions
	adbc.OTelTracing
	Base() *ConnectionImplBase
}

ConnectionImpl is an interface that drivers implement to provide vendor-specific functionality.

type ConnectionImplBase

type ConnectionImplBase struct {
	Alloc       memory.Allocator
	ErrorHelper ErrorHelper
	DriverInfo  *DriverInfo
	Logger      *slog.Logger
	Tracer      trace.Tracer

	Autocommit bool
	Closed     bool
	// contains filtered or unexported fields
}

ConnectionImplBase is a struct that provides default implementations of the ConnectionImpl interface. It is meant to be used as a composite struct for a driver's ConnectionImpl implementation.

func NewConnectionImplBase

func NewConnectionImplBase(database *DatabaseImplBase) ConnectionImplBase

NewConnectionImplBase instantiates ConnectionImplBase.

  • database is a DatabaseImplBase containing the common resources from the parent database, allowing the Arrow allocator, error handler, and logger to be reused.

func (*ConnectionImplBase) Base

func (base *ConnectionImplBase) Base() *ConnectionImplBase

func (*ConnectionImplBase) Close

func (base *ConnectionImplBase) Close() error

func (*ConnectionImplBase) Commit

func (base *ConnectionImplBase) Commit(ctx context.Context) error

func (*ConnectionImplBase) GetInfo

func (base *ConnectionImplBase) GetInfo(ctx context.Context, infoCodes []adbc.InfoCode) (reader array.RecordReader, err error)

func (*ConnectionImplBase) GetInitialSpanAttributes

func (cnxn *ConnectionImplBase) GetInitialSpanAttributes() []attribute.KeyValue

func (*ConnectionImplBase) GetObjects

func (base *ConnectionImplBase) GetObjects(ctx context.Context, depth adbc.ObjectDepth, catalog *string, dbSchema *string, tableName *string, columnName *string, tableType []string) (array.RecordReader, error)

func (*ConnectionImplBase) GetOption

func (base *ConnectionImplBase) GetOption(key string) (string, error)

func (*ConnectionImplBase) GetOptionBytes

func (base *ConnectionImplBase) GetOptionBytes(key string) ([]byte, error)

func (*ConnectionImplBase) GetOptionDouble

func (base *ConnectionImplBase) GetOptionDouble(key string) (float64, error)

func (*ConnectionImplBase) GetOptionInt

func (base *ConnectionImplBase) GetOptionInt(key string) (int64, error)

func (*ConnectionImplBase) GetTableSchema

func (base *ConnectionImplBase) GetTableSchema(ctx context.Context, catalog *string, dbSchema *string, tableName string) (*arrow.Schema, error)

func (*ConnectionImplBase) GetTableTypes

func (base *ConnectionImplBase) GetTableTypes(context.Context) (array.RecordReader, error)

func (*ConnectionImplBase) GetTraceParent

func (cnxn *ConnectionImplBase) GetTraceParent() string

func (*ConnectionImplBase) NewStatement

func (base *ConnectionImplBase) NewStatement() (adbc.Statement, error)

func (*ConnectionImplBase) ReadPartition

func (base *ConnectionImplBase) ReadPartition(ctx context.Context, serializedPartition []byte) (array.RecordReader, error)

func (*ConnectionImplBase) Rollback

func (base *ConnectionImplBase) Rollback(context.Context) error

func (*ConnectionImplBase) SetOption

func (base *ConnectionImplBase) SetOption(key string, val string) error

func (*ConnectionImplBase) SetOptionBytes

func (base *ConnectionImplBase) SetOptionBytes(key string, val []byte) error

func (*ConnectionImplBase) SetOptionDouble

func (base *ConnectionImplBase) SetOptionDouble(key string, val float64) error

func (*ConnectionImplBase) SetOptionInt

func (base *ConnectionImplBase) SetOptionInt(key string, val int64) error

func (*ConnectionImplBase) SetTraceParent

func (cnxn *ConnectionImplBase) SetTraceParent(traceParent string)

func (*ConnectionImplBase) StartSpan

func (cnxn *ConnectionImplBase) StartSpan(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption,
) (context.Context, trace.Span)

type ConstraintColumnUsage

type ConstraintColumnUsage struct {
	ForeignKeyCatalog  *string `json:"fk_catalog,omitempty"`
	ForeignKeyDbSchema *string `json:"fk_db_schema,omitempty"`
	ForeignKeyTable    string  `json:"fk_table"`
	ForeignKeyColumn   string  `json:"fk_column_name"`
}

ConstraintColumnUsage is a structured representation of adbc.UsageSchema

type ConstraintInfo

type ConstraintInfo struct {
	ConstraintName        *string                 `json:"constraint_name,omitempty"`
	ConstraintType        string                  `json:"constraint_type"`
	ConstraintColumnNames requiredList[string]    `json:"constraint_column_names"`
	ConstraintColumnUsage []ConstraintColumnUsage `json:"constraint_column_usage,omitempty"`
}

ConstraintInfo is a structured representation of adbc.ConstraintSchema

type CurrentNamespacer

type CurrentNamespacer interface {
	GetCurrentCatalog() (string, error)
	GetCurrentDbSchema() (string, error)
	SetCurrentCatalog(string) error
	SetCurrentDbSchema(string) error
}

CurrentNamespacer is an interface that drivers may implement to delegate stateful namespacing with DB catalogs and schemas. The appropriate (Get/Set)Options implementations will be provided using the results of these methods.

type DBSchemaInfo

type DBSchemaInfo struct {
	DbSchemaName   *string     `json:"db_schema_name,omitempty"`
	DbSchemaTables []TableInfo `json:"db_schema_tables"`
}

DBSchemaInfo is a structured representation of adbc.DBSchemaSchema

type Database

Database is the interface satisfied by the result of the NewDatabase constructor, given an input is provided satisfying the DatabaseImpl interface.

func NewDatabase

func NewDatabase(impl DatabaseImpl) Database

NewDatabase wraps a DatabaseImpl to create an adbc.Database.

type DatabaseImpl

type DatabaseImpl interface {
	adbc.Database
	adbc.GetSetOptions
	Base() *DatabaseImplBase
}

DatabaseImpl is an interface that drivers implement to provide vendor-specific functionality.

type DatabaseImplBase

type DatabaseImplBase struct {
	Alloc       memory.Allocator
	ErrorHelper ErrorHelper
	DriverInfo  *DriverInfo
	Logger      *slog.Logger
	Tracer      trace.Tracer
	// contains filtered or unexported fields
}

DatabaseImplBase is a struct that provides default implementations of the DatabaseImpl interface. It is meant to be used as a composite struct for a driver's DatabaseImpl implementation.

func NewDatabaseImplBase

func NewDatabaseImplBase(ctx context.Context, driver *DriverImplBase) (DatabaseImplBase, error)

NewDatabaseImplBase instantiates DatabaseImplBase.

  • driver is a DriverImplBase containing the common resources from the parent driver, allowing the Arrow allocator and error handler to be reused.

func (*DatabaseImplBase) Base

func (base *DatabaseImplBase) Base() *DatabaseImplBase

func (*DatabaseImplBase) Close

func (base *DatabaseImplBase) Close() (err error)

func (*DatabaseImplBase) GetInitialSpanAttributes

func (d *DatabaseImplBase) GetInitialSpanAttributes() []attribute.KeyValue

func (*DatabaseImplBase) GetOption

func (base *DatabaseImplBase) GetOption(key string) (string, error)

func (*DatabaseImplBase) GetOptionBytes

func (base *DatabaseImplBase) GetOptionBytes(key string) ([]byte, error)

func (*DatabaseImplBase) GetOptionDouble

func (base *DatabaseImplBase) GetOptionDouble(key string) (float64, error)

func (*DatabaseImplBase) GetOptionInt

func (base *DatabaseImplBase) GetOptionInt(key string) (int64, error)

func (*DatabaseImplBase) GetTraceParent

func (d *DatabaseImplBase) GetTraceParent() (traceParent string)

func (*DatabaseImplBase) InitTracing

func (base *DatabaseImplBase) InitTracing(ctx context.Context, driverName string, driverVersion string) (err error)

func (*DatabaseImplBase) Open

func (base *DatabaseImplBase) Open(ctx context.Context) (adbc.Connection, error)

func (*DatabaseImplBase) SetOption

func (base *DatabaseImplBase) SetOption(key string, val string) error

func (*DatabaseImplBase) SetOptionBytes

func (base *DatabaseImplBase) SetOptionBytes(key string, val []byte) error

func (*DatabaseImplBase) SetOptionDouble

func (base *DatabaseImplBase) SetOptionDouble(key string, val float64) error

func (*DatabaseImplBase) SetOptionInt

func (base *DatabaseImplBase) SetOptionInt(key string, val int64) error

func (*DatabaseImplBase) SetOptions

func (base *DatabaseImplBase) SetOptions(options map[string]string) error

func (*DatabaseImplBase) SetTraceParent

func (d *DatabaseImplBase) SetTraceParent(traceParent string)

func (*DatabaseImplBase) StartSpan

func (d *DatabaseImplBase) StartSpan(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption,
) (context.Context, trace.Span)

type DbObjectsEnumerator

type DbObjectsEnumerator interface {
	GetCatalogs(ctx context.Context, catalogFilter *string) ([]string, error)
	GetDBSchemasForCatalog(ctx context.Context, catalog string, schemaFilter *string) ([]string, error)
	GetTablesForDBSchema(ctx context.Context, catalog string, schema string, tableFilter *string, columnFilter *string, includeColumns bool) ([]TableInfo, error)
}

DbObjectsEnumerator is an interface that drivers may implement to simplify the implementation of adbc.Connection.GetObjects(). By independently implementing lookup for catalogs, dbSchemas and tables, the driverbase is able to provide the full GetObjects functionality for arbitrary search patterns and lookup depth.

type DbObjectsEnumeratorFactory

type DbObjectsEnumeratorFactory func(context.Context) (DbObjectsEnumerator, error)

DbObjectsEnumeratorFactory generates a DbObjectsEnumerator that will be used for a particular GetObjects call, allowing internally consistent caching without needing global state.

type Driver

type Driver interface {
	adbc.Driver
}

Driver is the interface satisfied by the result of the NewDriver constructor, given an input is provided satisfying the DriverImpl interface.

func NewDriver

func NewDriver(impl DriverImpl) Driver

NewDriver wraps a DriverImpl to create a Driver.

type DriverImpl

type DriverImpl interface {
	adbc.Driver
	adbc.DriverWithContext
	Base() *DriverImplBase
}

DriverImpl is an interface that drivers implement to provide vendor-specific functionality.

type DriverImplBase

type DriverImplBase struct {
	Alloc       memory.Allocator
	ErrorHelper ErrorHelper
	DriverInfo  *DriverInfo
	Logger      *slog.Logger
}

DriverImplBase is a struct that provides default implementations of the DriverImpl interface. It is meant to be used as a composite struct for a driver's DriverImpl implementation.

func NewDriverImplBase

func NewDriverImplBase(info *DriverInfo, alloc memory.Allocator) DriverImplBase

NewDriverImplBase instantiates DriverImplBase.

  • info contains build and vendor info, as well as the name to construct error messages.
  • alloc is an Arrow allocator to use.

func (*DriverImplBase) Base

func (base *DriverImplBase) Base() *DriverImplBase

func (*DriverImplBase) NewDatabase

func (base *DriverImplBase) NewDatabase(opts map[string]string) (adbc.Database, error)

func (*DriverImplBase) NewDatabaseWithContext

func (base *DriverImplBase) NewDatabaseWithContext(ctx context.Context, opts map[string]string) (adbc.Database, error)

func (*DriverImplBase) SetLogger

func (base *DriverImplBase) SetLogger(logger *slog.Logger)

type DriverInfo

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

func DefaultDriverInfo

func DefaultDriverInfo(name string) *DriverInfo

func (*DriverInfo) GetInfoForInfoCode

func (di *DriverInfo) GetInfoForInfoCode(code adbc.InfoCode) (any, bool)

func (*DriverInfo) GetName

func (di *DriverInfo) GetName() string

func (*DriverInfo) InfoSupportedCodes

func (di *DriverInfo) InfoSupportedCodes() []adbc.InfoCode

func (*DriverInfo) MustRegister

func (di *DriverInfo) MustRegister(codes map[adbc.InfoCode]any)

func (*DriverInfo) RegisterInfoCode

func (di *DriverInfo) RegisterInfoCode(code adbc.InfoCode, value any) error

type DriverInfoPreparer

type DriverInfoPreparer interface {
	PrepareDriverInfo(ctx context.Context, infoCodes []adbc.InfoCode) error
}

DriverInfoPreparer is an interface that drivers may implement to add/update DriverInfo values whenever adbc.Connection.GetInfo() is called.

type ErrorHelper

type ErrorHelper struct {
	DriverName     string
	ErrorInspector ErrorInspector
}

ErrorHelper helps format errors for ADBC drivers.

func (*ErrorHelper) AlreadyExists

func (helper *ErrorHelper) AlreadyExists(message string, format ...any) error

func (*ErrorHelper) Cancelled

func (helper *ErrorHelper) Cancelled(message string, format ...any) error

func (*ErrorHelper) Errorf

func (helper *ErrorHelper) Errorf(code adbc.Status, message string, format ...any) error

func (*ErrorHelper) IO

func (helper *ErrorHelper) IO(message string, format ...any) error

func (*ErrorHelper) Integrity

func (helper *ErrorHelper) Integrity(message string, format ...any) error

func (*ErrorHelper) Internal

func (helper *ErrorHelper) Internal(message string, format ...any) error

func (*ErrorHelper) InvalidArgument

func (helper *ErrorHelper) InvalidArgument(message string, format ...any) error

func (*ErrorHelper) InvalidData

func (helper *ErrorHelper) InvalidData(message string, format ...any) error

func (*ErrorHelper) InvalidState

func (helper *ErrorHelper) InvalidState(message string, format ...any) error

func (*ErrorHelper) NotFound

func (helper *ErrorHelper) NotFound(message string, format ...any) error

func (*ErrorHelper) NotImplemented

func (helper *ErrorHelper) NotImplemented(message string, format ...any) error

func (*ErrorHelper) Timeout

func (helper *ErrorHelper) Timeout(message string, format ...any) error

func (*ErrorHelper) Unauthenticated

func (helper *ErrorHelper) Unauthenticated(message string, format ...any) error

func (*ErrorHelper) Unauthorized

func (helper *ErrorHelper) Unauthorized(message string, format ...any) error

func (*ErrorHelper) Unknown

func (helper *ErrorHelper) Unknown(message string, format ...any) error

func (*ErrorHelper) WrapAlreadyExists

func (helper *ErrorHelper) WrapAlreadyExists(err error, format string, args ...any) error

func (*ErrorHelper) WrapCancelled

func (helper *ErrorHelper) WrapCancelled(err error, format string, args ...any) error

func (*ErrorHelper) WrapIO

func (helper *ErrorHelper) WrapIO(err error, format string, args ...any) error

func (*ErrorHelper) WrapIntegrity

func (helper *ErrorHelper) WrapIntegrity(err error, format string, args ...any) error

func (*ErrorHelper) WrapInternal

func (helper *ErrorHelper) WrapInternal(err error, format string, args ...any) error

func (*ErrorHelper) WrapInvalidArgument

func (helper *ErrorHelper) WrapInvalidArgument(err error, format string, args ...any) error

func (*ErrorHelper) WrapInvalidData

func (helper *ErrorHelper) WrapInvalidData(err error, format string, args ...any) error

func (*ErrorHelper) WrapInvalidState

func (helper *ErrorHelper) WrapInvalidState(err error, format string, args ...any) error

func (*ErrorHelper) WrapNotFound

func (helper *ErrorHelper) WrapNotFound(err error, format string, args ...any) error

func (*ErrorHelper) WrapNotImplemented

func (helper *ErrorHelper) WrapNotImplemented(err error, format string, args ...any) error

func (*ErrorHelper) WrapTimeout

func (helper *ErrorHelper) WrapTimeout(err error, format string, args ...any) error

func (*ErrorHelper) WrapUnauthenticated

func (helper *ErrorHelper) WrapUnauthenticated(err error, format string, args ...any) error

func (*ErrorHelper) WrapUnauthorized

func (helper *ErrorHelper) WrapUnauthorized(err error, format string, args ...any) error

func (*ErrorHelper) WrapUnknown

func (helper *ErrorHelper) WrapUnknown(err error, format string, args ...any) error

type ErrorInspector

type ErrorInspector interface {
	InspectError(err error, defaultStatus adbc.Status) adbc.Error
}

ErrorInspector inspects database driver errors and formats them as ADBC errors. Drivers can implement this interface to map database-specific errors to ADBC status codes, format vendor-specific error messages, and extract error details like SQLSTATE and vendor codes.

type GetObjectsInfo

type GetObjectsInfo struct {
	CatalogName      *string        `json:"catalog_name,omitempty"`
	CatalogDbSchemas []DBSchemaInfo `json:"catalog_db_schemas"`
}

GetObjectsInfo is a structured representation of adbc.GetObjectsSchema

func (*GetObjectsInfo) Scan

func (g *GetObjectsInfo) Scan(src any) error

Scan implements sql.Scanner.

type RecordReaderImpl

type RecordReaderImpl interface {
	io.Closer
	// AppendRows adds one or more rows of the current result set to the
	// record builder. Return io.EOF if no more rows can be appended from
	// the current result set. Return the number of rows appended, and an
	// estimate of row size. If ErrOverflow is returned, end the current
	// batch immediately. It is assumed the reader can retry again on the
	// next call.
	AppendRows(builder *array.RecordBuilder) (int64, int64, error)
	// BeginAppending is called exactly once before the first call to
	// AppendRow. The implementation can do any necessary initialization
	// here. It will be called after the first call to NextResultSet.
	BeginAppending(builder *array.RecordBuilder) error
	// NextResultSet closes the current result set and opens the next
	// result set for the given parameters. If there are no parameters, it
	// will be called exactly once with rec == nil.
	NextResultSet(ctx context.Context, rec arrow.RecordBatch, rowIdx int) (*arrow.Schema, error)
}

RecordReaderImpl is a row-wise implementation of a record reader. The driverbase can pivot this into an array.RecordReader.

type Shared

type Shared[T any] struct {
	// contains filtered or unexported fields
}

Shared allows shared usage of an underlying resource, but not concurrently.

func NewShared

func NewShared[T any](handle *T, closer io.Closer) *Shared[T]

func (*Shared[T]) Close

func (sh *Shared[T]) Close() error

func (*Shared[T]) Hold

func (sh *Shared[T]) Hold() (SharedHandle[T], error)

Hold gets exclusive access to the connection until the returned handle is released. Use sparingly; do not create long-lived handles as it increases potential for deadlock.

func (*Shared[T]) Run

func (sh *Shared[T]) Run(closure func(*T) error) error

type SharedHandle

type SharedHandle[T any] struct {
	// contains filtered or unexported fields
}

func (*SharedHandle[T]) Handle

func (sh *SharedHandle[T]) Handle() *T

func (*SharedHandle[T]) Release

func (sh *SharedHandle[T]) Release()

type Statement

type Statement interface {
	adbc.Statement
	adbc.GetSetOptions
}

func NewStatement

func NewStatement(impl StatementImpl) Statement

type StatementImplBase

type StatementImplBase struct {
	ErrorHelper ErrorHelper
	Tracer      trace.Tracer
	// contains filtered or unexported fields
}

func NewStatementImplBase

func NewStatementImplBase(cnxn *ConnectionImplBase, errorHelper ErrorHelper) StatementImplBase

func (*StatementImplBase) GetInitialSpanAttributes

func (st *StatementImplBase) GetInitialSpanAttributes() []attribute.KeyValue

func (*StatementImplBase) GetOption

func (st *StatementImplBase) GetOption(key string) (string, error)

func (*StatementImplBase) GetOptionBytes

func (st *StatementImplBase) GetOptionBytes(key string) ([]byte, error)

func (*StatementImplBase) GetOptionDouble

func (st *StatementImplBase) GetOptionDouble(key string) (float64, error)

func (*StatementImplBase) GetOptionInt

func (st *StatementImplBase) GetOptionInt(key string) (int64, error)

func (*StatementImplBase) GetTraceParent

func (st *StatementImplBase) GetTraceParent() string

func (*StatementImplBase) SetOption

func (st *StatementImplBase) SetOption(key, value string) error

func (*StatementImplBase) SetOptionBytes

func (st *StatementImplBase) SetOptionBytes(key string, value []byte) error

func (*StatementImplBase) SetOptionDouble

func (st *StatementImplBase) SetOptionDouble(key string, value float64) error

func (*StatementImplBase) SetOptionInt

func (st *StatementImplBase) SetOptionInt(key string, value int64) error

func (*StatementImplBase) SetTraceParent

func (st *StatementImplBase) SetTraceParent(traceParent string)

func (*StatementImplBase) StartSpan

func (st *StatementImplBase) StartSpan(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption,
) (context.Context, trace.Span)

type TableInfo

type TableInfo struct {
	TableName        string           `json:"table_name"`
	TableType        string           `json:"table_type"`
	TableColumns     []ColumnInfo     `json:"table_columns"`
	TableConstraints []ConstraintInfo `json:"table_constraints"`
}

TableInfo is a structured representation of adbc.TableSchema

type TableTypeLister

type TableTypeLister interface {
	ListTableTypes(ctx context.Context) ([]string, error)
}

TableTypeLister is an interface that drivers may implement to simplify the implementation of adbc.Connection.GetTableTypes() for backends that do not natively send these values as arrow records. The conversion of the result to a RecordReader is handled automatically.

type WriterProps

type WriterProps struct {
	// A target file size in bytes.
	MaxBytes           int64
	ParquetWriterProps *parquet.WriterProperties
	ArrowWriterProps   pqarrow.ArrowWriterProperties
}

WriterProps holds properties for writing data files to be ingested.

type XdbcDataType

type XdbcDataType int32

The JDBC/ODBC-defined type of any object. All the values here are the sames as in the JDBC and ODBC specs.

const (
	XdbcDataType_XDBC_UNKNOWN_TYPE  XdbcDataType = 0
	XdbcDataType_XDBC_CHAR          XdbcDataType = 1
	XdbcDataType_XDBC_NUMERIC       XdbcDataType = 2
	XdbcDataType_XDBC_DECIMAL       XdbcDataType = 3
	XdbcDataType_XDBC_INTEGER       XdbcDataType = 4
	XdbcDataType_XDBC_SMALLINT      XdbcDataType = 5
	XdbcDataType_XDBC_FLOAT         XdbcDataType = 6
	XdbcDataType_XDBC_REAL          XdbcDataType = 7
	XdbcDataType_XDBC_DOUBLE        XdbcDataType = 8
	XdbcDataType_XDBC_DATETIME      XdbcDataType = 9
	XdbcDataType_XDBC_INTERVAL      XdbcDataType = 10
	XdbcDataType_XDBC_VARCHAR       XdbcDataType = 12
	XdbcDataType_XDBC_DATE          XdbcDataType = 91
	XdbcDataType_XDBC_TIME          XdbcDataType = 92
	XdbcDataType_XDBC_TIMESTAMP     XdbcDataType = 93
	XdbcDataType_XDBC_LONGVARCHAR   XdbcDataType = -1
	XdbcDataType_XDBC_BINARY        XdbcDataType = -2
	XdbcDataType_XDBC_VARBINARY     XdbcDataType = -3
	XdbcDataType_XDBC_LONGVARBINARY XdbcDataType = -4
	XdbcDataType_XDBC_BIGINT        XdbcDataType = -5
	XdbcDataType_XDBC_TINYINT       XdbcDataType = -6
	XdbcDataType_XDBC_BIT           XdbcDataType = -7
	XdbcDataType_XDBC_WCHAR         XdbcDataType = -8
	XdbcDataType_XDBC_WVARCHAR      XdbcDataType = -9
)

func ToXdbcDataType

func ToXdbcDataType(dt arrow.DataType) (xdbcType XdbcDataType)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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