package table
import (
"github.com/google/uuid"
"github.com/polarsignals/iceberg-go"
)
type MetadataV1Builder struct {
*MetadataV1
}
func NewMetadataV1Builder (
location string ,
schema *iceberg .Schema ,
lastUpdatesMs int64 ,
lastColumnId int ,
) *MetadataV1Builder {
return &MetadataV1Builder {
MetadataV1 : &MetadataV1 {
Schema : schema ,
Partition : []iceberg .PartitionField {},
commonMetadata : commonMetadata {
FormatVersion : 1 ,
Loc : location ,
LastUpdatedMS : lastUpdatesMs ,
LastColumnId : lastColumnId ,
CurrentSchemaID : schema .ID ,
Specs : []iceberg .PartitionSpec {iceberg .NewPartitionSpec ()},
Props : iceberg .Properties {},
},
},
}
}
func CloneMetadataV1 (m Metadata ) *MetadataV1Builder {
b := &MetadataV1Builder {
MetadataV1 : &MetadataV1 {
Schema : m .CurrentSchema (),
Partition : []iceberg .PartitionField {},
commonMetadata : commonMetadata {
FormatVersion : m .Version (),
UUID : m .TableUUID (),
Loc : m .Location (),
Specs : m .PartitionSpecs (),
DefaultSpecID : m .DefaultPartitionSpec (),
Props : m .Properties (),
SchemaList : m .Schemas (),
CurrentSchemaID : m .SchemaID (),
LastPartitionID : m .LastPartitionSpecID (),
SnapshotList : m .Snapshots (),
CurrentSnapshotID : m .SnapshotID (),
SnapshotLog : m .GetSnapshotLog (),
MetadataLog : m .GetMetadataLog (),
SortOrderList : m .SortOrders (),
DefaultSortOrderID : m .SortOrderID (),
Refs : m .SnapshotRefs (),
},
},
}
return b
}
func (b *MetadataV1Builder ) WithLastUpdatedMs (lastUpdatedMs int64 ) *MetadataV1Builder {
b .LastUpdatedMS = lastUpdatedMs
return b
}
func (b *MetadataV1Builder ) WithFormatVersion (version int ) *MetadataV1Builder {
b .FormatVersion = version
return b
}
func (b *MetadataV1Builder ) WithLocation (location string ) *MetadataV1Builder {
b .Loc = location
return b
}
func (b *MetadataV1Builder ) WithSchema (schema *iceberg .Schema ) *MetadataV1Builder {
b .Schema = schema
b .CurrentSchemaID = schema .ID
b .LastColumnId = schema .NumFields ()
b .SchemaList = []*iceberg .Schema {schema }
return b
}
func (b *MetadataV1Builder ) WithTableUUID (id uuid .UUID ) *MetadataV1Builder {
b .UUID = id
return b
}
func (b *MetadataV1Builder ) WithSchemas (schemas []*iceberg .Schema ) *MetadataV1Builder {
b .SchemaList = schemas
return b
}
func (b *MetadataV1Builder ) WithCurrentSchemaID (currentSchemaID int ) *MetadataV1Builder {
b .CurrentSchemaID = currentSchemaID
return b
}
func (b *MetadataV1Builder ) WithPartitionSpecs (specs []iceberg .PartitionSpec ) *MetadataV1Builder {
b .Specs = specs
return b
}
func (b *MetadataV1Builder ) WithDefaultSpecID (defaultSpecID int ) *MetadataV1Builder {
b .DefaultSpecID = defaultSpecID
return b
}
func (b *MetadataV1Builder ) WithLastPartitionID (lastPartitionID int ) *MetadataV1Builder {
l := lastPartitionID
b .LastPartitionID = &l
return b
}
func (b *MetadataV1Builder ) WithProperties (properties iceberg .Properties ) *MetadataV1Builder {
b .Props = properties
return b
}
func (b *MetadataV1Builder ) WithCurrentSnapshotID (currentSnapshotID int64 ) *MetadataV1Builder {
id := currentSnapshotID
b .CurrentSnapshotID = &id
if b .Refs == nil {
b .Refs = make (map [string ]SnapshotRef )
}
b .Refs ["main" ] = SnapshotRef {
SnapshotID : currentSnapshotID ,
SnapshotRefType : BranchRef ,
}
return b
}
func (b *MetadataV1Builder ) WithSnapshots (snapshots []Snapshot ) *MetadataV1Builder {
b .SnapshotList = snapshots
return b
}
func (b *MetadataV1Builder ) WithSnapshotLog (snapshotLog []SnapshotLogEntry ) *MetadataV1Builder {
b .SnapshotLog = snapshotLog
return b
}
func (b *MetadataV1Builder ) WithMetadataLog (metadataLog []MetadataLogEntry ) *MetadataV1Builder {
b .MetadataLog = metadataLog
return b
}
func (b *MetadataV1Builder ) WithSortOrders (sortOrders []SortOrder ) *MetadataV1Builder {
b .SortOrderList = sortOrders
return b
}
func (b *MetadataV1Builder ) WithDefaultSortOrderID (defaultSortOrderID int ) *MetadataV1Builder {
b .DefaultSortOrderID = defaultSortOrderID
return b
}
func (b *MetadataV1Builder ) Build () Metadata {
return b .MetadataV1
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .