bq

package
v0.0.0-...-5597880 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExist    = errors.New("already exists")
	ErrNotExist = errors.New("not exists")
)

Functions

func DatasetNameWithRandomPostfix

func DatasetNameWithRandomPostfix(name string) string

Generate unique name for dataset: - https://cloud.google.com/bigquery/docs/datasets#dataset-naming

Types

type AccessEntry

type AccessEntry struct {
	Role       AccessRole
	EntityType EntityType
	Entity     string
	View       *View
}

func (AccessEntry) Validate

func (a AccessEntry) Validate() error

type AccessRole

type AccessRole string

AccessRole is the level of access to grant to a dataset.

const (
	// OwnerRole is the OWNER AccessRole.
	OwnerRole AccessRole = "OWNER"
	// ReaderRole is the READER AccessRole.
	ReaderRole AccessRole = "READER"
	// WriterRole is the WRITER AccessRole.
	WriterRole AccessRole = "WRITER"

	BigQueryMetadataViewerRole AccessRole = "roles/bigquery.metadataViewer"
	BigQueryDataViewerRole     AccessRole = "roles/bigquery.dataViewer"
)

func (AccessRole) String

func (r AccessRole) String() string

type Client

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

func NewClient

func NewClient(endpoint string, enableAuthentication bool, log zerolog.Logger) *Client

func (*Client) AddAndSetTablePolicy

func (c *Client) AddAndSetTablePolicy(ctx context.Context, projectID, datasetID, tableID, role, member string) error

func (*Client) AddDatasetRoleAccessEntry

func (c *Client) AddDatasetRoleAccessEntry(ctx context.Context, projectID, datasetID string, input *AccessEntry) error

func (*Client) AddDatasetViewAccessEntry

func (c *Client) AddDatasetViewAccessEntry(ctx context.Context, projectID, datasetID string, input *View) error

func (*Client) CreateDataset

func (c *Client) CreateDataset(ctx context.Context, projectID, datasetID, region string) error

func (*Client) CreateDatasetIfNotExists

func (c *Client) CreateDatasetIfNotExists(ctx context.Context, projectID, datasetID, region string) error

func (*Client) CreateTable

func (c *Client) CreateTable(ctx context.Context, input *Table) error

func (*Client) CreateTableOrUpdate

func (c *Client) CreateTableOrUpdate(ctx context.Context, input *Table) (*Table, error)

func (*Client) DeleteDataset

func (c *Client) DeleteDataset(ctx context.Context, project, datasetID string, deleteContents bool) error

func (*Client) DeleteTable

func (c *Client) DeleteTable(ctx context.Context, project, datasetID, tableID string) error

func (*Client) GetDataset

func (c *Client) GetDataset(ctx context.Context, projectID, datasetID string) (*Dataset, error)

func (*Client) GetDatasets

func (c *Client) GetDatasets(ctx context.Context, projectID string) ([]*Dataset, error)

func (*Client) GetTable

func (c *Client) GetTable(ctx context.Context, projectID, datasetID, tableID string) (*Table, error)

func (*Client) GetTables

func (c *Client) GetTables(ctx context.Context, projectID, datasetID string) ([]*Table, error)

func (*Client) QueryAndWait

func (c *Client) QueryAndWait(ctx context.Context, projectID, query string) (*JobStatistics, error)

func (*Client) RemoveAndSetTablePolicy

func (c *Client) RemoveAndSetTablePolicy(ctx context.Context, projectID, datasetID, tableID, role, member string) error

type Column

type Column struct {
	Name        string
	Type        FieldType
	Mode        ColumnMode
	Description string
}

func (Column) Validate

func (c Column) Validate() error

type ColumnMode

type ColumnMode string
const (
	NullableMode ColumnMode = "NULLABLE"
	RequiredMode ColumnMode = "REQUIRED"
	RepeatedMode ColumnMode = "REPEATED"
)

func (*ColumnMode) String

func (c *ColumnMode) String() string

type Dataset

type Dataset struct {
	ProjectID string
	DatasetID string

	Name        string
	Description string

	Access []*AccessEntry
}

type EntityType

type EntityType string
const (
	UserEmailEntity  EntityType = "user"
	GroupEmailEntity EntityType = "group"
	ViewEntity       EntityType = "view"
)

func (EntityType) String

func (e EntityType) String() string

type FieldType

type FieldType string
const (
	// StringFieldType is a string field type.
	StringFieldType FieldType = "STRING"
	// BytesFieldType is a bytes field type.
	BytesFieldType FieldType = "BYTES"
	// IntegerFieldType is a integer field type.
	IntegerFieldType FieldType = "INTEGER"
	// FloatFieldType is a float field type.
	FloatFieldType FieldType = "FLOAT"
	// BooleanFieldType is a boolean field type.
	BooleanFieldType FieldType = "BOOLEAN"
	// TimestampFieldType is a timestamp field type.
	TimestampFieldType FieldType = "TIMESTAMP"
	// RecordFieldType is a record field type. It is typically used to create columns with repeated or nested data.
	RecordFieldType FieldType = "RECORD"
	// DateFieldType is a date field type.
	DateFieldType FieldType = "DATE"
	// TimeFieldType is a time field type.
	TimeFieldType FieldType = "TIME"
	// DateTimeFieldType is a datetime field type.
	DateTimeFieldType FieldType = "DATETIME"
	// NumericFieldType is a numeric field type. Numeric types include integer types, floating point types and the
	// NUMERIC data type.
	NumericFieldType FieldType = "NUMERIC"
	// GeographyFieldType is a string field type.  Geography types represent a set of points
	// on the Earth's surface, represented in Well Known Text (WKT) format.
	GeographyFieldType FieldType = "GEOGRAPHY"
	// BigNumericFieldType is a numeric field type that supports values of larger precision
	// and scale than the NumericFieldType.
	BigNumericFieldType FieldType = "BIGNUMERIC"
	// IntervalFieldType is a representation of a duration or an amount of time.
	IntervalFieldType FieldType = "INTERVAL"
	// JSONFieldType is a representation of a json object.
	JSONFieldType FieldType = "JSON"
	// RangeFieldType represents a continuous range of values.
	RangeFieldType FieldType = "RANGE"
)

func (*FieldType) String

func (f *FieldType) String() string

type JobStatistics

type JobStatistics struct {
	CreationTime        time.Time
	StartTime           time.Time
	EndTime             time.Time
	TotalBytesProcessed int64
}

type Operations

type Operations interface {
	GetDataset(ctx context.Context, projectID, datasetID string) (*Dataset, error)
	GetDatasets(ctx context.Context, projectID string) ([]*Dataset, error)
	GetTable(ctx context.Context, projectID, datasetID, tableID string) (*Table, error)
	GetTables(ctx context.Context, projectID, datasetID string) ([]*Table, error)
	CreateDataset(ctx context.Context, projectID, datasetID, region string) error
	CreateDatasetIfNotExists(ctx context.Context, projectID, datasetID, region string) error
	CreateTable(ctx context.Context, input *Table) error
	CreateTableOrUpdate(ctx context.Context, input *Table) (*Table, error)
	DeleteTable(ctx context.Context, projectID, datasetID, tableID string) error
	DeleteDataset(ctx context.Context, projectID, datasetID string, deleteContents bool) error
	QueryAndWait(ctx context.Context, projectID, query string) (*JobStatistics, error)
	AddDatasetRoleAccessEntry(ctx context.Context, projectID, datasetID string, input *AccessEntry) error
	AddDatasetViewAccessEntry(ctx context.Context, projectID, datasetID string, view *View) error
	AddAndSetTablePolicy(ctx context.Context, projectID, datasetID, tableID, role, member string) error
	RemoveAndSetTablePolicy(ctx context.Context, projectID, datasetID, tableID, role, member string) error
}

type Table

type Table struct {
	ProjectID string
	DatasetID string
	TableID   string
	Location  string

	Name        string
	Description string
	Type        TableType

	// The table schema. If provided on create, ViewQuery must be empty.
	Schema []*Column

	// The query to use for a logical view. If provided on create, Schema must be nil.
	ViewQuery string

	LastModified time.Time
	Created      time.Time
	Expires      time.Time
	// contains filtered or unexported fields
}

func (Table) Validate

func (t Table) Validate() error

type TableType

type TableType string
const (
	// RegularTable is a regular table.
	RegularTable TableType = "TABLE"
	// ViewTable is a table type describing that the table is a logical view.
	// See more information at https://cloud.google.com//docs/views.
	ViewTable TableType = "VIEW"
	// ExternalTable is a table type describing that the table is an external
	// table (also known as a federated data source). See more information at
	// https://cloud.google.com/bigquery/external-data-sources.
	ExternalTable TableType = "EXTERNAL"
	// MaterializedView represents a managed storage table that's derived from
	// a base table.
	MaterializedView TableType = "MATERIALIZED_VIEW"
	// Snapshot represents an immutable point in time snapshot of some other
	// table.
	Snapshot TableType = "SNAPSHOT"
)

func (*TableType) String

func (t *TableType) String() string

type View

type View struct {
	ProjectID string
	DatasetID string
	TableID   string
}

func (View) Validate

func (v View) Validate() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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