view

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// LastAddedID is used in place of ID fields (e.g. schema, version) to indicate that
	// the last added instance of that type should be used.
	LastAddedID      = -1
	InitialVersionID = 1

	SupportedViewFormatVersion = 1
	DefaultViewFormatVersion   = SupportedViewFormatVersion
)
View Source
const (
	// ReplaceDropDialectAllowedKey is a view metadata property
	// indicating whether replacing a version while dropping a dialect is allowed.
	ReplaceDropDialectAllowedKey     = "replace.drop-dialect.allowed"
	ReplaceDropDialectAllowedDefault = false

	// VersionHistorySizeKey is a view metadata property which governs how many
	// view versions are retained.
	VersionHistorySizeKey     = "version.history.num-entries"
	VersionHistorySizeDefault = 10
)
View Source
const (
	UpdateAddSchema      = "add-schema"
	UpdateAddViewVersion = "add-view-version"

	UpdateAssignUUID = "assign-uuid"

	UpdateRemoveProperties = "remove-properties"

	UpdateSetCurrentViewVersion = "set-current-view-version"
	UpdateSetLocation           = "set-location"
	UpdateSetProperties         = "set-properties"

	UpdateUpgradeFormatVersion = "upgrade-format-version"
)

These are the various update actions defined in the iceberg spec

Variables

View Source
var (
	ErrInvalidViewMetadata              = errors.New("invalid view metadata")
	ErrInvalidViewMetadataFormatVersion = errors.New("invalid or missing format-version in view metadata")
)

Functions

func NewAddSchemaUpdate

func NewAddSchemaUpdate(schema *iceberg.Schema) *addSchemaUpdate

NewAddSchemaUpdate creates a new update that adds the given schema and updates the lastColumnID based on the schema.

func NewAddViewVersionUpdate

func NewAddViewVersionUpdate(version *Version) *addViewVersionUpdate

NewAddViewVersionUpdate creates a new ViewUpdate that adds a version to a view

func NewAssignUUIDUpdate

func NewAssignUUIDUpdate(uuid uuid.UUID) *assignUUIDUpdate

NewAssignUUIDUpdate creates a new update to assign a UUID to the table metadata.

func NewRemovePropertiesUpdate

func NewRemovePropertiesUpdate(removals []string) *removePropertiesUpdate

NewRemovePropertiesUpdate creates a new update that removes properties from the view metadata. The properties are identified by their names, and if a property with the given name does not exist, it is ignored.

func NewSetCurrentVersionUpdate

func NewSetCurrentVersionUpdate(id int64) *setCurrentViewVersionUpdate

NewSetCurrentVersionUpdate creates a new ViewUpdate that sets the current version of a view to the given version ID.

func NewSetLocationUpdate

func NewSetLocationUpdate(loc string) *setLocationUpdate

NewSetLocationUpdate creates a new update that sets the location of the view metadata.

func NewSetPropertiesUpdate

func NewSetPropertiesUpdate(updates iceberg.Properties) *setPropertiesUpdate

NewSetPropertiesUpdate creates a new update that sets the given properties in the view metadata.

func NewUpgradeFormatVersionUpdate

func NewUpgradeFormatVersionUpdate(formatVersion int) *upgradeFormatVersionUpdate

NewUpgradeFormatVersionUpdate creates a new update that upgrades the format version of the view metadata to the given formatVersion.

func WithDefaultViewCatalog

func WithDefaultViewCatalog(catalogName string) func(*Version)

func WriteMetadata added in v0.8.0

func WriteMetadata(ctx context.Context, metadata Metadata, ioProps iceberg.Properties, opts ...MetadataIOOption) (string, icebergio.WriteFileIO, error)

WriteMetadata writes a new view metadata file and returns its location and filesystem. The directory comes from table.WriteMetadataPathKey, or defaults to <view location>/metadata. Each file has a fresh view-<uuid>.metadata.json name. ioProps configures the filesystem and is not persisted in the metadata.

Failed writes and closes remove the incomplete file without inheriting cancellation. After a successful write, the caller owns publication and may use the returned filesystem to remove the file after a confirmed failed commit. A commit with an unknown outcome must retain the file. WithIORegistry selects an isolated filesystem for this write.

Types

type Metadata

type Metadata interface {
	// FormatVersion indicates the version of this metadata, 1 for V1
	FormatVersion() int
	// ViewUUID returns a UUID that identifies the view, generated when the
	// view is created. Implementations must throw an exception if a view's
	// UUID does not match the expected UUID after refreshing metadata.
	ViewUUID() uuid.UUID
	// Location is the table's base location. This is used by writers to determine
	// where to store data files, manifest files, and table metadata files.
	Location() string
	// Schemas returns the list of view schemas
	Schemas() []*iceberg.Schema
	// CurrentVersionID returns the ID of the current version of the view (version-id)
	CurrentVersionID() int64
	// CurrentVersion returns the current version of the view
	CurrentVersion() *Version
	// CurrentSchemaID returns the ID of the current schema
	CurrentSchemaID() int
	// CurrentSchema returns the current schema of the view
	CurrentSchema() *iceberg.Schema
	// SchemasByID returns a map of schema IDs to schemas
	SchemasByID() map[int]*iceberg.Schema
	// Versions returns the list of view versions
	Versions() []*Version
	// VersionLog returns a list of version log entries
	// with the timestamp and version-id for every change to current-version-id
	VersionLog() []VersionLogEntry
	// Properties is a string to string map of view properties.
	Properties() iceberg.Properties

	Equals(Metadata) bool
}

Metadata for an iceberg view as specified in the Iceberg spec https://iceberg.apache.org/view-spec/

func NewMetadata

func NewMetadata(version *Version, sc *iceberg.Schema, location string, props iceberg.Properties) (Metadata, error)

NewMetadata creates a new view metadata object using the provided version, schema, location, and props, generating a fresh UUID for the new table metadata.

func NewMetadataWithUUID

func NewMetadataWithUUID(version *Version, sc *iceberg.Schema, location string, props iceberg.Properties, viewUUID uuid.UUID) (Metadata, error)

NewMetadataWithUUID is like NewMetadata, but allows the caller to specify the UUID of the view rather than creating a new one.

func ParseMetadata

func ParseMetadata(r io.Reader) (Metadata, error)

ParseMetadata parses json metadata provided by the passed in reader, returning an error if one is encountered.

func ParseMetadataBytes

func ParseMetadataBytes(b []byte) (Metadata, error)

ParseMetadataBytes is like ParseMetadataString but for a byte slice.

func ParseMetadataString

func ParseMetadataString(s string) (Metadata, error)

ParseMetadataString is like ParseMetadata, but for a string rather than an io.Reader.

type MetadataBuildResult

type MetadataBuildResult struct {
	Metadata
	Changes Updates
}

MetadataBuildResult is returned by a successful Build() command This type contains the resulting view metadata from a build, as well as the logical updates performed to generate it

func (*MetadataBuildResult) MarshalJSON

func (m *MetadataBuildResult) MarshalJSON() ([]byte, error)

type MetadataBuilder

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

func MetadataBuilderFromBase

func MetadataBuilderFromBase(metadata Metadata) (*MetadataBuilder, error)

func NewMetadataBuilder

func NewMetadataBuilder() *MetadataBuilder

NewMetadataBuilder creates a builder for new view metadata.

func (*MetadataBuilder) AddSchema

func (b *MetadataBuilder) AddSchema(schema *iceberg.Schema) *MetadataBuilder

func (*MetadataBuilder) AddVersion

func (b *MetadataBuilder) AddVersion(newVersion *Version) *MetadataBuilder

func (*MetadataBuilder) Build

func (b *MetadataBuilder) Build() (*MetadataBuildResult, error)

Build builds the view metadata and updates from the builder

func (*MetadataBuilder) Err

func (b *MetadataBuilder) Err() error

func (*MetadataBuilder) HasChanges

func (b *MetadataBuilder) HasChanges() bool

func (*MetadataBuilder) RemoveProperties

func (b *MetadataBuilder) RemoveProperties(keys []string) *MetadataBuilder

func (*MetadataBuilder) SetCurrentVersion

func (b *MetadataBuilder) SetCurrentVersion(version *Version, schema *iceberg.Schema) *MetadataBuilder

func (*MetadataBuilder) SetCurrentVersionID

func (b *MetadataBuilder) SetCurrentVersionID(newVersionID int64) *MetadataBuilder

func (*MetadataBuilder) SetFormatVersion

func (b *MetadataBuilder) SetFormatVersion(formatVersion int) *MetadataBuilder

func (*MetadataBuilder) SetLoc

func (b *MetadataBuilder) SetLoc(loc string) *MetadataBuilder

func (*MetadataBuilder) SetProperties

func (b *MetadataBuilder) SetProperties(props iceberg.Properties) *MetadataBuilder

func (*MetadataBuilder) SetUUID

func (b *MetadataBuilder) SetUUID(newUUID uuid.UUID) *MetadataBuilder

type MetadataIOOption added in v0.8.0

type MetadataIOOption func(*metadataIOOptions)

MetadataIOOption configures the filesystem used to write view metadata. This is distinct from Option, which configures a loaded View.

func WithIORegistry added in v0.8.0

func WithIORegistry(registry *icebergio.Registry) MetadataIOOption

WithIORegistry uses a catalog-scoped FileIO registry to write view metadata. A nil registry uses the process-wide default. The registry is shared, not copied.

type Option added in v0.8.0

type Option func(*View)

Option configures a View at construction.

func WithLabels added in v0.8.0

func WithLabels(l *iceberg.Labels) Option

WithLabels attaches catalog-provided labels from a load response to the view. A nil value is ignored, leaving the view's labels nil.

type Representation

type Representation struct {
	// Must be sql
	Type string `json:"type"`
	// A SQL SELECT statement
	SQL string `json:"sql"`
	// The dialect of the sql SELECT statement (e.g., "trino" or "spark")
	Dialect string `json:"dialect"`
}

Representation is a struct containing information about a view's representation https://iceberg.apache.org/view-spec/#sql-representation

func NewRepresentation

func NewRepresentation(repr Representation) Representation

NewRepresentation creates a SQL view representation from named fields. The SQL and Dialect fields are validated by NewVersion.

type Representations

type Representations []Representation

type Requirement

type Requirement interface {
	// Validate checks that the current view metadata satisfies the requirement.
	Validate(Metadata) error
	GetType() string
}

A Requirement is a validation rule that must be satisfied before attempting to make and commit changes to a table. Requirements are used to ensure that the view is in a valid state before making changes.

func AssertViewUUID

func AssertViewUUID(uuid uuid.UUID) Requirement

AssertViewUUID creates a requirement that the table UUID matches the given UUID.

func ParseRequirement

func ParseRequirement(r io.Reader) (Requirement, error)

ParseRequirement parses json data provided by the reader into a Requirement

func ParseRequirementBytes

func ParseRequirementBytes(b []byte) (Requirement, error)

ParseRequirementBytes parses json bytes into a Requirement

func ParseRequirementString

func ParseRequirementString(s string) (Requirement, error)

ParseRequirementString parses json string into a Requirement

type Requirements

type Requirements []Requirement

func (*Requirements) UnmarshalJSON

func (r *Requirements) UnmarshalJSON(data []byte) error

type Update

type Update interface {
	// Action returns the name of the action that the update represents.
	Action() string
	// Apply applies the update to the given view metadata builder.
	Apply(viewBuilder *MetadataBuilder) error
}

Update represents a change to a view's metadata.

type Updates

type Updates []Update

func (*Updates) UnmarshalJSON

func (u *Updates) UnmarshalJSON(data []byte) error

type Version

type Version struct {
	// ID for the version
	VersionID int64 `json:"version-id"`
	// ID of the schema for the view version
	SchemaID int `json:"schema-id"`
	// Timestamp when the version was created (ms from epoch)
	TimestampMS int64 `json:"timestamp-ms"`
	// A string to string map of summary metadata about the version
	Summary VersionSummary `json:"summary"`
	// A list of representations for the view definition
	Representations []Representation `json:"representations"`
	// The default view namespace (as a list of strings)
	DefaultNamespace table.Identifier `json:"default-namespace"`
	// An (optional) default catalog name for querying the view
	DefaultCatalog string `json:"default-catalog,omitempty"`
}

func NewVersion

func NewVersion(id int64, schemaID int, representations []Representation, defaultNS table.Identifier, opts ...VersionOpt) (*Version, error)

NewVersion creates a Version instance from the provided parameters. It copies the representations and namespace so later changes to the inputs cannot modify the returned version. If building updates using the MetadataBuilder, and one desires to use the last added schema ID, one should use the LastAddedID constant as the provided schemaID

Note that NewVersion automatically seeds TimestampMS to time.Now().UnixMilli(), and one should use the option WithTimestampMS to override this behavior.

func NewVersionFromSQL

func NewVersionFromSQL(id int64, schemaID int, representation Representation, defaultNS table.Identifier, opts ...VersionOpt) (*Version, error)

NewVersionFromSQL creates a new Version with one SQL representation. SQL and dialect are passed as named fields to avoid swapping them.

func (*Version) Clone

func (v *Version) Clone() *Version

func (*Version) Equals

func (v *Version) Equals(other *Version) bool

Equals checks whether the other Version would behave the same while ignoring the view version id, and the creation timestamp

func (Version) MarshalJSON added in v0.8.0

func (v Version) MarshalJSON() ([]byte, error)

MarshalJSON writes a nil DefaultNamespace as an empty list because the spec requires the field.

type VersionLogEntry

type VersionLogEntry struct {
	// Timestamp when the view's current-version-id was updated (ms from epoch)
	TimestampMS int64 `json:"timestamp-ms"`
	// ID that current-version-id was set to
	VersionID int64 `json:"version-id"`
}

type VersionOpt

type VersionOpt func(*Version)

func WithTimestampMS

func WithTimestampMS(timestampMS int64) VersionOpt

func WithVersionSummary

func WithVersionSummary(summary VersionSummary) VersionOpt

type VersionSummary

type VersionSummary map[string]string

VersionSummary is string to string map of summary metadata about a view's version

type View

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

func CreateView

func CreateView(
	ctx context.Context,
	catalogName string,
	viewIdent table.Identifier,
	schema *iceberg.Schema,
	representation Representation,
	defaultNS table.Identifier,
	loc string,
	props iceberg.Properties,
	opts ...MetadataIOOption,
) (*View, error)

CreateView creates a new view metadata file and writes it to storage.

Returns a new View, or an error if creation fails.

Note: This function only supports creating new views with format version 1. It does not support updating existing view metadata. representation holds both SQL text and its dialect. WithIORegistry selects the FileIO registry for the metadata write. props configures FileIO and is also persisted in the view metadata. Use CreateViewWithIOProperties to keep storage credentials out of view metadata.

func CreateViewFromVersion added in v0.8.0

func CreateViewFromVersion(
	ctx context.Context,
	viewIdent table.Identifier,
	schema *iceberg.Schema,
	version *Version,
	loc string,
	ioProps iceberg.Properties,
	metadataProps iceberg.Properties,
	opts ...MetadataIOOption,
) (*View, error)

CreateViewFromVersion creates a view whose first version is version, kept as given apart from its IDs. A nil default namespace defaults to the view's namespace, a nil summary to the engine name, and a zero timestamp to now. WithIORegistry affects only filesystem resolution for the metadata write.

func CreateViewWithIOProperties added in v0.7.0

func CreateViewWithIOProperties(
	ctx context.Context,
	catalogName string,
	viewIdent table.Identifier,
	schema *iceberg.Schema,
	representation Representation,
	defaultNS table.Identifier,
	loc string,
	ioProps iceberg.Properties,
	metadataProps iceberg.Properties,
	opts ...MetadataIOOption,
) (*View, error)

CreateViewWithIOProperties creates a view using ioProps to configure the filesystem and metadataProps as the properties persisted in view metadata. representation holds both SQL text and its dialect. WithIORegistry optionally selects the registry used by the write without changing persisted metadata.

func New

func New(ident table.Identifier, meta Metadata, metadataLocation string, opts ...Option) *View

func NewFromLocation

func NewFromLocation(
	ctx context.Context,
	ident table.Identifier,
	metalocation string,
	fsysF table.FSysF,
) (*View, error)

func (View) CurrentSchema

func (t View) CurrentSchema() *iceberg.Schema

func (View) CurrentVersion

func (t View) CurrentVersion() *Version

func (View) Equals

func (t View) Equals(other View) bool

func (View) History added in v0.8.0

func (v View) History() []VersionLogEntry

History returns the retained changes to the current view version in order. The returned slice is independent of the view's metadata.

func (View) Identifier

func (t View) Identifier() table.Identifier

func (View) Labels added in v0.8.0

func (t View) Labels() *iceberg.Labels

Labels returns the catalog-provided labels from the load response, or nil if the catalog returned none. Labels are transient enrichment, not view state. The returned pointer aliases the view's labels and must be treated as read-only; mutating it affects the shared view value.

func (View) Location

func (t View) Location() string

func (View) Metadata

func (t View) Metadata() Metadata

func (View) MetadataLocation

func (t View) MetadataLocation() string

func (View) Properties

func (t View) Properties() iceberg.Properties

func (View) Schemas

func (t View) Schemas() map[int]*iceberg.Schema

func (View) VersionAsOf added in v0.8.0

func (v View) VersionAsOf(timestampMs int64) *Version

VersionAsOf returns the version that was current at or before timestampMs, measured in milliseconds since the Unix epoch. It uses the version log rather than version creation timestamps, including when a view is rolled back to a previous version.

When timestamps are equal or out of order, the last eligible log entry wins. It returns nil when no history entry is eligible or the selected version has expired from metadata. It does not substitute another retained version.

func (View) VersionByID added in v0.8.0

func (v View) VersionByID(versionID int64) *Version

VersionByID returns a retained view version by ID, or nil if the version is not available in this view's metadata. The returned version is a copy.

func (View) Versions

func (t View) Versions() []*Version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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