zeroshade commented on code in PR #307:
URL: https://github.com/apache/iceberg-go/pull/307#discussion_r1960181193


##########
utils.go:
##########
@@ -238,3 +239,68 @@ func avroEncode[T any](key string, version int, vals []T, 
out io.Writer) error {
 
        return enc.Close()
 }
+
+func structTypeToAvroPartitionSchema(st *StructType) (avro.Schema, error) {
+       var aFields []*avro.Field
+
+       for _, field := range st.Fields() {
+               aField, err := nestedFieldToAvroField(field)
+
+               if err != nil {
+                       return nil, err
+               }
+
+               aFields = append(aFields, aField)
+       }
+
+       return avro.NewRecordSchema("r102", "", aFields)
+}
+
+func nestedFieldToAvroField(f NestedField) (*avro.Field, error) {
+       sch, err := nestedFieldToAvroSchema(f)
+
+       if err != nil {
+               return nil, err
+       }
+
+       return avro.NewField(
+               f.Name,
+               sch,
+               avro.WithDoc(f.Doc),
+               avro.WithProps(map[string]any{"field-id": f.ID}),
+       )
+}
+
+func nestedFieldToAvroSchema(f NestedField) (avro.Schema, error) {
+       var sch avro.Schema
+
+       switch f.Type.(type) {
+       case *StringType:
+               sch = avro.NewPrimitiveSchema(avro.String, nil)
+       case *Int32Type:
+               sch = avro.NewPrimitiveSchema(avro.Int, nil)
+       case *Int64Type:
+               sch = avro.NewPrimitiveSchema(avro.Long, nil)
+       case *BinaryType:
+               sch = avro.NewPrimitiveSchema(avro.Bytes, nil)
+       case *BooleanType:
+               sch = avro.NewPrimitiveSchema(avro.Boolean, nil)
+       case *Float32Type:
+               sch = avro.NewPrimitiveSchema(avro.Float, nil)
+       case *Float64Type:
+               sch = avro.NewPrimitiveSchema(avro.Double, nil)
+       case *DateType:
+               sch = avro.NewPrimitiveSchema(avro.Int, 
avro.NewPrimitiveLogicalSchema(avro.Date))
+       default:

Review Comment:
   As far as I'm aware, yes. You can't partition on a struct/list/map type to 
my knowledge.



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