datafusion

package module
v0.0.0-...-4eccb2b Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

README

datafusion-go

Go Reference CI Go Report Card

datafusion-go is a Go database/sql driver and Arrow bridge backed by Apache DataFusion's in-process query engine.

Use it when you want analytic SQL from Go without running a database server, while still having access to Arrow record batches for callers that need exact Arrow schemas or complex values.

Status

  • Current module version: v0.530100.1.
  • Bundled Apache DataFusion version: 53.1.0.
  • Minimum Go version: 1.24.
  • Normal execution requires cgo and a C toolchain.
  • Transactions are not supported.
  • The DSN opens an in-process DataFusion session, not a remote host or file-backed embedded database.
  • Release automation publishes native libraries for darwin-arm64, darwin-amd64, linux-amd64, linux-arm64, and windows-amd64. Windows arm64 is not currently bundled.

Release metadata is maintained in versions.toml. Release tags are derived as v<major>.<encoded-datafusion-version>.<patch>, where DataFusion 53.1.0 encodes as 530100.

Why datafusion-go?

Apache DataFusion is a Rust query engine built around Arrow. datafusion-go wraps it for Go applications that already use database/sql, but it does not force every result through scalar row conversion.

The package has two main paths:

  • database/sql for ordinary SQL execution, prepared statements, connection pooling, and scalar row scanning.
  • Arrow-native APIs for streaming arrow.RecordBatch values and registering Go Arrow readers as DataFusion tables.

The driver is intentionally in-process. It is useful for local analytic execution, tests, tools, embedded query features, and services that want DataFusion inside the Go process. It is not a network database client, and it does not make DataFusion behave like a persistent file database.

Install

go get github.com/datafusion-contrib/datafusion-go

Install from a tagged release for normal consumer use. Pseudo-versions from @main are development snapshots and may not have matching GitHub Release assets for the native runtime downloader.

Normal builds require:

  • Go with CGO_ENABLED=1.
  • A C toolchain for the target platform.
  • A compatible libdatafusion_go native library at runtime.

Default builds use cgo but do not link DataFusion at Go link time. At runtime, the driver looks for a shared native library in this order:

  1. DATAFUSION_GO_LIBRARY, if set.
  2. internal/native/lib/<goos>-<goarch>/ in a source checkout.
  3. A checksum-verified library downloaded from the matching GitHub Release into the user cache.

Set DATAFUSION_GO_NO_DOWNLOAD=1 to disable automatic release-asset downloads. Set DATAFUSION_GO_DOWNLOAD_BASE to override the release download base URL.

CGO_ENABLED=0 is not supported for normal use; the package returns a clear datafusion-go requires cgo error in that mode.

Quick Start

Import the driver for registration and open the datafusion driver with an empty DSN:

package main

import (
	"context"
	"database/sql"
	"fmt"
	"log"

	_ "github.com/datafusion-contrib/datafusion-go"
)

func main() {
	db, err := sql.Open("datafusion", "")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	var one int64
	if err := db.QueryRowContext(context.Background(), "select 1").Scan(&one); err != nil {
		log.Fatal(err)
	}

	fmt.Println(one)
}

Runnable examples are available in:

Core Concepts

Driver and Sessions

The package registers itself with database/sql as datafusion.

db, err := sql.Open("datafusion", "")

A sql.DB opened by one connector shares a DataFusion SessionContext by default. This matches typical database/sql expectations: catalog changes such as CREATE VIEW are visible across pooled connections from the same sql.DB.

Use isolated sessions when you want each physical connection to have its own DataFusion session state:

db, err := sql.Open("datafusion", "?datafusion.go.shared_session=false")

Or configure it directly on a connector:

connector, err := datafusion.NewConnectorWithInitContext(
	"",
	nil,
	datafusion.WithSharedSession(false),
)
DSNs

Supported DSNs are:

  • ""
  • ?<options>
  • datafusion://
  • datafusion://?<options>

Query parameters are passed to DataFusion as session configuration options:

?datafusion.execution.batch_size=8192

Driver-owned options use the datafusion.go. prefix and are stripped before the remaining options are passed to DataFusion:

?datafusion.go.shared_session=false

File paths, hosts, and other URL forms are rejected. The URL form exists only to carry session options.

Query Paths

Use ordinary database/sql calls when rows contain scalar Arrow values that can be represented as database/sql/driver.Value values:

rows, err := db.QueryContext(ctx, "select 1 as value")

Use QueryArrowContext when you need exact Arrow schemas, record-batch streaming, or complex Arrow values that database/sql cannot scan:

conn, err := db.Conn(ctx)
if err != nil {
	return err
}
defer conn.Close()

reader, err := datafusion.QueryArrowContext(ctx, conn, "select 1 as value")
if err != nil {
	return err
}
defer reader.Close()

Records returned by Read must be released by the caller.

Common Usage

Initialization

Use NewConnector or NewConnectorWithInitContext when a pooled database needs setup SQL before use.

connector, err := datafusion.NewConnectorWithInitContext(
	"",
	func(ctx context.Context, exec driver.ExecerContext) error {
		_, err := exec.ExecContext(ctx, "create view nums as select 1 as n", nil)
		return err
	},
)
if err != nil {
	return err
}
defer connector.Close()

db := sql.OpenDB(connector)
defer db.Close()

In shared-session mode, the initialization callback runs once per connector. In isolated-session mode, it runs for each connection and reset.

Multiple Setup Statements

DataFusion prepares one SQL statement at a time. Split migration or setup scripts before calling the driver, then execute the statements in order:

err := datafusion.ExecStatements(ctx, db, []string{
	"create view one as select 1 as n",
	"create view two as select 2 as n",
})

The helper skips blank statements and wraps errors with the statement index.

Context Cancellation

Query contexts are bridged to native cancellation. Cancellation is checked during planning, stream creation, and record-batch reads.

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

rows, err := db.QueryContext(ctx, "select * from some_large_table")

Native cancellation errors can be matched with errors.Is(err, datafusion.ErrNativeCancelled).

SQL Parameters

The driver supports DataFusion SQL parameters through database/sql:

row := db.QueryRowContext(ctx, "select ? + 1, ?", int64(41), "x")

Supported ordinary parameter values are:

  • nil
  • bool
  • signed integer types that fit int64
  • unsigned integer types as DataFusion UInt64
  • floating-point values as float64
  • string
  • []byte
  • time.Time as Timestamp[ns]
  • time.Duration as Duration[ns]

time.Time preserves loadable IANA locations such as America/New_York. Fixed-offset, local, or otherwise non-loadable locations bind as UTC unless TimestampWithTimeZone is used. float32 values are promoted to DataFusion Float64 through database/sql conversion.

Other values are rejected by CheckNamedValue before native execution.

Use typed wrappers when inference would be ambiguous or when exact Arrow/DataFusion types matter:

row := db.QueryRowContext(
	ctx,
	"select $1, $2, $3, $4, $5",
	datafusion.DateFromTime(day),
	datafusion.TimeFromTime(clock),
	datafusion.DurationFromTime(2*time.Second),
	datafusion.DecimalString("123.45", 10, 2),
	datafusion.NullOf(datafusion.ParameterInt64),
)

Available wrappers cover UInt64, Date, Time, Timestamp, Duration, Decimal, and typed nulls through NullOf, NullDecimal, and NullTimestamp.

Bare nil binds as DataFusion's untyped null. Use NullOf, NullDecimal, or NullTimestamp when DataFusion needs a concrete type, for example select $1 + 1 with NullOf(ParameterInt64).

Prepared statements report Stmt.NumInput for ? placeholders, $1/$2 positional parameters, and distinct $name parameters. Repeated named parameters count once; each ? occurrence counts as a separate positional parameter. Mixed question-mark, dollar-numbered, and named parameter styles are rejected during prepare.

Named statements must be executed with matching sql.Named arguments. Positional arguments for named statements, named arguments for positional statements, missing names, extra names, and duplicate supplied names are rejected before query execution is handed to DataFusion.

Arrow Native Usage

Query Arrow Batches

QueryArrowContext executes SQL on a *sql.Conn and returns a closeable Arrow reader:

reader, err := datafusion.QueryArrowContext(ctx, conn, "select $1", int64(42))
if err != nil {
	return err
}
defer reader.Close()

for {
	record, err := reader.Read()
	if err == io.EOF {
		break
	}
	if err != nil {
		return err
	}
	// Use record.
	record.Release()
}

The Arrow reader owns native stream resources and must be closed. A finalizer is installed as a leak safety net, but finalizers are not prompt cleanup and should not be relied on for normal resource management.

Register Arrow Tables

Arrow record readers can be registered as in-memory DataFusion tables:

rdr, err := array.NewRecordReader(schema, []arrow.RecordBatch{batch})
if err != nil {
	return err
}
defer rdr.Release()

if err := datafusion.RegisterArrowReader(ctx, conn, "events", rdr); err != nil {
	return err
}

RegisterArrowReader consumes the remaining batches from the reader, serializes them as an Arrow IPC stream, and registers decoded Rust-owned batches. The copy is intentional: a registered table can outlive the cgo call, while ordinary Go Arrow arrays can contain Go-owned buffers that native code must not retain.

RegisterArrowReaderZeroCopy skips the IPC copy by exporting the reader through the Arrow C Stream Interface. Use it only when every exported Arrow buffer is valid for native code to retain until the table is dropped or the owning session/connector closes, for example data built with Arrow Go's memory/mallocator package or another C/foreign allocator.

Do not use the zero-copy API with ordinary Go-allocated Arrow buffers unless you fully own that lifetime and cgo pointer-safety tradeoff.

API Overview

Important exported APIs:

  • Driver: the database/sql/driver.Driver registered as datafusion.
  • Connector: owns the native DataFusion database handle used to open pooled connections.
  • NewConnector: creates a connector with an optional initialization callback.
  • NewConnectorWithInitContext: creates a connector whose initialization callback receives a context.
  • WithSharedSession: controls whether connections from one connector share a DataFusion SessionContext.
  • ExecStatements: executes an already-split slice of SQL statements.
  • QueryArrowContext: streams Arrow record batches from a *sql.Conn.
  • RegisterArrowReader: safely registers a Go Arrow reader as a DataFusion table through IPC copy.
  • RegisterArrowReaderZeroCopy: registers Arrow data without IPC copy when native buffer lifetime is guaranteed.
  • Error: structured driver errors with operation type and native error kind.
  • DataFusionVersion and DataFusionGoVersion: generated version constants.

See the Go package documentation for the complete API reference.

Type Conversion

database/sql row conversion currently supports:

Arrow type family Go value
Null nil
Bool bool
Signed integers int64
Unsigned integers int64 when in range
Float16/Float32/Float64 float64
Utf8/LargeUtf8/StringView string
Binary/LargeBinary/FixedSizeBinary/BinaryView []byte
Date/Time/Timestamp time.Time
Duration int64 nanoseconds
Decimal string
Intervals string

Column metadata is exposed through database/sql where Arrow schema information is precise: nullable columns use typed sql.Null* scan types where practical, fixed-size binary columns report length, decimal columns report precision and scale, and temporal/interval database type names include their Arrow unit or interval subtype.

Variable-width string and binary columns do not report declared lengths because DataFusion's Arrow result schema does not preserve SQL declarations such as VARCHAR(32).

Time-only values are returned as UTC time.Time values on the Unix epoch date. Duration values are returned as int64 nanoseconds because time.Duration is not a legal database/sql/driver.Value. Interval values are returned as strings that preserve their month, day, millisecond, and nanosecond components.

Nested and complex Arrow values such as lists, structs, maps, unions, dictionaries, extensions, and run-end encoded values are rejected from database/sql row conversion when schema information is available. Use the Arrow-native reader for exact batch data.

Semantics and Limits

  • PrepareContext validates SQL syntax with DataFusion's parser.
  • A prepared query must contain exactly one SQL statement. Multiple result sets are not supported; Rows.NextResultSet reports no additional result sets.
  • Stmt.NumInput reports parser-derived parameter counts for question-mark, dollar-numbered, or named parameters.
  • Connections from one connector share a DataFusion SessionContext by default.
  • Shared sessions intentionally share session-scoped catalog/config mutations, including CREATE VIEW, DROP VIEW, and SET, across all connections from the same connector.
  • Non-query statements are serialized at the connector level across ExecContext, QueryContext, and QueryArrowContext; queries can still observe normal ordering effects if they run concurrently with DDL.
  • Pooled reuse implements driver.SessionResetter. Shared sessions validate the connection and preserve shared session state; isolated sessions recreate the underlying SessionContext and rerun the connector initialization callback when one was provided.
  • Connections implement driver.Validator; closed connections are reported invalid before they return to the pool.
  • Native errors carry machine-readable error kinds across the C ABI and are exposed on *datafusion.Error.NativeKind.
  • errors.Is can match native sentinel errors: ErrNativeCancelled, ErrNativeInvalidArgument, ErrNativeFailure, and ErrNativePanic.
  • RowsAffected returns 0 by default and reports the sum of a single integer count, rows_affected, or rowsaffected output column when DataFusion emits one.
  • LastInsertId returns 0, nil; DataFusion does not expose insert IDs through this driver.
  • Prepared statement handles are reused when callers use db.Prepare or conn.PrepareContext, but DataFusion still plans and executes each run; the driver does not cache DataFusion physical plans.
  • Close is idempotent for connectors, connections, statements, rows, and Arrow readers.
  • Transactions are unsupported and return explicit unsupported errors. BeginTx still honors an already-canceled context before returning the unsupported transaction error.

Linking and Native Runtime

Default builds dynamically load a shared native library at runtime. This keeps ordinary Go builds from linking the DataFusion native library directly.

Source checkouts should run make bundle or make test before invoking Go tests that open the driver directly:

make test

make test builds the Rust shim, copies the generated native archive and shared library to internal/native/lib/<goos>-<goarch>/, and runs the dynamic and bundled Go test paths.

Development link modes:

make rust
go test -tags=datafusion_use_bundled ./...
go test -tags=datafusion_use_source ./...
go test -tags=datafusion_use_static_lib ./...
  • datafusion_use_bundled links the static archive from internal/native/lib/<goos>-<goarch>.
  • datafusion_use_source and datafusion_use_static_lib link from rust/target/release, so run make rust first.
  • On windows-amd64, make rust targets Rust's x86_64-pc-windows-gnu ABI so Go cgo and Rust produce compatible static objects.

Shared-library link mode links with -ldatafusion_go and requires libdatafusion_go to be on the system linker path:

CGO_LDFLAGS="-L/path/to/lib" go test -tags=datafusion_use_lib ./...

Compatibility and Versioning

versions.toml is the only human-maintained release/version source.

After changing it, regenerate derived Go/Rust version files and the Rust lockfile:

make generate
make generate.check

Do not hand-edit generated version constants in:

Generated Go/Rust files and rust/Cargo.lock updates should be committed with the versions.toml change.

Troubleshooting

datafusion-go requires cgo

Enable cgo for normal execution:

CGO_ENABLED=1 go test ./...
Native library not found

If automatic download is disabled or the release does not publish an asset for your platform, either set DATAFUSION_GO_LIBRARY or build a local library:

make bundle
DATAFUSION_GO_LIBRARY="$PWD/internal/native/lib/$(go env GOOS)-$(go env GOARCH)/libdatafusion_go.so" go test ./...

On macOS, use libdatafusion_go.dylib. On Windows, use datafusion_go.dll.

Local checkout tests fail before opening the driver

Run the project build/test target so internal/native/lib/<goos>-<goarch>/ is populated:

make test
DSN rejected

Use an empty DSN or a session-options DSN. Paths, hosts, and file URLs are intentionally unsupported.

sql.Open("datafusion", "")
sql.Open("datafusion", "?datafusion.execution.batch_size=8192")
sql.Open("datafusion", "datafusion://?datafusion.go.shared_session=false")
database/sql cannot scan a result column

The database/sql path rejects complex Arrow values. Use QueryArrowContext to read exact Arrow record batches.

Windows build or test failures

Use a MinGW/GNU C toolchain. The bundled Windows build targets Rust's x86_64-pc-windows-gnu ABI.

Development

Run linting:

make lint

Run the default Go test path:

make test

Run alternate Go link-mode tests:

make test.source
make test.static

Run Rust tests:

cargo test --manifest-path rust/Cargo.toml --release

For release-sensitive changes, prefer the full release verification targets documented in CONTRIBUTING.md.

Distribution

Native libraries are generated by the build and intentionally kept out of Git because the static archives exceed GitHub's normal file-size limits and Go module zips have a 500 MiB source limit.

Release automation builds static archives and shared libraries for darwin-arm64, darwin-amd64, linux-amd64, linux-arm64, and windows-amd64, verifies them without rebundling the current runner's local output, writes the release-asset SHA256SUMS manifest into the tagged tree, and uploads the generated native files plus checksums to the GitHub release.

Before a public release, run the release workflow once with publish=false and verify that all release-runner labels are available in GitHub Actions.

Contributing

See CONTRIBUTING.md for setup, testing, version-bump, and release instructions.

License

This project is licensed under the terms in LICENSE.

Documentation

Overview

Package datafusion provides a database/sql driver backed by Apache DataFusion.

The driver registers as "datafusion". It is intended for in-process analytic SQL over DataFusion's memory/session catalog and Arrow execution engine. Standard database/sql row scanning is supported for scalar Arrow types, and QueryArrowContext exposes native Arrow record batches for callers that need exact Arrow schemas or complex values. RegisterArrowReader registers Go Arrow record readers as DataFusion in-memory tables.

Index

Constants

View Source
const (
	// DataFusionVersion is the exact Rust datafusion crate version pinned by this release.
	DataFusionVersion = "53.1.0"

	// DataFusionVersionEncoded is used in Go module tags: v<major>.<encoded-datafusion-version>.<patch>.
	DataFusionVersionEncoded = "530100"

	// DataFusionGoMajor is the major component of datafusion-go release tags.
	DataFusionGoMajor = 0

	// DataFusionGoPatch is the patch component of datafusion-go release tags.
	DataFusionGoPatch = 1

	// DataFusionGoVersion is the full datafusion-go module version without the leading v.
	DataFusionGoVersion = "0.530100.1"
)

Variables

View Source
var (
	// ErrNativeCancelled matches errors caused by native query cancellation.
	ErrNativeCancelled = errors.New("datafusion native query canceled")
	// ErrNativeInvalidArgument matches native invalid-argument errors.
	ErrNativeInvalidArgument = errors.New("datafusion native invalid argument")
	// ErrNativeFailure matches uncategorized native DataFusion failures.
	ErrNativeFailure = errors.New("datafusion native failure")
	// ErrNativePanic matches panics caught on the Rust side of the FFI boundary.
	ErrNativePanic = errors.New("datafusion native panic")
)

Functions

func ExecStatements

func ExecStatements(ctx context.Context, execer SQLExecerContext, statements []string) error

ExecStatements executes already-split SQL statements in order.

DataFusion prepares exactly one SQL statement at a time, so callers handling migration files should split the script before calling this helper.

func RegisterArrowReader

func RegisterArrowReader(ctx context.Context, sqlConn *sql.Conn, tableName string, reader array.RecordReader) error

RegisterArrowReader registers the remaining batches in reader as a DataFusion in-memory table visible to SQL executed on sqlConn.

This safe path serializes the reader to an Arrow IPC stream and lets the native side decode that stream into Rust-owned Arrow batches. That copy is intentional: the registered table can outlive this call, while ordinary Go Arrow arrays may use Go-owned buffers that must not be retained by native code after a cgo call returns.

func RegisterArrowReaderZeroCopy

func RegisterArrowReaderZeroCopy(ctx context.Context, sqlConn *sql.Conn, tableName string, reader array.RecordReader) error

RegisterArrowReaderZeroCopy registers the remaining batches in reader as a DataFusion in-memory table by exporting reader through the Arrow C Stream Interface.

Unlike RegisterArrowReader, this path does not copy buffers into Rust-owned memory. Use it only when every exported Arrow buffer is safe for native code to retain until the registered table is dropped or the owning DataFusion session/connector is closed, for example buffers allocated with Arrow Go's mallocator or another C/foreign allocator. Passing ordinary Go-allocated Arrow buffers can violate cgo pointer lifetime rules because DataFusion keeps table batches after this call returns.

Types

type ArrowReader

type ArrowReader interface {
	arrio.Reader
	Schema() *arrow.Schema
	Close() error
}

ArrowReader streams Arrow record batches returned by DataFusion.

Callers must close the reader when they are done with it. Close cancels any in-flight native execution and releases native Arrow stream resources.

func QueryArrowContext

func QueryArrowContext(ctx context.Context, sqlConn *sql.Conn, query string, args ...any) (ArrowReader, error)

QueryArrowContext runs query on a DataFusion *sql.Conn and returns Arrow record batches without converting them through database/sql values.

type Conn

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

Conn is a single database/sql driver connection to a DataFusion SessionContext.

func (*Conn) Begin

func (conn *Conn) Begin() (driver.Tx, error)

Begin returns an unsupported error because DataFusion transactions are not supported.

func (*Conn) BeginTx

func (conn *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx returns an unsupported error after honoring an already-canceled context.

func (*Conn) CheckNamedValue

func (conn *Conn) CheckNamedValue(nv *driver.NamedValue) error

CheckNamedValue normalizes DataFusion-specific parameter wrapper types.

func (*Conn) Close

func (conn *Conn) Close() error

Close releases the native connection handle.

func (*Conn) ExecContext

func (conn *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

ExecContext executes a statement and returns a database/sql result.

func (*Conn) IsValid

func (conn *Conn) IsValid() bool

IsValid reports whether the connection can be reused by database/sql.

func (*Conn) Ping

func (conn *Conn) Ping(ctx context.Context) error

Ping validates that the connection is open.

func (*Conn) Prepare

func (conn *Conn) Prepare(query string) (driver.Stmt, error)

Prepare validates and prepares query using a background context.

func (*Conn) PrepareContext

func (conn *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

PrepareContext validates and prepares query.

func (*Conn) QueryArrowContext

func (conn *Conn) QueryArrowContext(ctx context.Context, query string, args []driver.NamedValue) (ArrowReader, error)

QueryArrowContext executes a query and returns Arrow record batches.

func (*Conn) QueryContext

func (conn *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext executes a query and adapts Arrow record batches to database/sql rows.

func (*Conn) ResetSession

func (conn *Conn) ResetSession(ctx context.Context) error

ResetSession resets isolated sessions and validates shared sessions for pool reuse.

type Connector

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

Connector owns the native DataFusion database handle used to open pooled connections.

func NewConnector

func NewConnector(dsn string, initFn func(driver.ExecerContext) error) (*Connector, error)

NewConnector creates a DataFusion connector for database/sql.

func NewConnectorWithInitContext

func NewConnectorWithInitContext(dsn string, initFn func(context.Context, driver.ExecerContext) error, options ...ConnectorOption) (*Connector, error)

NewConnectorWithInitContext creates a DataFusion connector with an optional initialization callback and connector options.

func (*Connector) Close

func (c *Connector) Close() error

Close releases the connector's DataFusion database resources.

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

Connect opens a new DataFusion connection.

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

Driver returns the database/sql driver used by the connector.

type ConnectorOption

type ConnectorOption func(*connectorOptions)

ConnectorOption configures a DataFusion connector.

func WithSharedSession

func WithSharedSession(shared bool) ConnectorOption

WithSharedSession controls whether connections from one Connector share a DataFusion SessionContext.

type Date

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

Date binds a parameter as an Arrow Date32 value.

func DateFromTime

func DateFromTime(t time.Time) Date

DateFromTime returns a Date using t's calendar date in t's location.

func (Date) Days

func (value Date) Days() int32

Days returns the Arrow Date32 day count since the Unix epoch.

func (Date) Time

func (value Date) Time() time.Time

Time returns the date as a UTC time at midnight.

type Decimal

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

Decimal binds a parameter as an Arrow Decimal128 value.

func DecimalString

func DecimalString(value string, precision uint8, scale int8) Decimal

DecimalString returns a Decimal parameter from a base-10 string, precision, and scale.

func NewDecimalString

func NewDecimalString(value string, precision uint8, scale int8) (Decimal, error)

NewDecimalString validates and returns a Decimal parameter from a base-10 string, precision, and scale.

func (Decimal) Precision

func (value Decimal) Precision() uint8

Precision returns the Arrow decimal precision.

func (Decimal) Scale

func (value Decimal) Scale() int8

Scale returns the Arrow decimal scale.

func (Decimal) String

func (value Decimal) String() string

String returns the decimal value's base-10 representation.

type Driver

type Driver struct{}

Driver implements database/sql/driver.Driver for DataFusion.

func (Driver) Open

func (d Driver) Open(dsn string) (driver.Conn, error)

func (Driver) OpenConnector

func (Driver) OpenConnector(dsn string) (driver.Connector, error)

type Duration

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

Duration binds a parameter as an Arrow duration with nanosecond precision.

func DurationFromTime

func DurationFromTime(d time.Duration) Duration

DurationFromTime returns a Duration from a Go time.Duration.

func DurationNanos

func DurationNanos(nanoseconds int64) Duration

DurationNanos returns a Duration from nanoseconds.

func (Duration) Duration

func (value Duration) Duration() time.Duration

Duration returns the value as a Go time.Duration.

func (Duration) Nanoseconds

func (value Duration) Nanoseconds() int64

Nanoseconds returns the duration as nanoseconds.

type Error

type Error struct {
	// Type identifies the driver operation that failed.
	Type ErrorType
	// NativeKind identifies native DataFusion failures when available.
	NativeKind NativeErrorKind
	// Message is the driver-level error message.
	Message string
	// Cause is the wrapped native or lower-level error.
	Cause error
}

Error is the structured error type returned by this driver.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorType

type ErrorType string

ErrorType identifies the operation that failed.

const (
	// ErrorConnect marks failures while opening a database or connection.
	ErrorConnect ErrorType = "connect"
	// ErrorPrepare marks failures while parsing or preparing SQL.
	ErrorPrepare ErrorType = "prepare"
	// ErrorBind marks failures while binding SQL parameters.
	ErrorBind ErrorType = "bind"
	// ErrorExecute marks failures while executing SQL or reading result batches.
	ErrorExecute ErrorType = "execute"
	// ErrorScan marks failures while adapting Arrow values to database/sql rows.
	ErrorScan ErrorType = "scan"
	// ErrorClosed marks use of a closed connector, connection, statement, or reader.
	ErrorClosed ErrorType = "closed"
	// ErrorUnsupported marks operations DataFusion does not support through this driver.
	ErrorUnsupported ErrorType = "unsupported"
	// ErrorNative marks uncategorized native FFI failures.
	ErrorNative ErrorType = "native"
)

type NativeErrorKind

type NativeErrorKind string

NativeErrorKind is the stable public classification for native DataFusion errors.

const (
	// NativeErrorKindCancelled indicates a query canceled through context cancellation.
	NativeErrorKindCancelled NativeErrorKind = "cancelled"
	// NativeErrorKindInvalidArgument indicates invalid SQL, parameters, or API input.
	NativeErrorKindInvalidArgument NativeErrorKind = "invalid_argument"
	// NativeErrorKindNative indicates an uncategorized native DataFusion failure.
	NativeErrorKindNative NativeErrorKind = "native"
	// NativeErrorKindPanic indicates a panic caught on the Rust side of the FFI boundary.
	NativeErrorKindPanic NativeErrorKind = "panic"
)

type Null

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

Null binds a typed null parameter.

func NullDecimal

func NullDecimal(precision uint8, scale int8) Null

NullDecimal returns a typed decimal null.

func NullOf

func NullOf(typ ParameterType) Null

NullOf returns a typed null for non-decimal parameter types.

func NullTimestamp

func NullTimestamp(timeZone string) Null

NullTimestamp returns a typed timestamp null with an explicit Arrow time zone string.

func (Null) Precision

func (value Null) Precision() uint8

Precision returns the decimal precision for decimal typed nulls.

func (Null) Scale

func (value Null) Scale() int8

Scale returns the decimal scale for decimal typed nulls.

func (Null) TimeZone

func (value Null) TimeZone() string

TimeZone returns the Arrow timestamp timezone string for timestamp typed nulls.

func (Null) Type

func (value Null) Type() ParameterType

Type returns the typed-null parameter type.

type ParameterType

type ParameterType int

ParameterType names a DataFusion scalar type for typed null parameters.

const (
	// ParameterBool identifies a boolean parameter.
	ParameterBool ParameterType = iota + 1
	// ParameterInt64 identifies a signed 64-bit integer parameter.
	ParameterInt64
	// ParameterUInt64 identifies an unsigned 64-bit integer parameter.
	ParameterUInt64
	// ParameterFloat64 identifies a 64-bit floating point parameter.
	ParameterFloat64
	// ParameterString identifies a UTF-8 string parameter.
	ParameterString
	// ParameterBinary identifies a binary parameter.
	ParameterBinary
	// ParameterDate identifies an Arrow Date32 parameter.
	ParameterDate
	// ParameterTime identifies an Arrow Time64 nanosecond parameter.
	ParameterTime
	// ParameterTimestamp identifies an Arrow timestamp parameter.
	ParameterTimestamp
	// ParameterDuration identifies an Arrow duration nanosecond parameter.
	ParameterDuration
	// ParameterDecimal identifies an Arrow Decimal128 parameter.
	ParameterDecimal
)

type SQLExecerContext

type SQLExecerContext interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

SQLExecerContext is implemented by *sql.DB, *sql.Conn, and *sql.Tx.

type Stmt

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

Stmt is a prepared DataFusion statement.

func (*Stmt) CheckNamedValue

func (s *Stmt) CheckNamedValue(nv *driver.NamedValue) error

CheckNamedValue normalizes DataFusion-specific parameter wrapper types.

func (*Stmt) Close

func (s *Stmt) Close() error

Close releases the native prepared statement handle.

func (*Stmt) Exec

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

Exec executes the statement with positional driver values.

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)

ExecContext executes the statement with normalized named values.

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

NumInput returns the number of SQL parameters found while preparing the statement.

func (*Stmt) Query

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Query executes the statement with positional driver values.

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

QueryContext executes the statement with normalized named values.

type Time

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

Time binds a parameter as an Arrow Time64 nanosecond value.

func NewTimeNanos

func NewTimeNanos(nanoseconds int64) (Time, error)

NewTimeNanos validates and returns a Time from nanoseconds since midnight.

func TimeFromTime

func TimeFromTime(t time.Time) Time

TimeFromTime returns a Time using only t's clock fields in t's location.

func TimeNanos

func TimeNanos(nanoseconds int64) Time

TimeNanos returns a Time from nanoseconds since midnight.

func (Time) Nanoseconds

func (value Time) Nanoseconds() int64

Nanoseconds returns the nanoseconds since midnight.

func (Time) Time

func (value Time) Time() time.Time

Time returns the clock value as a UTC time on the Unix epoch date.

type Timestamp

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

Timestamp binds a parameter as an Arrow timestamp with nanosecond precision.

func TimestampFromTime

func TimestampFromTime(t time.Time) Timestamp

TimestampFromTime returns a UTC timestamp parameter for t.

func TimestampWithTimeZone

func TimestampWithTimeZone(t time.Time, timeZone string) Timestamp

TimestampWithTimeZone returns a timestamp parameter with an explicit Arrow time zone string.

func (Timestamp) Time

func (value Timestamp) Time() time.Time

Time returns the timestamp value.

func (Timestamp) TimeZone

func (value Timestamp) TimeZone() string

TimeZone returns the Arrow timestamp timezone string.

type UInt64

type UInt64 uint64

UInt64 binds a parameter as an unsigned 64-bit integer.

func (UInt64) Uint64

func (value UInt64) Uint64() uint64

Uint64 returns the parameter value as a uint64.

Directories

Path Synopsis
examples
arrow command
parameters command
simple command
internal

Jump to

Keyboard shortcuts

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