bigquery

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package bigquery provides utilities for BigQuery operations including streaming inserts, table management, and query execution.

Index

Constants

This section is empty.

Variables

View Source
var StandardSchemas = struct {
	Telemetry bigquery.Schema
	Audit     bigquery.Schema
	Analytics bigquery.Schema
}{
	Telemetry: bigquery.Schema{
		{Name: "timestamp", Type: bigquery.TimestampFieldType, Required: true},
		{Name: "user_id", Type: bigquery.StringFieldType},
		{Name: "session_id", Type: bigquery.StringFieldType},
		{Name: "event_type", Type: bigquery.StringFieldType, Required: true},
		{Name: "event_data", Type: bigquery.JSONFieldType},
		{Name: "duration_ms", Type: bigquery.IntegerFieldType},
		{Name: "error", Type: bigquery.StringFieldType},
	},
	Audit: bigquery.Schema{
		{Name: "timestamp", Type: bigquery.TimestampFieldType, Required: true},
		{Name: "user_id", Type: bigquery.StringFieldType, Required: true},
		{Name: "action", Type: bigquery.StringFieldType, Required: true},
		{Name: "resource", Type: bigquery.StringFieldType},
		{Name: "result", Type: bigquery.StringFieldType},
		{Name: "ip_address", Type: bigquery.StringFieldType},
		{Name: "user_agent", Type: bigquery.StringFieldType},
	},
	Analytics: bigquery.Schema{
		{Name: "timestamp", Type: bigquery.TimestampFieldType, Required: true},
		{Name: "metric_name", Type: bigquery.StringFieldType, Required: true},
		{Name: "metric_value", Type: bigquery.FloatFieldType, Required: true},
		{Name: "dimensions", Type: bigquery.JSONFieldType},
		{Name: "user_id", Type: bigquery.StringFieldType},
		{Name: "session_id", Type: bigquery.StringFieldType},
	},
}

StandardSchemas provides common BigQuery schemas

Functions

func SchemaFromStruct

func SchemaFromStruct(v interface{}) (bigquery.Schema, error)

SchemaFromStruct generates a BigQuery schema from a struct The struct should have `bigquery` tags

Types

type Client

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

Client provides efficient BigQuery operations with lazy table creation

func NewClient

func NewClient(ctx context.Context, config Config) (*Client, error)

NewClient creates a new BigQuery client

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes the BigQuery client and flushes pending batches

func (*Client) GetDataset

func (c *Client) GetDataset() *bigquery.Dataset

GetDataset returns the dataset reference

func (*Client) GetTable

func (c *Client) GetTable(tableID string) *bigquery.Table

GetTable returns a table reference

func (*Client) InsertRow

func (c *Client) InsertRow(ctx context.Context, tableID string, row interface{}, schema bigquery.Schema) error

InsertRow inserts a single row into a BigQuery table

func (*Client) InsertRowAsync

func (c *Client) InsertRowAsync(tableID string, row interface{})

InsertRowAsync adds a row to the batch for async insertion

func (*Client) Query

func (c *Client) Query(ctx context.Context, sql string, params ...bigquery.QueryParameter) (*bigquery.RowIterator, error)

Query executes a BigQuery SQL query

type Config

type Config struct {
	ProjectID     string
	DatasetID     string
	BatchSize     int           // Number of rows to batch before inserting
	BatchInterval time.Duration // Max time to wait before flushing batch
}

Config contains configuration for BigQuery client

Jump to

Keyboard shortcuts

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