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


##########
manifest.go:
##########
@@ -2771,6 +2776,20 @@ func (d *dataFile) setFieldIDToDecimalScaleMap(m 
map[int]int) {
        d.fieldIDToDecimalScale = m
 }
 
+// normalizeFormat sets d.Format to the FileFormat constant matching its
+// decoded spelling, or returns an error if it names no known format.
+// Every Avro decode path must call it before the value is compared or
+// exposed.
+func (d *dataFile) normalizeFormat() error {
+       format, err := FileFormatFromString(string(d.Format))
+       if err != nil {
+               return fmt.Errorf("data file %q has invalid file format: %w", 
d.FilePath(), err)
+       }

Review Comment:
   **nit** — Redundant error nesting: 'has invalid file format: unknown file 
format: csv'
   
   normalizeFormat wraps FileFormatFromString's message, which already says 
'unknown file format: <s>'. The combined string reads 'data file "..." has 
invalid file format: unknown file format: csv'. Something like 'data file %q: 
%w' would read cleanly while keeping the path context that motivated the wrap. 
Purely cosmetic.



##########
data_file_codec_test.go:
##########
@@ -93,6 +93,46 @@ func TestDataFileCodecWithDroppedPartitionSource(t 
*testing.T) {
        require.Equal(t, map[int]any{1000: nil, 1001: int32(3)}, 
decoded.Partition())
 }
 
+func TestUnmarshalAvroDataFileEntryNormalizesFileFormat(t *testing.T) {
+       spec := NewPartitionSpec()
+       schema := NewSchema(0)
+
+       tests := []struct {
+               name          string
+               written       FileFormat
+               expected      FileFormat
+               errorContains string
+       }{
+               {name: "spec lowercase", written: "parquet", expected: 
ParquetFile},
+               {name: "mixed case", written: "Parquet", expected: ParquetFile},
+               {name: "uppercase", written: ParquetFile, expected: 
ParquetFile},
+               {name: "lowercase orc", written: "orc", expected: OrcFile},
+               {name: "unknown format", written: "csv", errorContains: 
"unknown file format: csv"},
+       }

Review Comment:
   **nit** — Codec test table is a strict subset of the manifest one
   
   The manifest table covers avro, puffin and empty-format; the codec table 
stops at parquet/orc/csv. Both call the same normalizeFormat helper so this is 
not a correctness gap, but since the two tables are otherwise parallel, 
mirroring the empty-format row would make the asymmetry deliberate rather than 
incidental. Not worth a round-trip on its own.



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