zeroshade commented on code in PR #36796:
URL: https://github.com/apache/arrow/pull/36796#discussion_r1281166530


##########
go/arrow/avro/schema.go:
##########
@@ -0,0 +1,409 @@
+// 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 avro reads Avro OCF files and presents the extracted data as records
+package avro
+
+import (
+       "encoding/json"
+       "fmt"
+       "math"
+       "strconv"
+
+       "github.com/apache/arrow/go/v13/arrow"
+)
+
+type schemaNode struct {
+       name        string
+       ofType      interface{}
+       logicalType string
+       precision   int32
+       scale       int32
+       size        int
+       symbols     []string
+       fields      []interface{}
+}
+
+// ArrowSchemaFromAvro returns a new Arrow schema from an Avro schema JSON.
+// If the top level is of record type, set includeTopLevel to either make
+// its fields top level fields in the resulting schema or nested in a single 
field.
+func ArrowSchemaFromAvro(avroSchema []byte) (*arrow.Schema, error) {
+       var m map[string]interface{}
+       var node schemaNode
+       json.Unmarshal(avroSchema, &m)
+       if m["type"].(string) == "record" {
+               if _, ok := m["fields"]; ok {
+                       for _, field := range m["fields"].([]interface{}) {
+                               node.fields = append(node.fields, 
field.(map[string]interface{}))
+                       }
+                       if len(node.fields) == 0 {
+                               return nil, fmt.Errorf("invalid avro schema: no 
top level record fields found")
+                       }
+               }
+       }
+       fields := iterateFields(node.fields)
+       return arrow.NewSchema(fields, nil), nil
+}

Review Comment:
   Yea, that's fine. MIT license is compatible with the Apache 2 license and 
can be bundled together as components



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

Reply via email to