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


##########
go/arrow/avro/reader.go:
##########
@@ -0,0 +1,490 @@
+// 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
+
+import (
+       "errors"
+       "fmt"
+       "io"
+       "sync"
+       "sync/atomic"
+
+       "github.com/apache/arrow/go/v13/arrow"
+       "github.com/apache/arrow/go/v13/arrow/array"
+       "github.com/apache/arrow/go/v13/arrow/internal/debug"
+       "github.com/apache/arrow/go/v13/arrow/memory"
+       "github.com/linkedin/goavro/v2"
+)
+
+// Reader wraps goavro/OCFReader and creates array.Records from a schema.
+type OCFReader struct {
+       r      *goavro.OCFReader
+       schema *arrow.Schema
+
+       refs int64
+       bld  *array.RecordBuilder
+       cur  arrow.Record
+       err  error
+
+       chunk int
+       done  bool
+       next  func() bool
+
+       mem memory.Allocator
+
+       topLevel bool
+       once     sync.Once
+
+       fieldConverter []func(val string)
+       columnFilter   []string
+       columnTypes    map[string]arrow.DataType
+
+       stringsCanBeNull bool
+       nulls            []string
+}
+
+// NewReader returns a reader that reads from an Avro OCF file and creates
+// arrow.Records from the converted schema.
+func NewOCFReader(r io.Reader, opts ...Option) *OCFReader {
+       ocfr, err := goavro.NewOCFReader(r)
+       if err != nil {
+               panic(fmt.Errorf("%w: could not create avro ocfreader", 
arrow.ErrInvalid))
+       }
+
+       rr := &OCFReader{
+               r: ocfr,
+               //schema:           schema,

Review Comment:
   extraneous comment?



##########
go/arrow/avro/reader.go:
##########
@@ -0,0 +1,490 @@
+// 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
+
+import (
+       "errors"
+       "fmt"
+       "io"
+       "sync"
+       "sync/atomic"
+
+       "github.com/apache/arrow/go/v13/arrow"
+       "github.com/apache/arrow/go/v13/arrow/array"
+       "github.com/apache/arrow/go/v13/arrow/internal/debug"
+       "github.com/apache/arrow/go/v13/arrow/memory"
+       "github.com/linkedin/goavro/v2"
+)
+
+// Reader wraps goavro/OCFReader and creates array.Records from a schema.
+type OCFReader struct {
+       r      *goavro.OCFReader
+       schema *arrow.Schema
+
+       refs int64
+       bld  *array.RecordBuilder
+       cur  arrow.Record
+       err  error
+
+       chunk int
+       done  bool
+       next  func() bool
+
+       mem memory.Allocator
+
+       topLevel bool
+       once     sync.Once
+
+       fieldConverter []func(val string)
+       columnFilter   []string
+       columnTypes    map[string]arrow.DataType
+
+       stringsCanBeNull bool
+       nulls            []string
+}
+
+// NewReader returns a reader that reads from an Avro OCF file and creates
+// arrow.Records from the converted schema.
+func NewOCFReader(r io.Reader, opts ...Option) *OCFReader {
+       ocfr, err := goavro.NewOCFReader(r)
+       if err != nil {
+               panic(fmt.Errorf("%w: could not create avro ocfreader", 
arrow.ErrInvalid))
+       }
+
+       rr := &OCFReader{
+               r: ocfr,
+               //schema:           schema,
+               refs:             1,
+               chunk:            1,
+               stringsCanBeNull: false,
+       }
+       //rr.r.ReuseRecord = true

Review Comment:
   same



##########
go/arrow/avro/reader.go:
##########
@@ -0,0 +1,490 @@
+// 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
+
+import (
+       "errors"
+       "fmt"
+       "io"
+       "sync"
+       "sync/atomic"
+
+       "github.com/apache/arrow/go/v13/arrow"
+       "github.com/apache/arrow/go/v13/arrow/array"
+       "github.com/apache/arrow/go/v13/arrow/internal/debug"
+       "github.com/apache/arrow/go/v13/arrow/memory"
+       "github.com/linkedin/goavro/v2"
+)
+
+// Reader wraps goavro/OCFReader and creates array.Records from a schema.
+type OCFReader struct {
+       r      *goavro.OCFReader
+       schema *arrow.Schema
+
+       refs int64
+       bld  *array.RecordBuilder
+       cur  arrow.Record
+       err  error
+
+       chunk int
+       done  bool
+       next  func() bool
+
+       mem memory.Allocator
+
+       topLevel bool
+       once     sync.Once
+
+       fieldConverter []func(val string)
+       columnFilter   []string
+       columnTypes    map[string]arrow.DataType
+
+       stringsCanBeNull bool
+       nulls            []string
+}
+
+// NewReader returns a reader that reads from an Avro OCF file and creates
+// arrow.Records from the converted schema.
+func NewOCFReader(r io.Reader, opts ...Option) *OCFReader {
+       ocfr, err := goavro.NewOCFReader(r)
+       if err != nil {
+               panic(fmt.Errorf("%w: could not create avro ocfreader", 
arrow.ErrInvalid))
+       }
+
+       rr := &OCFReader{
+               r: ocfr,
+               //schema:           schema,
+               refs:             1,
+               chunk:            1,
+               stringsCanBeNull: false,

Review Comment:
   unneeded since Avro can represent null values



##########
go/arrow/avro/schema.go:
##########
@@ -0,0 +1,512 @@
+// 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"
+       "github.com/apache/arrow/go/v13/internal/types"
+)
+
+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.
+func ArrowSchemaFromAvro(avroSchema []byte) (*arrow.Schema, error) {
+       var m map[string]interface{}
+       var node schemaNode
+       json.Unmarshal(avroSchema, &m)
+       if name, ok := m["name"]; ok {
+               node.name = name.(string)
+       } else {
+               node.name = "NameStub"
+       }

Review Comment:
   were we gonna try using the hambra library for this?



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