Documentation
¶
Overview ¶
Package bqsql runs a GoogleSQL subset on SQLite and converts BigQuery values between their REST encodings.
Index ¶
- Constants
- Variables
- func Cell(f Field, stored any) any
- func CellFor(f Field, stored any, o CellOptions) any
- func FormatFloat(f float64) string
- func FormatNumeric(f float64) string
- func FormatTemporal(k Kind, t time.Time) string
- func FromSQLite(f Field, v any) (any, error)
- func LogicalBytes(f Field, stored any) int64
- func NormalizeSchema(fs []Field) error
- func ParseRecord(fields []Field, obj map[string]any, o ParseOptions) ([]any, error)
- func ParseTemporal(k Kind, v any) (time.Time, error)
- func ParseValue(f Field, v any, o ParseOptions) (any, error)
- func Row(fields []Field, row []any) map[string]any
- func RowFor(fields []Field, row []any, o CellOptions) map[string]any
- func ToSQLite(f Field, stored any) driver.Value
- type Catalog
- type CellOptions
- type Column
- type Effect
- type ErrKind
- type Error
- type Field
- type Input
- type Kind
- type Param
- type ParseOptions
- type Query
- type Result
- type Statement
- type StmtKind
- type TableData
- type TableRef
- type Type
Constants ¶
const ( OpWrite = "WRITE" OpCreateTable = "CREATE_TABLE" OpCreateView = "CREATE_VIEW" OpCreateSchema = "CREATE_SCHEMA" OpDropTable = "DROP_TABLE" OpDropView = "DROP_VIEW" OpDropSchema = "DROP_SCHEMA" OpAlter = "ALTER" )
Effect operations.
const ( ModeNullable = "NULLABLE" ModeRequired = "REQUIRED" ModeRepeated = "REPEATED" )
Schema modes.
const ( TimestampLayout = "2006-01-02 15:04:05.000000" DateLayout = "2006-01-02" DatetimeLayout = "2006-01-02T15:04:05.000000" TimeLayout = "15:04:05.000000" )
Canonical stored encodings of temporal values.
Variables ¶
var ErrSchema = errors.New("invalid schema")
ErrSchema is wrapped by every schema validation failure.
var ErrSyntax = errors.New("syntax error")
ErrSyntax is wrapped by every parse failure.
var ErrValue = errors.New("invalid value")
ErrValue is wrapped by every value conversion failure.
Functions ¶
func CellFor ¶
func CellFor(f Field, stored any, o CellOptions) any
CellFor converts a stored value into the REST "v" encoding for f under o.
func FormatFloat ¶
FormatFloat renders f as the REST API does: shortest round-trip digits, with ".0" on whole numbers.
func FormatNumeric ¶
FormatNumeric renders f as a NUMERIC with scale 9 and no trailing zeros.
func FormatTemporal ¶
FormatTemporal renders t in the canonical stored encoding for k.
func FromSQLite ¶
FromSQLite converts a value read from SQLite into the stored form for f.
func LogicalBytes ¶
LogicalBytes estimates the logical storage size of a stored value the way BigQuery bills it.
func NormalizeSchema ¶
NormalizeSchema validates fs and rewrites type and mode names to their REST spellings.
func ParseRecord ¶
ParseRecord converts a JSON object into a positional record for fields.
func ParseTemporal ¶
ParseTemporal parses the many spellings BigQuery accepts for TIMESTAMP, DATE, DATETIME and TIME.
func ParseValue ¶
func ParseValue(f Field, v any, o ParseOptions) (any, error)
ParseValue converts a decoded JSON value into the stored form for f. Stored scalars are strings, records are positional []any and repeated fields are []any; NULL is nil.
Types ¶
type Catalog ¶
type Catalog interface {
Table(ref TableRef) (*TableData, bool)
DatasetExists(project, dataset string) bool
}
Catalog resolves tables for the compiler.
type CellOptions ¶
type CellOptions struct {
// Int64Timestamp renders TIMESTAMP cells as integer microseconds, as formatOptions.useInt64Timestamp requests.
Int64Timestamp bool
}
CellOptions tunes the REST cell encoding.
type Column ¶
Column is a named, typed struct member or relation column.
func FieldColumns ¶
FieldColumns converts schema fields into typed columns.
type Effect ¶
type Effect struct {
Options map[string]string
Ref TableRef
Op string
ViewQuery string
AlterOp string
Fields []Field
Rows [][]any
OrReplace bool
IfNotExist bool
IfExists bool
Cascade bool
}
Effect is a catalog change a statement asks the caller to apply.
type Error ¶
Error is a query analysis or execution failure.
type Field ¶
type Field struct {
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode,omitempty"`
Description string `json:"description,omitempty"`
MaxLength string `json:"maxLength,omitempty"`
Precision string `json:"precision,omitempty"`
Scale string `json:"scale,omitempty"`
Fields []Field `json:"fields,omitempty"`
}
Field is one schema column in the REST TableFieldSchema encoding.
func ColumnFields ¶
ColumnFields renders typed columns as schema fields.
type Kind ¶
type Kind uint8
Kind is a GoogleSQL type family.
const ( KindUnknown Kind = iota KindInt KindFloat KindBool KindString KindBytes KindTimestamp KindDate KindTime KindDatetime KindNumeric KindBigNumeric KindJSON KindGeography KindStruct KindArray )
Type kinds.
type Param ¶
Param is a query parameter; Name is empty for positional parameters and Value is in stored form.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a parsed SELECT statement, possibly with set operations, CTEs, ORDER BY and LIMIT.
type Result ¶
type Result struct {
Statement string
Fields []Field
Rows [][]any
Effects []Effect
Affected int64
Inserted int64
Updated int64
Deleted int64
Kind StmtKind
}
Result is the outcome of one statement.
type Statement ¶
Statement is one parsed GoogleSQL statement.
func ParseStatement ¶
ParseStatement parses a single GoogleSQL statement.
type StmtKind ¶
type StmtKind uint8
StmtKind classifies a parsed statement.