alliasgher commented on code in PR #876:
URL: https://github.com/apache/iceberg-go/pull/876#discussion_r3074617274
##########
manifest.go:
##########
@@ -1650,6 +1667,48 @@ func avroPartitionData(input map[int]any, logicalTypes
map[int]avro.LogicalType)
return out
}
+// convertFixedValue wraps a FixedType partition value for hamba/avro's
+// union encoder. The encoder cannot dispatch a bare [N]byte array inside
+// a union (see https://github.com/hamba/avro/issues/571), but it does
+// accept the explicit {"<fixed-name>": [N]byte} form used elsewhere for
+// UUID and decimal fixed branches. Nil (the other union arm) is passed
+// through untouched.
+func convertFixedValue(v any, size int) any {
+ if v == nil {
+ return map[string]any{"null": nil}
+ }
+
+ switch b := v.(type) {
+ case []byte:
+ return map[string]any{fixedSchemaName(size):
convertToFixedArray(padOrTruncateBytes(b, size), size)}
Review Comment:
Fixed in 7300516 — replaced `padOrTruncateBytes` with a strict length check
that panics with a clear message if `len(b) != size`. Agreed that silent
truncation here is a data-correctness risk, not a convenience.
##########
schema_conversions_test.go:
##########
@@ -147,3 +151,52 @@ func TestPartitionTypeToAvroSchemaNullableAndNonNullable(t
*testing.T) {
assert.Empty(t, encoded)
})
}
+
+// TestFixedPartitionColumnAvroSchema exercises the full encode/decode path
+// for a FixedType partition column. Before #845 was fixed the partition
+// schema emitted Avro "bytes" (a spec violation); the round-trip here
+// pins the behaviour to a true Avro "fixed" branch.
+func TestFixedPartitionColumnAvroSchema(t *testing.T) {
Review Comment:
Added two manifest-level tests in f896a44:\n\n-
`TestFixedTypePartitionManifestRoundTrip` — creates a table schema with a
FixedType partition column, writes an entry via `WriteManifest`, reads it back
via `ReadManifest`, and asserts the partition value survives byte-for-byte.
This exercises `getFieldIDMap` → `fixedByteSizes`, `avroPartitionData` →
`convertFixedValue`, `ManifestWriter.addEntry`, and
`convertAvroValueToIcebergType` → `unwrapFixedValue`.\n\n-
`TestFixedTypePartitionBackwardCompatibility` — constructs the Avro payload
directly with a `bytes`-typed partition field (simulating what old code wrote),
then reads it with the new code and asserts the value is returned as `[]byte`
without panicking.
--
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]