etseidl commented on code in PR #466:
URL: https://github.com/apache/parquet-format/pull/466#discussion_r1829600414
##########
LogicalTypes.md:
##########
@@ -648,49 +650,92 @@ optional group my_list (LIST) {
}
```
-Some existing data does not include the inner element layer. For
-backward-compatibility, the type of elements in `LIST`-annotated structures
-should always be determined by the following rules:
+##### 2-level structure
+
+Some existing data does not include the inner element layer, meaning that
`LIST`
+annotates a 2-level structure. In contrast to 3-level structure, the repetition
+of 2-level structure can be `optional`, `required`, or `repeated`.
+
+```
+<list-repetition> group <name> (LIST) {
+ repeated <element-type> <element-name>;
+}
+```
+
+For backward-compatibility, the type of elements in `LIST`-annotated 2-level
+structures should always be determined by the following rules:
1. If the repeated field is not a group, then its type is the element type and
elements are required.
-2. If the repeated field is a group with multiple fields, then its type is the
- element type and elements are required.
-3. If the repeated field is a group with one field and is named either `array`
- or uses the `LIST`-annotated group's name with `_tuple` appended then the
- repeated type is the element type and elements are required.
-4. Otherwise, the repeated field's type is the element type with the repeated
- field's repetition.
+2. If the repeated field is a group with multiple fields, then its type (Struct
+ type with multiple fields) is the element type and elements are required.
+3. If the repeated field is a group with one `required` or `optional` field,
+ and is named either `array` or uses the `LIST`-annotated group's name with
+ `_tuple` appended, then the repeated type (Struct type with single field) is
+ the element type and elements are required.
+4. If the repeated field is a `LIST`-annotated group with one `repeated` field,
+ then the element type is a list type with 2-level structure and elements are
+ required.
+5. Otherwise, the repeated field's type is the element type with the repeated
+ field's repetition. Please note that the repeated field here (a group with
+ one field) cannot be `LIST`-annotated or `MAP`-annotated 3-level structure,
+ as such a group's repetition must be `required` or `optional`.
Examples that can be interpreted using these rules:
```
-// List<Integer> (nullable list, non-null elements)
+// Rule 1: List<Integer> (nullable list, non-null elements)
optional group my_list (LIST) {
repeated int32 element;
}
-// List<Tuple<String, Integer>> (nullable list, non-null elements)
+// Rule 2: List<Struct<String, Integer>> (nullable list, non-null elements)
optional group my_list (LIST) {
repeated group element {
required binary str (STRING);
required int32 num;
};
}
-// List<OneTuple<String>> (nullable list, non-null elements)
+// Rule 3: List<Struct<String>> (nullable list, non-null elements)
optional group my_list (LIST) {
repeated group array {
required binary str (STRING);
};
}
-// List<OneTuple<String>> (nullable list, non-null elements)
+// Rule 3: List<Struct<String>> (nullable list, non-null elements)
optional group my_list (LIST) {
repeated group my_list_tuple {
required binary str (STRING);
};
}
+
+// List<List<Integer>>
+// Rule 4: nullable outer list with non-null elements
+// Rule 1: non-null inner list with non-null elements
+optional group my_list (LIST) {
+ repeated group array (LIST) {
+ repeated int32 array;
+ }
+}
+```
+
+##### 1-level structure without `LIST` annotation
+
+Some existing data does not even have the `LIST` annotation and simply uses
+`repeated` repetition to annotate the element type. In this case, the element
+type MUST be a primitive type and both the list and elements are required.
Review Comment:
https://github.com/apache/parquet-format/pull/17 is an interesting read, and
explains why the unannotated version exists (allows direct conversion from
protobuf). I _would_ prefer there be a single, canonical way to represent
lists, so perhaps we should bring up deprecating the direct form on the ML. I
don't know how relevant it is now (and in fact only learned of its existence
last week).
--
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]