twuebi commented on code in PR #594:
URL: https://github.com/apache/iceberg-go/pull/594#discussion_r2416111602


##########
types.go:
##########
@@ -677,32 +701,77 @@ func (BinaryType) primitive()     {}
 func (BinaryType) Type() string   { return "binary" }
 func (BinaryType) String() string { return "binary" }
 
+// TimestampNsType represents a timestamp stored as nanoseconds since the unix 
epoch
+// without regard for timezone. Requires format version 3+.
+type TimestampNsType struct{}
+
+func (TimestampNsType) Equals(other Type) bool {
+       _, ok := other.(TimestampNsType)
+
+       return ok
+}
+
+func (TimestampNsType) primitive()     {}
+func (TimestampNsType) Type() string   { return "timestamp_ns" }
+func (TimestampNsType) String() string { return "timestamp_ns" }
+
+// TimestampTzNsType represents a timestamp stored as UTC with nanoseconds 
since
+// the unix epoch. Requires format version 3+.
+type TimestampTzNsType struct{}
+
+func (TimestampTzNsType) Equals(other Type) bool {
+       _, ok := other.(TimestampTzNsType)
+
+       return ok
+}
+
+func (TimestampTzNsType) primitive()     {}
+func (TimestampTzNsType) Type() string   { return "timestamptz_ns" }
+func (TimestampTzNsType) String() string { return "timestamptz_ns" }
+
 var PrimitiveTypes = struct {
-       Bool        PrimitiveType
-       Int32       PrimitiveType
-       Int64       PrimitiveType
-       Float32     PrimitiveType
-       Float64     PrimitiveType
-       Date        PrimitiveType
-       Time        PrimitiveType
-       Timestamp   PrimitiveType
-       TimestampTz PrimitiveType
-       String      PrimitiveType
-       Binary      PrimitiveType
-       UUID        PrimitiveType
+       Bool          PrimitiveType
+       Int32         PrimitiveType
+       Int64         PrimitiveType
+       Float32       PrimitiveType
+       Float64       PrimitiveType
+       Date          PrimitiveType
+       Time          PrimitiveType
+       Timestamp     PrimitiveType
+       TimestampTz   PrimitiveType
+       TimestampNs   PrimitiveType
+       TimestampTzNs PrimitiveType
+       String        PrimitiveType
+       Binary        PrimitiveType
+       UUID          PrimitiveType
 }{
-       Bool:        BooleanType{},
-       Int32:       Int32Type{},
-       Int64:       Int64Type{},
-       Float32:     Float32Type{},
-       Float64:     Float64Type{},
-       Date:        DateType{},
-       Time:        TimeType{},
-       Timestamp:   TimestampType{},
-       TimestampTz: TimestampTzType{},
-       String:      StringType{},
-       Binary:      BinaryType{},
-       UUID:        UUIDType{},
+       Bool:          BooleanType{},
+       Int32:         Int32Type{},
+       Int64:         Int64Type{},
+       Float32:       Float32Type{},
+       Float64:       Float64Type{},
+       Date:          DateType{},
+       Time:          TimeType{},
+       Timestamp:     TimestampType{},
+       TimestampTz:   TimestampTzType{},
+       TimestampNs:   TimestampNsType{},
+       TimestampTzNs: TimestampTzNsType{},
+       String:        StringType{},
+       Binary:        BinaryType{},
+       UUID:          UUIDType{},
+}
+
+// MinFormatVersionForType returns the minimum table format version required
+// for the given type. Returns 1 for types supported in all versions, or a 
higher
+// version number for types that require newer format versions.
+func MinFormatVersionForType(t Type) int {
+       switch t.(type) {
+       case TimestampNsType, TimestampTzNsType:
+               return 3
+       default:
+               // All other types supported in v1+
+               return 1
+       }

Review Comment:
   I'm not 100% convinced that we have to do it recursively, it refers to the 
type that's passed in, struct & list are supported since v1, in the future we 
may add other composite types that wouldn't be, so IMO it's semantically valid 
to say it refers to the current type instead of recursively to everything 
inside.
   
   Iceberg-java where I got this from just uses a map:
   
   ```
     @VisibleForTesting
     static final Map<Type.TypeID, Integer> MIN_FORMAT_VERSIONS =
         ImmutableMap.of(
             Type.TypeID.TIMESTAMP_NANO, 3,
             Type.TypeID.VARIANT, 3,
             Type.TypeID.UNKNOWN, 3,
             Type.TypeID.GEOMETRY, 3,
             Type.TypeID.GEOGRAPHY, 3);
   ```
   
   It's not public there, I'd also like to keep it unexported here but not sure 
how to achieve that.
   
   We're mostly exporting this due to types living in another place than the 
metadata builder where we do the compatibility check, we do the compat check 
there to avoid exporting the check function itself. I'd be happy to improve the 
structure, in java the check lives in Schema.
   
   Ultimately this is also not a hill I'm willing to die on. If you strongly 
prefer recursive, I can do that too.



-- 
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]

Reply via email to