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


##########
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: %w", d.FilePath(), err)
+       }

Review Comment:
   **nit** — Corrected error message is pinned by no assertion
   
   The delta's whole payload is the wording of this format string, but no test 
asserts it. Reintroducing the redundant 'has invalid file format:' prefix keeps 
the suite green, so the improvement can silently regress. Tightening one row 
per table to assert the full 'data file "...": unknown file format: csv' would 
lock it in. Cosmetic-only, so not worth a round-trip on its own.



##########
data_file_codec_test.go:
##########
@@ -93,6 +93,47 @@ 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"},
+               {name: "empty format", written: "", errorContains: "unknown 
file format: "},
+       }

Review Comment:
   **nit** — empty-format row asserts a prefix common to every unknown-format 
error
   
   errorContains "unknown file format: " is a substring of "unknown file 
format: csv" and of every other unknown-format message, so the row cannot 
distinguish the empty value from any other rejected spelling. It still verifies 
that an empty file_format is not silently accepted, which is the point of the 
row, so this is purely about assertion precision. Same applies to 
manifest_test.go:2456.



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