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


##########
table/internal/avro_writer.go:
##########
@@ -0,0 +1,710 @@
+// 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"
+       "encoding/json"
+       "errors"
+       "fmt"
+       "io"
+       "io/fs"
+       "math/big"
+       "os"
+       "strconv"
+       "strings"
+       "unicode"
+       "unicode/utf16"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/extensions"
+       "github.com/apache/iceberg-go"
+       iceberginternal "github.com/apache/iceberg-go/internal"
+       iceio "github.com/apache/iceberg-go/io"
+       "github.com/twmb/avro"
+       "github.com/twmb/avro/ocf"
+)
+
+// avroFormat writes Avro Object Container Files using stable Iceberg field 
IDs.
+// Reading stays in the independent Avro scanner change.
+type avroFormat struct{}
+
+type (
+       avroWriteProps   struct{ codec string }
+       avroWriteSummary struct {
+               rows   int64
+               nulls  map[int]int64
+               values map[int]int64
+       }
+)
+
+func (avroFormat) Open(context.Context, iceio.IO, string) (FileReader, error) {
+       return nil, fmt.Errorf("%w: Avro reading requires the Avro scanner", 
iceberg.ErrNotImplemented)
+}
+
+func (avroFormat) PathToIDMapping(sc *iceberg.Schema) (map[string]int, error) {
+       if sc == nil {
+               return nil, fmt.Errorf("%w: missing Avro schema", 
iceberg.ErrInvalidArgument)
+       }
+       mapping := make(map[string]int, sc.NumFields())
+       for _, f := range sc.Fields() {
+               mapping[f.Name] = f.ID
+       }
+
+       return mapping, nil
+}
+
+func (avroFormat) DataFileStatsFromMeta(meta Metadata, _ 
map[int]StatisticsCollector, _ map[string]int, _ map[int]struct{}, _ 
*arrow.Schema) *DataFileStatistics {
+       s := meta.(*avroWriteSummary)
+
+       return &DataFileStatistics{RecordCount: s.rows, NullValueCounts: 
s.nulls, ValueCounts: s.values}
+}
+
+func (avroFormat) GetWriteProperties(props iceberg.Properties) any {

Review Comment:
   Java's `TableProperties.AVRO_COMPRESSION_DEFAULT` is `gzip`; defaulting to 
`snappy` here means the same table writes differently depending on the client.



##########
table/internal/interfaces.go:
##########
@@ -100,6 +100,8 @@ func GetFileFormat(format iceberg.FileFormat) FileFormat {
        switch format {
        case iceberg.ParquetFile:
                return parquetFormat{}
+       case iceberg.AvroFile:

Review Comment:
   With `write.format.default=avro`, this lets appends commit Avro files that 
`GetFile` can't read, so the table becomes unscannable by iceberg-go. Please 
keep Avro off the table write path until a reader lands.



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