Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type ConfigProvider
- type DataOptions
- type Dataset
- type Handler
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) CancelJob(project, id string) (map[string]any, error)
- func (b *InMemoryBackend) CreateDataset(project string, body map[string]any) (map[string]any, error)
- func (b *InMemoryBackend) CreateTable(project, ds string, body map[string]any) (map[string]any, error)
- func (b *InMemoryBackend) DeleteDataset(project, id string, deleteContents bool) error
- func (b *InMemoryBackend) DeleteJob(project, id string) error
- func (b *InMemoryBackend) DeleteTable(project, ds, id string) error
- func (b *InMemoryBackend) GetDataset(project, id string) (map[string]any, error)
- func (b *InMemoryBackend) GetJob(project, id string) (map[string]any, error)
- func (b *InMemoryBackend) GetQueryResults(project, id string, o QueryResultOptions) (map[string]any, error)
- func (b *InMemoryBackend) GetTable(project, ds, id string) (map[string]any, error)
- func (b *InMemoryBackend) InsertAll(project, ds, id string, req InsertRequest) (map[string]any, error)
- func (b *InMemoryBackend) InsertJob(ctx context.Context, project string, body map[string]any, media []byte) (map[string]any, error)
- func (b *InMemoryBackend) ListData(project, ds, id string, o DataOptions) (map[string]any, error)
- func (b *InMemoryBackend) ListDatasets(project string, o ListOptions) page.Page[map[string]any]
- func (b *InMemoryBackend) ListJobs(project string, o JobListOptions) page.Page[map[string]any]
- func (b *InMemoryBackend) ListProjects() []map[string]any
- func (b *InMemoryBackend) ListTables(project, ds string, o ListOptions) (page.Page[map[string]any], error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) RunQuery(ctx context.Context, project string, req map[string]any) (map[string]any, error)
- func (b *InMemoryBackend) SetObjectStore(s ObjectStore)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) UpdateDataset(project, id string, body map[string]any, replace bool) (map[string]any, error)
- func (b *InMemoryBackend) UpdateTable(project, ds, id string, body map[string]any, replace bool) (map[string]any, error)
- type InsertRequest
- type InsertRow
- type Job
- type JobListOptions
- type ListOptions
- type ObjectStore
- type Provider
- type QueryResultOptions
- type Settings
- type Table
Constants ¶
const DefaultPort = 9050
DefaultPort is the dedicated listener's default TCP port.
Variables ¶
var ErrNilAppContext = errors.New("gcpbigquery: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
var ErrObjectNotFound = errors.New("object not found")
ErrObjectNotFound is returned by an ObjectStore when a bucket or object does not exist.
var ErrSnapshotNull = errors.New("gcpbigquery: snapshot contains a null dataset")
ErrSnapshotNull is returned when a snapshot holds a null dataset.
Functions ¶
This section is empty.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPBigQuerySettings() Settings
}
ConfigProvider extracts BigQuery configuration from the AppContext Config.
type DataOptions ¶
type DataOptions struct {
PageToken string
SelectedFields string
StartIndex int
Max int
Int64Timestamp bool
}
DataOptions are the tabledata.list parameters.
type Dataset ¶
type Dataset struct {
Meta map[string]any `json:"meta"`
Tables map[string]*Table `json:"tables"`
Location string `json:"location"`
Created int64 `json:"created"`
Modified int64 `json:"modified"`
Hidden bool `json:"hidden,omitempty"`
}
Dataset is a BigQuery dataset. Meta holds the writable passthrough fields (labels, access, description, ...).
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
// contains filtered or unexported fields
}
Handler serves the BigQuery v2 REST API.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name for metrics.
func (*Handler) ExtractResource ¶
ExtractResource returns project[/dataset[.table]] for metrics.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler for all BigQuery requests.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: BigQuery runs on its own listener.
func (*Handler) Shutdown ¶
Shutdown stops the dedicated listener, forcing a close if graceful shutdown fails.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds every dataset, table, row and job under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend.
func (*InMemoryBackend) CancelJob ¶
func (b *InMemoryBackend) CancelJob(project, id string) (map[string]any, error)
CancelJob implements jobs.cancel; every job finishes inside the insert call so this reports the final job.
func (*InMemoryBackend) CreateDataset ¶
func (b *InMemoryBackend) CreateDataset(project string, body map[string]any) (map[string]any, error)
CreateDataset implements datasets.insert.
func (*InMemoryBackend) CreateTable ¶
func (b *InMemoryBackend) CreateTable(project, ds string, body map[string]any) (map[string]any, error)
CreateTable implements tables.insert.
func (*InMemoryBackend) DeleteDataset ¶
func (b *InMemoryBackend) DeleteDataset(project, id string, deleteContents bool) error
DeleteDataset implements datasets.delete.
func (*InMemoryBackend) DeleteJob ¶
func (b *InMemoryBackend) DeleteJob(project, id string) error
DeleteJob implements jobs.delete.
func (*InMemoryBackend) DeleteTable ¶
func (b *InMemoryBackend) DeleteTable(project, ds, id string) error
DeleteTable implements tables.delete.
func (*InMemoryBackend) GetDataset ¶
func (b *InMemoryBackend) GetDataset(project, id string) (map[string]any, error)
GetDataset implements datasets.get.
func (*InMemoryBackend) GetJob ¶
func (b *InMemoryBackend) GetJob(project, id string) (map[string]any, error)
GetJob implements jobs.get.
func (*InMemoryBackend) GetQueryResults ¶
func (b *InMemoryBackend) GetQueryResults(project, id string, o QueryResultOptions) (map[string]any, error)
GetQueryResults implements jobs.getQueryResults.
func (*InMemoryBackend) GetTable ¶
func (b *InMemoryBackend) GetTable(project, ds, id string) (map[string]any, error)
GetTable implements tables.get.
func (*InMemoryBackend) InsertAll ¶
func (b *InMemoryBackend) InsertAll(project, ds, id string, req InsertRequest) (map[string]any, error)
InsertAll implements tabledata.insertAll.
func (*InMemoryBackend) InsertJob ¶
func (b *InMemoryBackend) InsertJob( ctx context.Context, project string, body map[string]any, media []byte, ) (map[string]any, error)
InsertJob implements jobs.insert; media carries the body of a multipart or resumable upload for load jobs.
func (*InMemoryBackend) ListData ¶
func (b *InMemoryBackend) ListData(project, ds, id string, o DataOptions) (map[string]any, error)
ListData implements tabledata.list.
func (*InMemoryBackend) ListDatasets ¶
func (b *InMemoryBackend) ListDatasets(project string, o ListOptions) page.Page[map[string]any]
ListDatasets implements datasets.list.
func (*InMemoryBackend) ListJobs ¶
func (b *InMemoryBackend) ListJobs(project string, o JobListOptions) page.Page[map[string]any]
ListJobs implements jobs.list, newest first.
func (*InMemoryBackend) ListProjects ¶
func (b *InMemoryBackend) ListProjects() []map[string]any
ListProjects implements projects.list over every project that owns a dataset or a job.
func (*InMemoryBackend) ListTables ¶
func (b *InMemoryBackend) ListTables(project, ds string, o ListOptions) (page.Page[map[string]any], error)
ListTables implements tables.list.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads backend state from a snapshot.
func (*InMemoryBackend) RunQuery ¶
func (b *InMemoryBackend) RunQuery(ctx context.Context, project string, req map[string]any) (map[string]any, error)
RunQuery implements jobs.query: it creates a query job, runs it and returns the first page of results.
func (*InMemoryBackend) SetObjectStore ¶
func (b *InMemoryBackend) SetObjectStore(s ObjectStore)
SetObjectStore wires the object store load and extract jobs read from and write to.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises the backend state.
func (*InMemoryBackend) UpdateDataset ¶
func (b *InMemoryBackend) UpdateDataset(project, id string, body map[string]any, replace bool) (map[string]any, error)
UpdateDataset implements datasets.patch (merge) and datasets.update (replace).
func (*InMemoryBackend) UpdateTable ¶
func (b *InMemoryBackend) UpdateTable( project, ds, id string, body map[string]any, replace bool, ) (map[string]any, error)
UpdateTable implements tables.patch (merge) and tables.update (replace).
type InsertRequest ¶
type InsertRequest struct {
Rows []InsertRow `json:"rows"`
SkipInvalidRows bool `json:"skipInvalidRows"`
IgnoreUnknownValues bool `json:"ignoreUnknownValues"`
}
InsertRequest is the tabledata.insertAll request body.
type Job ¶
type Job struct {
Config map[string]any `json:"config"`
Stats map[string]any `json:"stats"`
ErrorResult *jobError `json:"errorResult,omitempty"`
Dest *tableRef `json:"dest,omitempty"`
Project string `json:"project"`
ID string `json:"id"`
Location string `json:"location"`
Type string `json:"type"`
State string `json:"state"`
User string `json:"user"`
Schema []bqsql.Field `json:"schema,omitempty"`
Rows [][]any `json:"rows,omitempty"`
Created int64 `json:"created"`
Started int64 `json:"started"`
Ended int64 `json:"ended"`
NumDML int64 `json:"numDml"`
DryRun bool `json:"dryRun,omitempty"`
HasResult bool `json:"hasResult,omitempty"`
}
Job is a BigQuery job. Query jobs keep their result rows so getQueryResults can page them.
type JobListOptions ¶
type JobListOptions struct {
PageToken string
StateFilter []string
MinCreated int64
MaxCreated int64
Max int
}
JobListOptions are the jobs.list parameters.
type ListOptions ¶
ListOptions carries the paging parameters shared by list calls.
type ObjectStore ¶
type ObjectStore interface {
// ListObjects returns the names of every object in bucket that starts with prefix.
ListObjects(bucket, prefix string) ([]string, error)
// ReadObject returns the content of one object.
ReadObject(bucket, name string) ([]byte, error)
// WriteObject creates or replaces one object.
WriteObject(bucket, name string, data []byte, contentType string) error
}
ObjectStore is the slice of Cloud Storage that load and extract jobs need.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Google BigQuery. It serves the REST API on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type QueryResultOptions ¶
QueryResultOptions are the getQueryResults parameters.
type Settings ¶
type Settings struct {
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 164-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPBigQuery.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
type Table ¶
type Table struct {
Meta map[string]any `json:"meta"`
Seen map[string]int64 `json:"seen,omitempty"`
ViewQuery string `json:"viewQuery,omitempty"`
Schema []bqsql.Field `json:"schema"`
Rows [][]any `json:"rows"`
Created int64 `json:"created"`
Modified int64 `json:"modified"`
Seq int64 `json:"seq"`
}
Table is a table or view with its rows in the canonical stored encoding.