nastra commented on code in PR #11:
URL: https://github.com/apache/iceberg-go/pull/11#discussion_r1348502543


##########
table/snapshots.go:
##########
@@ -0,0 +1,186 @@
+// 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 table
+
+import (
+       "encoding/json"
+       "errors"
+       "fmt"
+       "strconv"
+
+       "github.com/apache/iceberg-go"
+       "github.com/apache/iceberg-go/io"
+       "golang.org/x/exp/maps"
+)
+
+type Operation string
+
+const (
+       OpAppend    Operation = "append"
+       OpReplace   Operation = "replace"
+       OpOverwrite Operation = "overwrite"
+       OpDelete    Operation = "delete"
+)
+
+var (
+       ErrInvalidOperation = errors.New("invalid operation value")
+       ErrMissingOperation = errors.New("missing operation key")
+)
+
+// ValidOperation ensures that a given string is one of the valid operation
+// types: append,replace,overwrite,delete
+func ValidOperation(s string) (Operation, error) {
+       switch s {
+       case "append", "replace", "overwrite", "delete":
+               return Operation(s), nil
+       }
+       return "", fmt.Errorf("%w: found '%s'", ErrInvalidOperation, s)
+}
+
+const operationKey = "operation"
+
+// Summary stores the summary information for a snapshot indicating
+// the operation that created the snapshot, and various properties
+// which might exist in the summary.
+type Summary struct {
+       Operation  Operation
+       Properties map[string]string
+}
+
+func (s *Summary) Equals(other *Summary) bool {
+       if s == other {
+               return true
+       }
+
+       if s != nil && other == nil {
+               return false
+       }
+
+       if s.Operation != other.Operation {
+               return false
+       }
+
+       if len(s.Properties) == 0 && len(other.Properties) == 0 {
+               return true
+       }
+
+       return maps.Equal(s.Properties, other.Properties)
+}
+
+func (s *Summary) UnmarshalJSON(b []byte) (err error) {
+       alias := map[string]string{}
+       if err = json.Unmarshal(b, &alias); err != nil {
+               return
+       }
+
+       op, ok := alias[operationKey]
+       if !ok {
+               return ErrMissingOperation
+       }
+
+       if s.Operation, err = ValidOperation(op); err != nil {
+               return
+       }
+
+       delete(alias, operationKey)
+       s.Properties = alias
+       return nil
+}
+
+func (s *Summary) MarshalJSON() ([]byte, error) {
+       props := maps.Clone(s.Properties)
+       if s.Operation != "" {
+               if props == nil {
+                       props = make(map[string]string)
+               }
+               props[operationKey] = string(s.Operation)
+       }
+
+       return json.Marshal(props)
+}
+
+type Snapshot struct {
+       SnapshotID       int64    `json:"snapshot-id"`
+       ParentSnapshotID *int64   `json:"parent-snapshot-id,omitempty"`
+       SequenceNumber   int      `json:"sequence-number"`
+       TimestampMs      int      `json:"timestamp-ms"`

Review Comment:
   should this be int64?



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to