Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions view/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ func LoadMetadata(ctx context.Context,
return &m, nil
}

// NewMetadata returns a view metadata for a given version.
func NewMetadata(schema *iceberg.Schema,
version Version,
loc string,
props iceberg.Properties,
) Metadata {
// override the corresponding view version fields with the following values.
versionId := int64(1)
Comment on lines +67 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we overriding the version.VersionID with 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove, was thinking it may be better to have a predictable starting point vs whatever is passed in

timestampMs := time.Now().UnixMilli()

if version.SchemaID != schema.ID {
version.SchemaID = schema.ID
}
version.VersionID = versionId
Comment on lines +71 to +74
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also return an error on mismatch instead

version.TimestampMs = timestampMs

return &metadata{
UUID: uuid.NewString(),
FmtVersion: 1,
Loc: loc,
SchemaList: []*iceberg.Schema{schema},
CurrentVersionId: versionId,
VersionList: []Version{version},
VersionLogList: []VersionLogEntry{
{
TimestampMs: timestampMs,
VersionID: versionId,
},
},
Props: props,
}
}

// CreateMetadata creates a new view metadata file and writes it to storage.
//
// Returns the full path to the created metadata file, or an error if creation fails.
Expand Down Expand Up @@ -89,23 +122,7 @@ func CreateMetadata(
}

metadataLocation = loc + "/metadata/view-" + uuid.New().String() + ".metadata.json"

viewUUID := uuid.New().String()
viewMetadata := metadata{
UUID: viewUUID,
FmtVersion: 1,
Loc: loc,
SchemaList: []*iceberg.Schema{schema},
CurrentVersionId: versionId,
VersionList: []Version{viewVersion},
VersionLogList: []VersionLogEntry{
{
TimestampMs: timestampMs,
VersionID: versionId,
},
},
Props: props,
}
viewMetadata := NewMetadata(schema, viewVersion, loc, props)

viewMetadataBytes, err := json.Marshal(viewMetadata)
if err != nil {
Expand Down
Loading