Documentation
¶
Index ¶
- Constants
- Variables
- func NewAddSchemaUpdate(schema *iceberg.Schema) *addSchemaUpdate
- func NewAddViewVersionUpdate(version *Version) *addViewVersionUpdate
- func NewAssignUUIDUpdate(uuid uuid.UUID) *assignUUIDUpdate
- func NewRemovePropertiesUpdate(removals []string) *removePropertiesUpdate
- func NewSetCurrentVersionUpdate(id int64) *setCurrentViewVersionUpdate
- func NewSetLocationUpdate(loc string) *setLocationUpdate
- func NewSetPropertiesUpdate(updates iceberg.Properties) *setPropertiesUpdate
- func NewUpgradeFormatVersionUpdate(formatVersion int) *upgradeFormatVersionUpdate
- func WithDefaultViewCatalog(catalogName string) func(*Version)
- type Metadata
- func NewMetadata(version *Version, sc *iceberg.Schema, location string, ...) (Metadata, error)
- func NewMetadataWithUUID(version *Version, sc *iceberg.Schema, location string, ...) (Metadata, error)
- func ParseMetadata(r io.Reader) (Metadata, error)
- func ParseMetadataBytes(b []byte) (Metadata, error)
- func ParseMetadataString(s string) (Metadata, error)
- type MetadataBuildResult
- type MetadataBuilder
- func (b *MetadataBuilder) AddSchema(schema *iceberg.Schema) *MetadataBuilder
- func (b *MetadataBuilder) AddVersion(newVersion *Version) *MetadataBuilder
- func (b *MetadataBuilder) Build() (*MetadataBuildResult, error)
- func (b *MetadataBuilder) Err() error
- func (b *MetadataBuilder) HasChanges() bool
- func (b *MetadataBuilder) RemoveProperties(keys []string) *MetadataBuilder
- func (b *MetadataBuilder) SetCurrentVersion(version *Version, schema *iceberg.Schema) *MetadataBuilder
- func (b *MetadataBuilder) SetCurrentVersionID(newVersionID int64) *MetadataBuilder
- func (b *MetadataBuilder) SetFormatVersion(formatVersion int) *MetadataBuilder
- func (b *MetadataBuilder) SetLoc(loc string) *MetadataBuilder
- func (b *MetadataBuilder) SetProperties(props iceberg.Properties) *MetadataBuilder
- func (b *MetadataBuilder) SetUUID(newUUID uuid.UUID) *MetadataBuilder
- type Representation
- type Representations
- type Requirement
- type Requirements
- type Update
- type Updates
- type Version
- type VersionLogEntry
- type VersionOpt
- type VersionSummary
- type View
- func (t View) CurrentSchema() *iceberg.Schema
- func (t View) CurrentVersion() *Version
- func (t View) Equals(other View) bool
- func (t View) Identifier() table.Identifier
- func (t View) Location() string
- func (t View) Metadata() Metadata
- func (t View) MetadataLocation() string
- func (t View) Properties() iceberg.Properties
- func (t View) Schemas() map[int]*iceberg.Schema
- func (t View) Versions() []*Version
Constants ¶
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 )
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 )
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 ¶
var ( ErrInvalidViewMetadata = errors.New("invalid view metadata") ErrInvalidViewMetadataFormatVersion = errors.New("invalid or missing format-version in view metadata") )
Functions ¶
func NewAddSchemaUpdate ¶
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 ¶
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 ¶
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 ¶
ParseMetadata parses json metadata provided by the passed in reader, returning an error if one is encountered.
func ParseMetadataBytes ¶
ParseMetadataBytes is like ParseMetadataString but for a byte slice.
func ParseMetadataString ¶
ParseMetadataString is like ParseMetadata, but for a string rather than an io.Reader.
type MetadataBuildResult ¶
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, error)
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 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(sql string, dialect string) Representation
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 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. 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, sql string, defaultNS table.Identifier, opts ...VersionOpt) (*Version, error)
NewVersionFromSQL creates a new Version with a single representation using the provided SQL and dialect "default".
type VersionLogEntry ¶
type VersionOpt ¶
type VersionOpt func(*Version)
func WithTimestampMS ¶
func WithTimestampMS(timestampMS int64) VersionOpt
func WithVersionSummary ¶
func WithVersionSummary(summary VersionSummary) VersionOpt
type VersionSummary ¶
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, viewSQL string, defaultNS table.Identifier, loc string, props iceberg.Properties, ) (*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.
func NewFromLocation ¶
func (View) CurrentSchema ¶
func (View) CurrentVersion ¶
func (View) Identifier ¶
func (t View) Identifier() table.Identifier
func (View) MetadataLocation ¶
func (View) Properties ¶
func (t View) Properties() iceberg.Properties