zeroshade commented on code in PR #600: URL: https://github.com/apache/iceberg-go/pull/600#discussion_r2448817314
########## view/metadata.go: ########## @@ -0,0 +1,127 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package view + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "time" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/internal" + "github.com/apache/iceberg-go/io" + "github.com/google/uuid" +) + +func LoadMetadata(ctx context.Context, + props iceberg.Properties, + metadataLocation string, + name string, + namespace string, +) (_ Metadata, err error) { + fs, err := io.LoadFS(ctx, props, metadataLocation) + if err != nil { + return nil, fmt.Errorf("error loading view metadata: %w", err) + } + + inputFile, err := fs.Open(metadataLocation) + if err != nil { + return nil, fmt.Errorf("%s.%s: error encountered loading view metadata: %w", namespace, name, err) + } + defer internal.CheckedClose(inputFile, &err) + + var m metadata + if err := json.NewDecoder(inputFile).Decode(&m); err != nil { + return nil, fmt.Errorf("error encountered decoding view metadata: %w", err) + } + + return &m, nil +} + +func CreateMetadata( Review Comment: docstring ########## view/metadata.go: ########## @@ -0,0 +1,127 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package view + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "time" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/internal" + "github.com/apache/iceberg-go/io" + "github.com/google/uuid" +) + +func LoadMetadata(ctx context.Context, Review Comment: docstring ########## view/metadata.go: ########## @@ -0,0 +1,127 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package view + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "time" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/internal" + "github.com/apache/iceberg-go/io" + "github.com/google/uuid" +) + +func LoadMetadata(ctx context.Context, + props iceberg.Properties, + metadataLocation string, + name string, + namespace string, +) (_ Metadata, err error) { + fs, err := io.LoadFS(ctx, props, metadataLocation) + if err != nil { + return nil, fmt.Errorf("error loading view metadata: %w", err) + } + + inputFile, err := fs.Open(metadataLocation) + if err != nil { + return nil, fmt.Errorf("%s.%s: error encountered loading view metadata: %w", namespace, name, err) + } + defer internal.CheckedClose(inputFile, &err) + + var m metadata + if err := json.NewDecoder(inputFile).Decode(&m); err != nil { + return nil, fmt.Errorf("error encountered decoding view metadata: %w", err) + } + + return &m, nil +} + +func CreateMetadata( + ctx context.Context, + catalogName string, + nsIdent []string, + schema *iceberg.Schema, + viewSQL string, + loc string, + props iceberg.Properties, +) (metadataLocation string, err error) { + versionId := int64(1) + timestampMs := time.Now().UnixMilli() + + viewVersion := Version{ + VersionID: versionId, + TimestampMs: timestampMs, + SchemaID: schema.ID, + Summary: map[string]string{"sql": viewSQL}, + Representations: []SQLRepresentation{ + {Type: "sql", SQL: viewSQL, Dialect: "default"}, + }, + DefaultCatalog: &catalogName, + DefaultNamespace: nsIdent, + } + + metadataLocation = loc + "/metadata/view-" + uuid.New().String() + ".metadata.json" + + viewUUID := uuid.New().String() Review Comment: Should these uuid's match? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
