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


##########
catalog/glue/schema.go:
##########
@@ -0,0 +1,107 @@
+// 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 glue
+
+import (
+       "fmt"
+       "strings"
+
+       "github.com/apache/iceberg-go"
+       "github.com/aws/aws-sdk-go-v2/aws"
+       "github.com/aws/aws-sdk-go-v2/service/glue/types"
+)
+
+// schemaToGlueColumns converts an Iceberg schema to a list of Glue columns.
+func schemaToGlueColumns(schema *iceberg.Schema) []types.Column {
+       var columns []types.Column
+       for _, field := range schema.Fields() {
+               columns = append(columns, fieldToGlueColumn(field))
+       }
+
+       return columns
+}
+
+// fieldToGlueColumn converts an Iceberg nested field to a Glue column.
+func fieldToGlueColumn(field iceberg.NestedField) types.Column {
+       column := types.Column{
+               Name:    aws.String(field.Name),
+               Comment: aws.String(field.Doc),
+       }
+       column.Type = aws.String(icebergTypeToGlueType(field.Type))
+
+       return column
+}
+
+// icebergTypeToGlueType converts an Iceberg type to a Glue type string 
representation.
+// It handles primitive types as well as nested types like structs, lists, and 
maps.
+func icebergTypeToGlueType(typ iceberg.Type) string {
+       switch t := typ.(type) {
+       case iceberg.BooleanType:
+               return "boolean"
+       case iceberg.Int32Type:
+               return "int"
+       case iceberg.Int64Type:
+               return "bigint"
+       case iceberg.Float32Type:
+               return "float"
+       case iceberg.Float64Type:
+               return "double"
+       case iceberg.DateType:
+               return "date"
+       case iceberg.TimeType:
+               return "string" // Glue doesn't have a time type. TODO: Double 
check if this is correct
+       case iceberg.TimestampType:
+               return "timestamp"
+       case iceberg.TimestampTzType:
+               return "timestamp" // TODO: Double check if this is correct
+       case iceberg.StringType:
+               return "string"
+       case iceberg.UUIDType:
+               return "string" // Represent UUID as string
+       case iceberg.BinaryType:
+               return "binary"
+       case iceberg.DecimalType:
+               return fmt.Sprintf("decimal(%d,%d)", t.Precision(), t.Scale())
+       case iceberg.FixedType:
+               return fmt.Sprintf("binary(%d)", t.Len())
+       case *iceberg.StructType:
+               // For struct types, create a 
struct<field1:type1,field2:type2,...> representation
+               var fieldStrings []string
+               for _, field := range t.Fields() {
+                       fieldStrings = append(fieldStrings,
+                               fmt.Sprintf("%s:%s", field.Name, 
icebergTypeToGlueType(field.Type)))
+               }
+
+               return fmt.Sprintf("struct<%s>", strings.Join(fieldStrings, 
","))
+       case *iceberg.ListType:
+               // For list types, create an array<type> representation
+               elementField := t.ElementField()
+
+               return fmt.Sprintf("array<%s>", 
icebergTypeToGlueType(elementField.Type))
+       case *iceberg.MapType:
+               // For map types, create a map<keyType,valueType> representation
+               keyField := t.KeyField()
+               valueField := t.ValueField()
+
+               return fmt.Sprintf("map<%s,%s>",
+                       icebergTypeToGlueType(keyField.Type),
+                       icebergTypeToGlueType(valueField.Type))

Review Comment:
   is there documentation we can link to for Glue that specifies these formats? 



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