RussellSpitzer commented on code in PR #16972:
URL: https://github.com/apache/iceberg/pull/16972#discussion_r3501568369


##########
format/spec.md:
##########
@@ -345,6 +346,33 @@ For example, a struct column `point` with fields `x` 
(default 0) and `y` (defaul
 
 Default values are attributes of fields in schemas and serialized with fields 
in the JSON format. See [Appendix C](#appendix-c-json-serialization).
 
+#### Collations
+
+A `string` field may carry a **collation**, an attribute that changes how the 
field's values are compared and ordered without changing how they are stored. 
Collations enable case-insensitive, accent-insensitive, and locale-aware 
comparison and sorting. A collation only affects comparison: the stored value 
is returned unchanged (a value written as `'appLE'` is read back as `'appLE'`).
+
+A field's collation is stored as a `collation` attribute on the field (see 
[Appendix C](#appendix-c-json-serialization)). The attribute is allowed only on 
`string` fields. If a field has no `collation` attribute, comparison defaults 
to UTF-8 byte order, which is the behavior of all prior versions.
+
+A collation is identified by a provider-qualified name of the form 
`<provider>.<name>`, for example `icu.en_US-ci`. The provider names the library 
that defines the collation (`icu` for collations defined by the [Unicode 
Collation Algorithm](https://unicode.org/reports/tr10/) over 
[CLDR](https://cldr.unicode.org/) locale data; other providers may define 
engine-specific collations such as case-folding variants). The name selects a 
locale and optional modifiers for case sensitivity (`ci`/`cs`), accent 
sensitivity (`ai`/`as`), trimming, and case folding. The reserved name `utf8` 
denotes UTF-8 byte-order comparison.
+
+The schema stores the collation **name without a version**, so any engine that 
supports the collation can read the table. UCA, DUCET, CLDR, and ICU collation 
orders are [not stable across 
versions](https://unicode.org/reports/tr10/#Non-Goals), so collation-aware 
metrics carry the implementation version they were produced under (see below) 
and a reader uses them only when it can produce the same order.
+
+##### Collation Bounds
+
+Because a collation can reorder values (for example `'a' < 'B'` under a 
case-insensitive collation, but `'a' > 'B'` in byte order), the byte-order 
`lower_bounds` and `upper_bounds` cannot be used to evaluate predicates on a 
collated column. Collation-aware bounds are stored separately in 
`data_file.collation_bounds`, a map from column id to a list of 
`collation_bound` structs:
+
+| Field id, name | Type | Description |
+|----------------|------|-------------|
+| **`151 collation`** | `string` | Collation the bounds were produced for, 
e.g. `icu.en_US-ci` |

Review Comment:
   To explain a bit more
   
   A string field would be defined like 
   ```
   {
        field_id: 10000 - Utf8 Metrics are here
        Collations {
             name1, version1 or whatever : field_id 10001
             name2, version2 or whatever : field_id 10002
   }
   ```
         
   So each individual string can have as many collations as you like and can 
have them simultaneously. At the row level content_stats we would only populate 
those fields for the collations valid for that data file. 
   
   I'm not sure I follow on the "version bump" comment. If the version bump 
doesn't effectively change the ordering the engine should use the existing 
collation? I'm not sure we should encode in the format itself the version 
bounds of the external library. Seems like that's something that every engine 
should know when looking at these metrics.
   
   



##########
format/spec.md:
##########
@@ -345,6 +346,33 @@ For example, a struct column `point` with fields `x` 
(default 0) and `y` (defaul
 
 Default values are attributes of fields in schemas and serialized with fields 
in the JSON format. See [Appendix C](#appendix-c-json-serialization).
 
+#### Collations
+
+A `string` field may carry a **collation**, an attribute that changes how the 
field's values are compared and ordered without changing how they are stored. 
Collations enable case-insensitive, accent-insensitive, and locale-aware 
comparison and sorting. A collation only affects comparison: the stored value 
is returned unchanged (a value written as `'appLE'` is read back as `'appLE'`).
+
+A field's collation is stored as a `collation` attribute on the field (see 
[Appendix C](#appendix-c-json-serialization)). The attribute is allowed only on 
`string` fields. If a field has no `collation` attribute, comparison defaults 
to UTF-8 byte order, which is the behavior of all prior versions.
+
+A collation is identified by a provider-qualified name of the form 
`<provider>.<name>`, for example `icu.en_US-ci`. The provider names the library 
that defines the collation (`icu` for collations defined by the [Unicode 
Collation Algorithm](https://unicode.org/reports/tr10/) over 
[CLDR](https://cldr.unicode.org/) locale data; other providers may define 
engine-specific collations such as case-folding variants). The name selects a 
locale and optional modifiers for case sensitivity (`ci`/`cs`), accent 
sensitivity (`ai`/`as`), trimming, and case folding. The reserved name `utf8` 
denotes UTF-8 byte-order comparison.
+
+The schema stores the collation **name without a version**, so any engine that 
supports the collation can read the table. UCA, DUCET, CLDR, and ICU collation 
orders are [not stable across 
versions](https://unicode.org/reports/tr10/#Non-Goals), so collation-aware 
metrics carry the implementation version they were produced under (see below) 
and a reader uses them only when it can produce the same order.
+
+##### Collation Bounds
+
+Because a collation can reorder values (for example `'a' < 'B'` under a 
case-insensitive collation, but `'a' > 'B'` in byte order), the byte-order 
`lower_bounds` and `upper_bounds` cannot be used to evaluate predicates on a 
collated column. Collation-aware bounds are stored separately in 
`data_file.collation_bounds`, a map from column id to a list of 
`collation_bound` structs:
+
+| Field id, name | Type | Description |
+|----------------|------|-------------|
+| **`151 collation`** | `string` | Collation the bounds were produced for, 
e.g. `icu.en_US-ci` |

Review Comment:
   To explain a bit more
   
   A string field would be defined like 
   ```
   {
        field_id: 10000 - Utf8 Metrics are here
        Collations {
             name1, version1 or whatever : field_id 10001
             name2, version2 or whatever : field_id 10002
             }
   }
   ```
         
   So each individual string can have as many collations as you like and can 
have them simultaneously. At the row level content_stats we would only populate 
those fields for the collations valid for that data file. 
   
   I'm not sure I follow on the "version bump" comment. If the version bump 
doesn't effectively change the ordering the engine should use the existing 
collation? I'm not sure we should encode in the format itself the version 
bounds of the external library. Seems like that's something that every engine 
should know when looking at these metrics.
   
   



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