zeroshade commented on code in PR #8122:
URL: https://github.com/apache/iceberg/pull/8122#discussion_r1272476772


##########
go/iceberg/types.go:
##########
@@ -0,0 +1,582 @@
+// 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 iceberg
+
+import (
+       "encoding/json"
+       "fmt"
+       "regexp"
+       "strconv"
+       "strings"
+
+       "golang.org/x/exp/slices"
+)
+
+var (
+       regexFromBrackets = regexp.MustCompile(`^\w+\[(\d+)\]$`)
+       decimalRegex      = regexp.MustCompile(`decimal\((\d+),\s*(\d+)\)`)
+)
+
+type Properties map[string]string
+
+// Type is an interface representing any of the available iceberg types,
+// such as primitives (int32/int64/etc.) or nested types (list/struct/map).
+type Type interface {
+       fmt.Stringer
+       Type() string
+       Equals(Type) bool
+}
+
+// NestedType is an interface that allows access to the child fields of
+// a nested type such as a list/struct/map type.
+type NestedType interface {
+       Type
+       Children() []NestedField
+}
+
+type typeIFace struct {
+       Type
+}
+
+func (t *typeIFace) MarshalJSON() ([]byte, error) {
+       return []byte(`"` + t.Type.Type() + `"`), nil
+}
+
+func (t *typeIFace) UnmarshalJSON(b []byte) error {
+       var typename string
+       err := json.Unmarshal(b, &typename)
+       if err == nil {
+               switch typename {
+               case "boolean":
+                       t.Type = BooleanType{}
+               case "int":
+                       t.Type = Int32Type{}
+               case "long":
+                       t.Type = Int64Type{}
+               case "float":
+                       t.Type = Float32Type{}
+               case "double":
+                       t.Type = Float64Type{}
+               case "date":
+                       t.Type = DateType{}
+               case "time":
+                       t.Type = TimeType{}
+               case "timestamp":
+                       t.Type = TimestampType{}
+               case "timestamptz":
+                       t.Type = TimestampTzType{}
+               case "string":
+                       t.Type = StringType{}
+               case "uuid":
+                       t.Type = UUIDType{}
+               case "binary":
+                       t.Type = BinaryType{}
+               default:
+                       switch {
+                       case strings.HasPrefix(typename, "fixed"):

Review Comment:
   same comment as above, I was following the way that pyiceberg works, which 
regex is essentially just doing the same thing as I'm doing here by checking 
for the prefix and then parsing the number out of the brackets. If we're gonna 
switch this to the same regex as the Java side, we should probably do the same 
in pyiceberg so that all three are aligned, yes?



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