zeroshade commented on code in PR #2721:
URL: https://github.com/apache/iceberg-go/pull/2721#discussion_r4722198781
##########
manifest.go:
##########
@@ -715,10 +727,15 @@ func newManifestReader(
var writerSchema *avro.Schema
var rd *ocf.Reader
var err error
+ // Java allows non-ASCII letters and digits in an Avro name (it tests
+ // each UTF-16 char with Character.isLetter/isLetterOrDigit), so a
+ // Java-written header can name a partition field with a character that
+ // the strict Avro name rule rejects.
+ laxNames := ocf.WithSchemaOpts(avro.WithLaxNames(nil))
Review Comment:
Nit (non-blocking): this option and its comment are repeated in
`table/internal/avro_files.go`, `table/partition_statistics_write.go` and
`table/validate_snapshot.go`. A shared helper in `internal` would keep the four
readers in step.
Also, `WithLaxNames(nil)` accepts any non-empty name, which is broader than
"non-ASCII letters and digits". That's fine for reading, but the comment could
say so. Alternatively, pass a validator that checks names with
`unicode.IsLetter` / `unicode.IsDigit` to match Java exactly.
##########
schema_conversions.go:
##########
@@ -83,3 +84,29 @@ func partitionTypeToAvroSchema(t *StructType) (*avro.Schema,
error) {
return node.Schema()
}
+
+// avroCompatibleName returns name as a valid Avro name. For an ASCII name it
+// matches Java's AvroSchemaUtil.makeCompatibleName: a character Avro does not
+// allow becomes "_x" and its code point in upper-case hex, and a digit that
+// starts the name gets a "_" before it. Unlike Java and makeCompatibleName,
+// it also escapes a non-ASCII letter, because twmb/avro accepts only names
+// that match [A-Za-z_][A-Za-z0-9_]*. A partition field name such as
+// "event.ts_day", which GeneratePartitionFieldName makes for a nested source
+// column, is not a valid Avro name. Readers find partition fields by field
+// ID, so the name is only a label.
+func avroCompatibleName(name string) string {
Review Comment:
Nit (non-blocking): an escaped name can collide with a real field name. For
example, a spec with partition fields `a.b` and `a_x2Eb` fails with `duplicate
record field name "a_x2Eb"`. Java has the same collision and the error is
clear, so a sentence in the doc comment is enough.
--
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]