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


##########
table/internal/avro_files.go:
##########
@@ -0,0 +1,501 @@
+// 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 internal
+
+import (
+       "context"
+       "errors"
+       "fmt"
+       "math"
+       "strconv"
+       "sync/atomic"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       arrowavro "github.com/apache/arrow-go/v18/arrow/avro"
+       "github.com/apache/arrow-go/v18/arrow/compute"
+       "github.com/apache/iceberg-go"
+       iceio "github.com/apache/iceberg-go/io"
+       avro "github.com/twmb/avro"
+       "github.com/twmb/avro/ocf"
+)
+
+// AvroFileSource reads Iceberg data files stored as Avro object container 
files.
+// The decoder streams Arrow record batches. Column pruning is performed by the
+// scanner after decoding, rather than by the OCF decoder. Nullable records and
+// containers with nested complex values are rejected because the underlying
+// decoder does not safely handle them.
+type AvroFileSource struct {
+       fs   iceio.IO
+       file iceberg.DataFile
+}
+
+func (s *AvroFileSource) GetReader(ctx context.Context) (FileReader, error) {
+       if err := ctx.Err(); err != nil {
+               return nil, err
+       }
+       f, err := s.fs.Open(ctx, s.file.FilePath())
+       if err != nil {
+               return nil, err
+       }
+       reader, err := newAvroFileReader(ctx, f)
+       if err != nil {
+               return nil, errors.Join(err, f.Close())
+       }
+
+       return reader, nil
+}
+
+type avroFileReader struct {
+       file     iceio.File
+       records  *arrowavro.OCFReader
+       schema   *arrow.Schema
+       fileSize int64
+       used     bool
+       closed   bool
+}
+
+// newAvroFileReader reads the original OCF header separately because Arrow's
+// Avro-to-Arrow conversion drops Iceberg's custom field-id properties.
+func newAvroFileReader(ctx context.Context, f iceio.File) (*avroFileReader, 
error) {
+       stat, err := f.Stat()
+       if err != nil {
+               return nil, err
+       }
+       header, err := ocf.NewReader(f)
+       if err != nil {
+               return nil, err
+       }
+       schemaJSON := string(header.Metadata()["avro.schema"])
+       if err := header.Close(); err != nil {
+               return nil, err
+       }
+       if err := validateAvroReadSchema(schemaJSON); err != nil {
+               return nil, err
+       }
+       if _, err := f.Seek(0, 0); err != nil {
+               return nil, err
+       }
+       records, err := arrowavro.NewOCFReader(f,

Review Comment:
   `arrowavro.NewOCFReader` brings `hamba/avro/v2` and its dependencies back 
into the module. Since `twmb/avro` is already used just above to read the 
header, please decode the records with it too and build the Arrow arrays 
directly.



##########
table/internal/avro_files.go:
##########
@@ -0,0 +1,501 @@
+// 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 internal
+
+import (
+       "context"
+       "errors"
+       "fmt"
+       "math"
+       "strconv"
+       "sync/atomic"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       arrowavro "github.com/apache/arrow-go/v18/arrow/avro"
+       "github.com/apache/arrow-go/v18/arrow/compute"
+       "github.com/apache/iceberg-go"
+       iceio "github.com/apache/iceberg-go/io"
+       avro "github.com/twmb/avro"
+       "github.com/twmb/avro/ocf"
+)
+
+// AvroFileSource reads Iceberg data files stored as Avro object container 
files.
+// The decoder streams Arrow record batches. Column pruning is performed by the
+// scanner after decoding, rather than by the OCF decoder. Nullable records and

Review Comment:
   This rejects nullable records and nested containers, so optional struct 
columns, `list<struct>` and Iceberg's array-backed maps can't be read. These 
limits come from the arrow-go decoder; a `twmb/avro`-based decoder shouldn't 
need these guards.



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