athena

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package athena implements warehouse.Source for Amazon Athena (Trino SQL) with the AWS SDK for Go v2.

A query is submitted with StartQueryExecution (workgroup, database, catalog, output location and "?" parameters as ExecutionParameters), polled with GetQueryExecution using exponential backoff until it SUCCEEDS, FAILS or is CANCELLED, and read with paginated GetQueryResults. When the caller's context ends first the query is stopped with StopQueryExecution so it does not keep scanning (and billing). Credentials and region come from the default AWS chain; region in the source config takes precedence.

Parameters are sent as SQL literals (Athena substitutes them server-side): strings are single-quoted with quotes doubled, numbers and booleans are written verbatim, nil becomes NULL.

Result values are converted from Athena's textual results using the column types in ResultSetMetadata:

boolean                        → bool
tinyint/smallint/integer/bigint → int64
real/float/double              → float64 ("NaN"/"Infinity"/"-Infinity" strings)
decimal                        → float64 when lossless, else the exact decimal string
timestamp [with time zone]     → RFC 3339 string with nanoseconds, UTC
date                           → "YYYY-MM-DD"
varbinary                      → base64 string
json                           → decoded value
everything else                → string (array, map and row values keep
                                 Athena's display format; CAST them to JSON
                                 for structured values)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertValue

func ConvertValue(typ, s string) any

ConvertValue converts Athena's textual rendering s of a value of type typ (as reported in ColumnInfo.Type) to a JSON-friendly value. Values that do not parse as their declared type are returned as strings.

func Literal

func Literal(v any) (string, error)

Literal renders a JSON scalar as an Athena (Trino) SQL literal for ExecutionParameters. Strings are single-quoted with embedded quotes doubled (Trino strings have no backslash escapes), so a value can never leave its literal. Literals longer than Athena's 1024-character limit are rejected.

Types

type API

type API interface {
	StartQueryExecution(ctx context.Context, in *sdk.StartQueryExecutionInput, optFns ...func(*sdk.Options)) (*sdk.StartQueryExecutionOutput, error)
	GetQueryExecution(ctx context.Context, in *sdk.GetQueryExecutionInput, optFns ...func(*sdk.Options)) (*sdk.GetQueryExecutionOutput, error)
	GetQueryResults(ctx context.Context, in *sdk.GetQueryResultsInput, optFns ...func(*sdk.Options)) (*sdk.GetQueryResultsOutput, error)
	StopQueryExecution(ctx context.Context, in *sdk.StopQueryExecutionInput, optFns ...func(*sdk.Options)) (*sdk.StopQueryExecutionOutput, error)
}

API is the subset of the Athena client used by Source.

type Options

type Options struct {
	// Logger receives warnings (default slog.Default()).
	Logger *slog.Logger
	// Client replaces the SDK client entirely (tests, custom middleware).
	Client API
	// AWSConfig replaces config.LoadDefaultConfig (custom credential
	// chains). The source's region still takes precedence.
	AWSConfig *aws.Config
	// Endpoint overrides the Athena endpoint URL (VPC endpoints, tests).
	Endpoint string
	// PollInterval is the first GetQueryExecution delay (default 250ms);
	// it grows by 1.5× up to MaxPollInterval (default 2s).
	PollInterval    time.Duration
	MaxPollInterval time.Duration
}

Options are optional settings.

type Source

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

Source is a warehouse.Source backed by Athena. It is safe for concurrent use.

func New

func New(ctx context.Context, name string, src config.WarehouseSource, opts Options) (*Source, error)

New creates an Athena source. Loading the AWS configuration reads only local sources (environment, shared files); credentials are resolved per request.

func (*Source) Close

func (s *Source) Close() error

Close is a no-op: the SDK client holds no resources that need releasing.

func (*Source) Placeholder

func (s *Source) Placeholder(int) string

Placeholder returns "?" (Athena execution parameters).

func (*Source) Query

func (s *Source) Query(ctx context.Context, sql string, args []any, lim warehouse.Limits) (*warehouse.Result, error)

Query runs sql and returns the rows that fit within lim. No further pages are fetched once the size cap is reached.

Jump to

Keyboard shortcuts

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