You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@parquet.apache.org by "alkis (via GitHub)" <gi...@apache.org> on 2024/05/29 19:36:57 UTC

[PR] [T3] Add extension points for all thrift messages [parquet-format]

alkis opened a new pull request, #254:
URL: https://github.com/apache/parquet-format/pull/254

   Specify a backwards/forward compatible way to extend *any* Thrift struct in Parquet.
   
   ref [Parquet Metadata evolution](https://docs.google.com/document/d/1PQpY418LkIDHMFYCY8ne_G-CFpThK15LLpzWYbc7rFU/edit)
   
   ### Jira
   
   - [ ] My PR addresses the following [Parquet Jira](https://issues.apache.org/jira/browse/PARQUET/) issues and references them in the PR title. For example, "PARQUET-1234: My Parquet PR"
     - https://issues.apache.org/jira/browse/PARQUET-XXX
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Commits
   
   - [ ] My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain Javadoc that explain what it does
   


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706789241


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2292867771

   > The reason to prefer "extension types" over "third-party types" or "external types" is that at some point some of them might get standardized inside Parquet, like [Arrow does](https://arrow.apache.org/docs/format/CanonicalExtensions.html).
   > 
   > Though we could also dictate a policy that standardizing an extension type is done by creating a new logical type. @wgtmac
   
   Agreed. I think we can simply follow the rule of Arrow's extension type. A naive proposal would be adding a custom key-value metadata field to `struct SchemaElement`. WDYT?


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2154420460

   I marked this ready for review. I have tested offline that this method works as expected and has virtually no impact in parse speed of the original `FileMetaData` thrift message.
   
   How can we move this forward?


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "steveloughran (via GitHub)" <gi...@apache.org>.
steveloughran commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1627886023


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   i'm just thinking "if ever you want to do any kind of reading across other apps, having a hint of structure would be good". Even if it is just to say "this file has databricks "type 2" footers rather than "something by databricks"



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2358202122

   > I want to make sure @pitrou is happy with the change.
   
   He had one [suggestion](https://github.com/apache/parquet-format/pull/254/commits/4e8672e148c1054b913fc9b5e4c188b56978e51c) which I accepted.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2321086374

   > It seems that license header should be added before merging.
   
   Added.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1705716398


##########
ExtensionExamples.md:
##########
@@ -0,0 +1,77 @@
+# Parquet extension examples
+
+To illustrate the applicability of the proposed specification we provide examples of fictional extensions to parquet and how migration can play out if/when the community decides to adopt them in the official specification.

Review Comment:
   Also, nit but "parquet" should be capitalized "Parquet".



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706647895


##########
ExtensionExamples.md:
##########
@@ -0,0 +1,77 @@
+# Parquet extension examples
+
+To illustrate the applicability of the proposed specification we provide examples of fictional extensions to parquet and how migration can play out if/when the community decides to adopt them in the official specification.

Review Comment:
   Fixed.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "ahmarsuhail (via GitHub)" <gi...@apache.org>.
ahmarsuhail commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1635498873


##########
README.md:
##########
@@ -285,6 +285,107 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |

Review Comment:
   @alkis could I please reserve `AWS` for Amazon, thank you  :) 



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291505258

   > Hi, can we perhaps find another term than "extension" for this feature? The reason is that we may also want to add support for extension types to Parquet (where "extension types" fits naturally with the corresponding feature in Apache Arrow), which might breed confusion when talking about "Parquet extensions". https://lists.apache.org/thread/lcrjoymddllxf8wvq33ddm5fd0tk9mh7
   > 
   > (but perhaps I'm being overly cautious here, what do you think?)
   
   It would be beneficial to avoid confusion. I can't think of a great name for it though. If we name them "experiments" it will make them look risky and can reduce adoption when we use them for migration. "plugins" - I don't like it either. Got any suggestions?
   
   For the extensions in the discussion, I do not have a lot of context: what's the advantage of such extensions vs adding the logical types to the spec?


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623187543


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   IIUC where @steveloughran is coming from `PAR` is reserved so that when we remove the old footer we end up with `PAR\x00` as magic. Similarly with `PER`. Everything else is going to be ephemeral/experimental.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2355591653

   > @wgtmac are we merging this?
   
   I want to make sure @pitrou is happy with the change.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "emkornfield (via GitHub)" <gi...@apache.org>.
emkornfield commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1643824592


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   My main concern with this type of proposal, is the "considered final" piece.  I think if there is closed development here, some extent the incentives of getting to a new 'PAR' are potentially misaligned.  
   
   I like how we are currently iterating in the open on the proposals so everyone has a chance to validate them and provide input.  From a community perspective there is obviously nothing that can be done to stop vendors from having custom metadata in the long run, but at least it would be nice to try to provide guidance for the interim process to encourage openness (maybe the table  above could also contain an optional link to a public repo/gist so that the community can keep tabs on the different approaches?)



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1713416994


##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the ColumnMetaData struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+    4 bytes   | PAR1

Review Comment:
   I committed it because the extension in this case is inside `ColumnMetaData` and it would be one enum + offset/len. If we add this here perhaps I should flesh out that part as well?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1629831010


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   After thinking some more, I simplified the specification further.
   
   I removed all the fields from the encoding itself except the magic 3 byte disambiguator.
   
   The rest are moved into an example section that describes how one might design a `FileMetaData` replacement.
   
   The extension mechanism is very flexible, one might extend `ColumnMetaData` with some extra information and in that design the extension may be very different than the `FileMetaData` replacement.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706646063


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions

Review Comment:
   In the sync it was agreed that we put this small part here and pull only the examples in another file. I will wait for confirmation we want to move everything in another file before moving this. @julienledem WDYT?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "emkornfield (via GitHub)" <gi...@apache.org>.
emkornfield commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623175024


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   How do you see ASF different then PAR?  If this is for other projects I think they should probably reserve it independently?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291021085

   Hi, can we perhaps find another term than "extension" for this feature? The reason is that we may also want to add support for extension types to Parquet (where "extension types" fits naturally with the corresponding feature in Apache Arrow), which might breed confusion when talking about "Parquet extensions".
   https://lists.apache.org/thread/lcrjoymddllxf8wvq33ddm5fd0tk9mh7
   
   (but perhaps I'm being overly cautious here, what do you think?)


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "mhaseeb123 (via GitHub)" <gi...@apache.org>.
mhaseeb123 commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1637308299


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+

Review Comment:
   Hi @alkis , can we reserve "NVD" for NVIDIA as well. Thank you very much!



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1738549841


##########
BinaryProtocolExtensions.md:
##########
@@ -0,0 +1,133 @@
+# Binary Protocol Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+some-UUID is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **FlatBuffers** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new some-other-UUID for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the `ColumnMetaData` struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+              |             | FileMetaData
+              |             | ColumnMetaData: a
+              |             | ColumnMetaData: b
+    F bytes   |             | <extension-blob with offsets to new encoding>
+              |             | ColumnMetaData: c
+              |             | <extension-blob with offsets to new encoding>
+              |             | ColumnMetaData: d
+    4 bytes   | PAR1
+
+The custom reader is compiled with thrift IDL with a binary for field with id 32767. This is done to become extension aware and inspect the extension bytes looking for the UUID disambiguator. If that’s found it decodes the offsets from the rest of the bytes and reads the region of the file containing the new encoding.
+
+If/when the encoding is ratified, it is added to the official specification as an additional type in `Encodings` at which point the extension is no longer necessary, nor the duplicated data in the row group.
+
+## Appending extensions to thrift

Review Comment:
   Yes I have considered it. The advantage of not adding it is that readers will not materialize the extension string. This means all but the readers that care about the extension will not use additional memory or incur extra allocation because of it.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1683802525


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   This was discussed in Parquet Sync on Jul 17th and replaced with a UUID.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1627721788


##########
README.md:
##########
@@ -285,6 +285,68 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by

Review Comment:
   Should we make this `BYTE_ARRAY` as per https://github.com/apache/parquet-format/pull/251?
   ```suggestion
   of this field is always `BYTE_ARRAY` for maximum extensibility and fast skipping by
   ```



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1705717371


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Parquet Thrift IDL reserves field-id `32767` of every Thrift struct for extensions. The (Thrift) type of this field is always `binary`. These choices provide some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Appending extensions to thrift
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  thrift.pop_back();                // remove the stop field
+  thrift += "\x08";                 // binary
+  AppendUleb(32767, &thrift);       // field-id
+  AppendUleb(ext.size(), &thrift);  // field isze

Review Comment:
   A definition of `AppendUleb` should be included as well.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706648829


##########
ExtensionExamples.md:
##########
@@ -0,0 +1,77 @@
+# Parquet extension examples
+
+To illustrate the applicability of the proposed specification we provide examples of fictional extensions to parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+## Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | UUID1
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.

Review Comment:
   Switched to `some-UUID` and `some-other-UUID`.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1683802898


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |

Review Comment:
   This was discussed in Parquet Sync on Jul 17th and was switched to UUID.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1717947363


##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the ColumnMetaData struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+    4 bytes   | PAR1

Review Comment:
   My confusion comes from the fact that it is actually the file layout. How about adding an example on what the extension looks like in the `ColumnMetaData`?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291560967

   > For the extensions in the discussion, I do not have a lot of context: what's the advantage of such extensions vs adding the logical types to the spec?
   
   The point is to decouple the Thrift / Format spec from the definition of new extension (logical) types. It allows third-party definitions of such types and gradual standardization thereof (either inside the Apache Parquet project itself, or by consensus inside a subcommunity). It also makes it easier for the implementations of said types to live outside of the core Parquet implementations, which is desirable for complex and/or highly-specific domains such as with [GeoParquet](https://github.com/opengeospatial/geoparquet).
   
   (personally, I would rather Parquet C++ didn't have to reimplement logic for geospatial data :-))
   


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "julienledem (via GitHub)" <gi...@apache.org>.
julienledem commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623070786


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 

Review Comment:
   I assume we constraint this to binary so that skipping it takes the least amount of time. It might be worth mentioning it here.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623188061


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1629831010


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   After thinking some more, I simplified the specification further.
   
   I have removed all the fields from the encoding itself except the magic 3 byte disambiguator.
   
   The rest are moved into an example section that describes how one might design a `FileMetaData` replacement.
   
   The extension mechanism is very flexible, one might extend `ColumnMetaData` with some extra information and in that design the extension may be very different than the `FileMetaData` replacement.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1640211675


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   I explain this in the previous comment. Some extensions will never be made public and they are served by the same mechanism.



##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   I explain this in the previous comment. Some extensions will never be made public but they are served by the same mechanism.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "julienledem (via GitHub)" <gi...@apache.org>.
julienledem commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1640090405


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   If this is intended to be a temporary state while the new PAR footer format is being iterated on, maybe we don't need to reserve names like this as "PAR" will be the eventual replacement excluding other names.
   
   It seems to me that this proposal would be better described as a path toward evolving the parquet footer while preserving compatibility for a while. The new footer replacing the existing one eventually.
   
   I think extensibility would be useful as well but those two are not the same thing. By extensibility, I would expect users to have a safe, efficient way to add metadata to the file.



##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |

Review Comment:
   This seems to imply that the extension mechanism is exclusive. We can not have at the same time a new "PAR" metadata format and a proprietary extension.



##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |

Review Comment:
   Also,I think we should list here only names that are actually being used and add some information of where they are used and link corresponding documentation. I don't think we need to "reserve" potential future use by a company of their own name.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1627754719


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   Should we have an adhoc `ADH` or experimental `EXP` for the development and benchmark use?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "JFinis (via GitHub)" <gi...@apache.org>.
JFinis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1628128498


##########
README.md:
##########
@@ -285,6 +285,68 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";

Review Comment:
   Add a comment what this magic number is.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1628333100


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   I am still tempted to leave this out as I find it of little utility and unnecessary constraint. What if the designer actually uses some id or version but that's better put at the end of the binary blob before the crc of the len? Why do we want to force it to the start?
   
   I am adding a paragraph to strongly suggest that implementors add an `id` to their extension to make interoperability easier in case it is needed but I leave it up to them to incorporate where they deem most appropriate.



##########
README.md:
##########
@@ -285,6 +285,68 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+To add your extension, file a JIRA and send a PR.
+
+The current list of extensions are
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `DBR` | Databricks |
+| `CDH` | Cloudera |
+| `ASF` | Apache |

Review Comment:
   Done.



##########
README.md:
##########
@@ -285,6 +285,68 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";

Review Comment:
   Done.



##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291569893

   > The point is to decouple the Thrift / Format spec from the definition of new extension (logical) types. It allows third-party definitions of such types and gradual standardization thereof (either inside the Apache Parquet project itself, or by consensus inside a subcommunity). It also makes it easier for the implementations of said types to live outside of the core Parquet implementations, which is desirable for complex and/or highly-specific domains such as with [GeoParquet](https://github.com/opengeospatial/geoparquet).
   > 
   > (personally, I would rather Parquet C++ didn't have to reimplement logic for geospatial data :-))
   
   Makes sense. Should we name these extensions type-extensions or third-party-types or external-types? Should we name the extensions in this PR format-extensions (not sure if this is specific enough though).


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1718554016


##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the ColumnMetaData struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+    4 bytes   | PAR1

Review Comment:
   Added. Let me know if it helps.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "emkornfield (via GitHub)" <gi...@apache.org>.
emkornfield commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623175483


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:

Review Comment:
   along these lines, maybe clarify the process (i.e. it is not heavy weight all it requires is filing an issue and making a PR)?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "steveloughran (via GitHub)" <gi...@apache.org>.
steveloughran commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1627886732


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   EXP sounds good. 



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1640211675


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   I explain this in the previous comment. Some extensions will never be made public but they are served by the same mechanism as public extensions in transition to become the new standard.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1640207092


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |

Review Comment:
   It is exclusive because the extension mechanism covers: custom/internal extensions, experimental public extensions, and transition period for new additions to the standard.
   
   I think an example will make this clearer.
   
   The way I see this playing out is:
   1. different vendors add their own extensions in a way that do not interfere with one another. By construction only one extension can be in a file - since a writer is owned by one vendor and will write that vendors extension. The disambiguator string here so that readers that know about *one* (or more) extensions can check if the extension that is present is one they can read. Some of these extensions will never be made public.
   2. at some point a vendor say `NVD` wants to make their extension public by including it in the standard. At this point there is a formal proposal to include it in the format as a first class part of metadata.
   3. the extension is reviewed and accepted - possibly in a form slightly different that proposed
   4. the accepted proposal takes magic `PAR` and is now public. For a transition period the format contains the new format as an extension so that readers have time to be upgraded. This is one of the reasons we pre-reserve `PAR` now.
   5. once the transition period is over, the extension verbatim becomes the new footer, but now without the thrift field header because it is no longer an extension. At this point we also say that the new magic for the parquet file in this version is `PAR\0`. This will require very little changes to readers that already supported (4).



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1705711472


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions

Review Comment:
   We should perhaps move this to dedicated MD file, such that the examples can also be put in the same file?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706773921


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions

Review Comment:
   How about we leave in the README just this:
   
   > Parquet Thrift IDL reserves field-id `32767` of every Thrift struct for extensions. The (Thrift) type of this field is always `binary`.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706775094


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions

Review Comment:
   Yes, and link to the relevant document.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions (any thrift message) [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2297006103

   > Perhaps "Binary protocol extensions" or "Unparsed protocol extensions"? "Metadata" is usually vague.
   
   Qualified as "Binary Protocol Extensions".


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1735488678


##########
BinaryProtocolExtensions.md:
##########
@@ -0,0 +1,133 @@
+# Binary Protocol Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+some-UUID is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **FlatBuffers** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new some-other-UUID for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the `ColumnMetaData` struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+              |             | FileMetaData
+              |             | ColumnMetaData: a
+              |             | ColumnMetaData: b
+    F bytes   |             | <extension-blob with offsets to new encoding>
+              |             | ColumnMetaData: c
+              |             | <extension-blob with offsets to new encoding>
+              |             | ColumnMetaData: d
+    4 bytes   | PAR1
+
+The custom reader is compiled with thrift IDL with a binary for field with id 32767. This is done to become extension aware and inspect the extension bytes looking for the UUID disambiguator. If that’s found it decodes the offsets from the rest of the bytes and reads the region of the file containing the new encoding.
+
+If/when the encoding is ratified, it is added to the official specification as an additional type in `Encodings` at which point the extension is no longer necessary, nor the duplicated data in the row group.
+
+## Appending extensions to thrift

Review Comment:
   Have you considered directly adding a `32767: optional binary reserved_extension` field to `FileMetaData` and `ColumnMetaData` to make it easier for implementations to append data?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291699330

   @pitrou wdyt about calling the extensions in this PR "Metadata Extensions" vs the other ones "Type Extensions"? Would that clear it?
   
   Bonus is that if/when we add flatbuffers the extension points for flatbuffers will also fall in the same bucket.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291598462

   The reason to prefer "extension types" over "third-party types" or "external types" is that at some point some of them might get standardized inside Parquet, like [Arrow does](https://arrow.apache.org/docs/format/CanonicalExtensions.html).
   
   Though we could also dictate a policy that standardizing an extension type is done by creating a new logical type. @wgtmac 


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1754588827


##########
BinaryProtocolExtensions.md:
##########
@@ -0,0 +1,152 @@
+<!--
+  - Licensed to the Apache Software Foundation (ASF) under one
+  - or more contributor license agreements.  See the NOTICE file
+  - distributed with this work for additional information
+  - regarding copyright ownership.  The ASF licenses this file
+  - to you under the Apache License, Version 2.0 (the
+  - "License"); you may not use this file except in compliance
+  - with the License.  You may obtain a copy of the License at
+  -
+  -   http://www.apache.org/licenses/LICENSE-2.0
+  -
+  - Unless required by applicable law or agreed to in writing,
+  - software distributed under the License is distributed on an
+  - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  - KIND, either express or implied.  See the License for the
+  - specific language governing permissions and limitations
+  - under the License.
+  -->
+
+# Binary Protocol Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+some-UUID is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **FlatBuffers** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new some-other-UUID for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the `ColumnMetaData` struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+              |             | FileMetaData
+              |             | ColumnMetaData: a
+              |             | ColumnMetaData: b
+    F bytes   |             | <extension-blob with offsets to new encoding>
+              |             | ColumnMetaData: c
+              |             | <extension-blob with offsets to new encoding>
+              |             | ColumnMetaData: d
+    4 bytes   | PAR1
+
+The custom reader is compiled with thrift IDL with a binary for field with id 32767. This is done to become extension aware and inspect the extension bytes looking for the UUID disambiguator. If that’s found it decodes the offsets from the rest of the bytes and reads the region of the file containing the new encoding.
+
+If/when the encoding is ratified, it is added to the official specification as an additional type in `Encodings` at which point the extension is no longer necessary, nor the duplicated data in the row group.
+
+## Appending extensions to thrift
+
+```c++
+void AppendUleb(uint32_t x, std::string* out) {
+  while (true) {
+    uint8_t c = x & 0x7F;
+    if (x < 0x80) return out->push_back(c);
+    out->push_back(c + 0x80);
+    x >>= 7;
+  }
+};
+
+std::string AppendExtension(std::string thrift, const std::string& ext) {
+  thrift.back() = '\x08';      // replace stop field with binary type

Review Comment:
   ```suggestion
     assert(thrift.back() == '\x00');   // there was a stop field in the first place
     thrift.back() = '\x08';      // replace stop field with binary type
   ```



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623189082


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   In practice they will start with some ID because vendors will experiment and need to disambiguate internally. But I do not want to specify this since it won't make it in the official spec.
   
   For example, Databricks experiments with footers. It uses the above mechanism and rolls this out to several customers. The first byte contains some id for the blob:
   1. some custom encoding to speed up colchunk offset parsing only, with the idea that this is enough to pipeline data I/O with metadata parsing
   2. some more refinement to the encoding
   3. another experiment, now with more structured data, say flatbuffers
   4. refinement of (3)
   5. etc
   6. Final version proposed for inclusion to the spec
   At this point (6) does not have to end up in the official spec. The way it will be added is either through changing the magic of parquet, or through adding a new binary field in `FileMetaData` that contains the final version of the encoding.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1627754089


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   Should we have an adhoc `ADH` or experimental `EXP` for the development and benchmark use?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1713003208


##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  

Review Comment:
   ```suggestion
   2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **FlatBuffers** `FileMetaData` will be present.  
   ```



##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the ColumnMetaData struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+    4 bytes   | PAR1

Review Comment:
   ```suggestion
       4 bytes   | PAR1
       ----------+-------------+----------------------------
                 |             | Column b (new encoding)
                 |             | Column c (new encoding)
       R bytes   |  Row Group  | Column a
                 |     0       | Column d
                 |             | Column b (old encoding)
                 |             | Column c (old encoding)
       ----------+-------------+----------------------------
       F bytes   |FileMetaData |
       ----------+-------------+----------------------------
       4 bytes   | PAR1
   ```
   
   It looks a little bit confusing to me if we omit the `FileMetaData` section. Propose the change for completion with a little stylish modification.



##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.

Review Comment:
   ```suggestion
   some-UUID is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
   ```



##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the ColumnMetaData struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+    4 bytes   | PAR1
+
+The custom reader is compiled with thrift IDL with a binary for field with id 32767\. This is done to become extension aware and inspect the extension bytes looking for the UUID disambiguator. If that’s found it decodes the offsets from the rest of the bytes and reads the region of the file containing the new encoding.

Review Comment:
   ```suggestion
   The custom reader is compiled with thrift IDL with a binary for field with id 32767. This is done to become extension aware and inspect the extension bytes looking for the UUID disambiguator. If that’s found it decodes the offsets from the rest of the bytes and reads the region of the file containing the new encoding.
   ```



##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  

Review Comment:
   ```suggestion
   * There is a new some-other-UUID for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
   ```



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1705714734


##########
ExtensionExamples.md:
##########
@@ -0,0 +1,77 @@
+# Parquet extension examples
+
+To illustrate the applicability of the proposed specification we provide examples of fictional extensions to parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+## Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | UUID1
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.

Review Comment:
   Note that UUID1, UUID2... can be understood as the various versions of the UUID generation algorithm, which might make this confusing to the reader.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706658756


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Parquet Thrift IDL reserves field-id `32767` of every Thrift struct for extensions. The (Thrift) type of this field is always `binary`. These choices provide some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Appending extensions to thrift
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  thrift.pop_back();                // remove the stop field
+  thrift += "\x08";                 // binary
+  AppendUleb(32767, &thrift);       // field-id
+  AppendUleb(ext.size(), &thrift);  // field isze

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2352201386

   @wgtmac are we merging this?


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "steveloughran (via GitHub)" <gi...@apache.org>.
steveloughran commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1622681238


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   * put in `CDH` for cloudera.
   * put in `ASF` for apache software foundation (i.e. if projects can agree)



##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:

Review Comment:
   make a table, and clarify "current" to "at the time this specification was written"



##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   I'd be tempted to declare that the first 2 bytes map to a format ID. This does stop extension formats being completely closed, provided the authors don't change it and document the structure



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "emkornfield (via GitHub)" <gi...@apache.org>.
emkornfield commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623175261


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   @steveloughran could you elaborate I'm don't think I understand what you  are suggesting?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623189082


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   In practice they will start with some ID because vendors will experiment and need to disambiguate. But I do not want to specify this since it won't make it in the official spec.
   
   For example, Databricks experiments with footers. It uses the above mechanism and rolls this out to several customers. The first byte contains some id for the blob:
   1. some custom encoding to speed up colchunk offset parsing only, with the idea that this is enough to pipeline data I/O with metadata parsing
   2. some more refinement to the encoding
   3. another experiment, now with more structured data, say flatbuffers
   4. refinement of (3)
   5. etc
   6. Final version proposed for inclusion to the spec
   At this point (6) does not have to end up in the official spec. The way it will be added is either through changing the magic of parquet, or through adding a new binary field in `FileMetaData` that contains the final version of the encoding.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "JFinis (via GitHub)" <gi...@apache.org>.
JFinis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1628126788


##########
README.md:
##########
@@ -285,6 +285,68 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by

Review Comment:
   Thrift doesn't have ``BYTE_ARRAY`, just `binary`. The former is a physical type in Parquet, but thrift messages don't use Par quet types.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions (any thrift message) [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2309712842

   Doesn't this require a vote before merging?


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "JFinis (via GitHub)" <gi...@apache.org>.
JFinis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1628129932


##########
README.md:
##########
@@ -285,6 +285,68 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+To add your extension, file a JIRA and send a PR.
+
+The current list of extensions are
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `DBR` | Databricks |
+| `CDH` | Cloudera |
+| `ASF` | Apache |

Review Comment:
   If this PR gets merged, can I please reserve `CRM` for Salesforce, thanks :).



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac merged PR #254:
URL: https://github.com/apache/parquet-format/pull/254


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2336510391

   As the vote has passed, I will merge it if no objection or feedback received before Sep 12.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions (any thrift message) [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2309680295

   Friendly ping. Since there are no other comments can we merge this?


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2311721909

   > Doesn't this require a vote before merging?
   
   Started one here: https://lists.apache.org/thread/x3472kldrq5kjnld9ztj1jozz25f40hg


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add binary protocol extensions [parquet-format]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2316590096

   ```
   [INFO] Rat check: Summary over all files. Unapproved: 1, unknown: 1, generated: 0, approved: 28 licenses.
   Warning:  Files with unapproved licenses:
     BinaryProtocolExtensions.md
   
   [INFO] ------------------------------------------------------------------------
   [INFO] BUILD FAILURE
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time:  11.651 s
   [INFO] Finished at: 2024-08-22T15:38:07Z
   [INFO] ------------------------------------------------------------------------
   Error:  Failed to execute goal org.apache.rat:apache-rat-plugin:0.16.1:check (default) on project parquet-format: Too many files with unapproved license: 1 See RAT report in: /home/runner/work/parquet-format/parquet-format/target/rat.txt -> [Help 1]
   Error:  
   Error:  To see the full stack trace of the errors, re-run Maven with the -e switch.
   Error:  Re-run Maven using the -X switch to enable full debug logging.
   Error:  
   Error:  For more information about the errors and possible solutions, please read the following articles:
   Error:  [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
   Error: Process completed with exit code 1.
   ```
   
   It seems that license header should be added before merging.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1683802525


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+
+To reserve additional magic numbers, file a JIRA and send a PR.
+
+The magic is 3 bytes because it is always followed by the 0 byte, the thrift
+field stop byte. Together this defines a 4 byte magic number, which can be used
+in place of existing parquet magic numbers.
+
+#### An example FileMetaData replacement and migration plan
+
+Consider the case of extending `FileMetaData` a full replacement. That is
+the new encoding contains all the information of `FileMetaData` and readers
+that know about it can elide parsing the current thrift `FileMetaData`. This
+extension has additional considerations and requirements.
+
+First, observe that `FileMetaData` is located between the last column chunk
+and the 4-byte length plus 4-byte `PAR1` magic. Sophisticated parquet readers,
+typically read the tail of files speculatively and expect to find the full
+footer in that fetch. Thus our extension must be decodable from the end of the
+file, and without having to fetch the full old `FileMetaData` thrift encoding.
+As a corollary finding the bounds of the extension should not require thrift
+parsing.
+
+To satisfy these requirements we define our `FileMetaData` extension as:
+
+    N bytes: the new `FileMetaData` replacement - in some encoding
+    4 bytes: little endian crc32 of the previous N bytes
+    4 bytes: N in little endian
+    4 bytes: little endian crc32 of N
+    3 bytes: 3-byte magic extension from the table above
+
+Each field plays its role to satisfy the requirements. In reverse order:
+1. 3-byte magic extension: as per the specification. When this new
+`FileMetaData` replaces the old, we can replace the thrift `FileMetaData`
+including the trailing 8 bytes and replace them with our extension plus the
+null byte verbatim.
+2. `le32(N)` + `crc32(N)`: The pair of len and its crc32 is useful to validate
+that the length is correct. Otherwise we might be tripped to read an
+unspecified number of bytes only to later find their crc32 does not match.
+3. `crc32(bytes)`: The crc32 of the new `FileMetaData` itself is important to
+avoid reading corrupt or erroneous metadata.
+4. The bytes of the encoding. This should be in our new encoding, for the sake
+of argument flatbuffers, prefixed with an ID so that we as we experiment can
+distinguish different versions of metadata.
+
+The development and migration plan might look like:
+1. A period where the new `FileMetaData` will be written after the old, with a
+non-reserved 3 byte magic, say `DBR`.
+2. Once the format stabilizes and is considered final, it is brought to the
+parquet commitee for ratification.
+3. When ratified the extension is moved to an approved state and takes the
+reserved 3 byte magic `PAR`.

Review Comment:
   This was discussed in Parquet Sync and replaced with a UUID.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1713416994


##########
Extensions.md:
##########
@@ -0,0 +1,127 @@
+# Parquet Extensions
+
+The extension mechanism of the `binary` Thrift field-id `32767` has some desirable properties:
+
+* Existing readers will ignore these extensions without any modifications  
+* Existing readers will ignore the extension bytes with little processing overhead  
+* The content of the extension is freeform and can be encoded in any format. This format is not restricted to Thrift.  
+* Extensions can be appended to existing Thrift serialized structs [without requiring Thrift libraries](#appending-extensions-to-thrift) for manipulation (or changes to the thrift IDL).
+
+Because only one field-id is reserved the extension bytes themselves require disambiguation; otherwise readers will not be able to decode extensions safely. This is left to implementers which MUST put enough unique state in their extension bytes for disambiguation. This can be relatively easily achieved by adding a [UUID](https://en.wikipedia.org/wiki/Universally\_unique\_identifier) at the start or end of the extension bytes. The extension does not specify a disambiguation mechanism to allow more flexibility to implementers.
+
+Putting everything together in an example, if we would extend `FileMetaData` it would look like this on the wire.
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(M) encoded size of the extension
+    M bytes   | extension bytes
+    1 byte    | \0 (thrift stop field)
+
+The choice to reserve only one field-id has an additional (and frankly unintended) property. It creates scarcity in the extension space and disincentivizes vendors from keeping their extensions private. As a vendor having an extension means one cannot use it in tandem with other extensions from other vendors even if such extensions are publicly known. The easiest path of interoperability and ability to further experiment is to push an extension through standardization and continue experimenting with other ideas internally on top of the (now) standardized version.
+
+#### Path to standardization
+
+So far the above specification shows how different vendors can add extensions without stepping on each other's toes. As long as extensions are private this works out ok.
+
+Unavoidably (and desirably) some extensions will make it into the official specification. Depending on the nature of the extension, migration can take different paths. While it is out of the scope of this document to design all such migrations, we illustrate some of these paths in the [examples](#examples).
+
+## Examples
+
+To illustrate the applicability of the extension mechanism we provide examples of fictional extensions to Parquet and how migration can play out if/when the community decides to adopt them in the official specification.
+
+### Footer
+
+A variant of `FileMetaData` encoded in Flatbuffers is introduced. This variant is more performant and can scale to very wide tables, something that current Thrift `FileMetaData` struggles with.
+
+In its private form the footer of a Parquet file will look like so:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v0) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+UUID1 is some UUID picked for this extension and it is used throughout (possibly internal) experimentation. It is put at the end to allow detection of the extension when parsed in reverse. The little-endian sizes and crc32s are also to the end to facilitate efficient parsing the footer in reverse without requiring parsing the Thrift compact protocol that precedes it.
+
+At some point the experiments conclude and the extension shared publicly with the community. The extension is proposed for inclusion to the standard with a migration plan to replace the existing `FileMetaData`.
+
+The community reviews the proposal and (potentially) proposes changes to the Flatbuffers IDL representation. In addition, because this extension is a *replacement* of an existing struct, it must:
+
+1. have some way of being extended in the future much like what it replaces. Because the extension mechanism only allows for a single extension, without this in place we cannot have footer extensions during the migration.  
+2. consider its intermediate form where both the **Thrift** `FileMetaData` and the **flatbuffer** `FileMetaData` will be present.  
+3. consider its final form where the long form header for `32767: binary` may not be present.
+
+Once the design is ratified the new `FileMetaData` encoding is made final with the following migration plan. For the next N years writers will write both the Thrift and the flatbuffer `FileMetaData`. It will look much like its private form except the flatbuffer IDL may be different:
+
+    N-1 bytes | Thrift compact protocol encoded FileMetadata (minus \0 thrift stop field)
+    4 bytes   | 08 FF FF 01 (long form header for 32767: binary)
+    1-5 bytes | ULEB128(K+28) encoded size of the extension
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    16 bytes  | some-other-UUID
+    1 byte    | \0 (thrift stop field)
+    4 bytes   | PAR1
+
+After the migration period, the end of the Parquet file may look like this:
+
+    K bytes   | Flatbuffers representation (v1) of FileMetaData
+    4 bytes   | little-endian crc32(flatbuffer)
+    4 bytes   | little-endian size(flatbuffer)
+    4 bytes   | little-endian crc32(size(flatbuffer))
+    4 bytes   | PAR3
+
+In this example, we see several design decisions for the extension at play:
+
+* There is a new UUID2 for the accepted change to the standard and now the Thrift `FileMetaData` cannot be extended itself.  
+* The length of the footer and the crc32 of the length itself, guarantees that new readers will not overshoot reading bytes in case of corrupt bits in these critical 8 bytes of the file.  
+* The crc32 of the flatbuffer representation enhances Parquet to have crc32 for metadata as well which is arguably more important than crc32 for data.  
+* The new encoding itself, which MUST contain some way to be extended in the future (much like Thrift does with this specification).
+
+### Encoding
+
+The community experiments with a new encoding extension. At the same time they want to keep the newly encoded Parquet files open for everyone to read. So they add a new encoding via an extension to the ColumnMetaData struct. The extension stores offsets in the Parquet file where the new and duplicate encoded data for this column lives. The new writer carefully places all the new encodings at the start of the row group and all the old encodings at the end of the row group. This layout minimizes disruption for readers unaware of the new encodings.
+
+In its private form Parquet files look like so:
+
+    4 bytes   | PAR1
+              |             | Column b (new encoding)
+              |             | Column c (new encoding)
+    R bytes   |  Row Group  | Column a
+              |     0       | Column d
+              |             | Column b (old encoding)
+              |             | Column c (old encoding)
+    4 bytes   | PAR1

Review Comment:
   I ommitted it because the extension in this case is inside `ColumnMetaData` and it would be one enum + offset/len. If we add this here perhaps I should flesh out that part as well?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2291568220

   > It would be beneficial to avoid confusion. I can't think of a great name for it though. If we name them "experiments" it will make them look risky and can reduce adoption when we use them for migration. "plugins" - I don't like it either. Got any suggestions?
   
   "Thrift protocol escapes"? "Thrift binary appends"?
   


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #254:
URL: https://github.com/apache/parquet-format/pull/254#issuecomment-2296244473

   > @pitrou wdyt about calling the extensions in this PR "Metadata Extensions" vs the other ones "Type Extensions"? Would that clear it?
   
   Perhaps "Binary protocol extensions" or "Unparsed protocol extensions"? "Metadata" is usually vague.


-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1705712123


##########
ExtensionExamples.md:
##########
@@ -0,0 +1,77 @@
+# Parquet extension examples
+
+To illustrate the applicability of the proposed specification we provide examples of fictional extensions to parquet and how migration can play out if/when the community decides to adopt them in the official specification.

Review Comment:
   It won't be a "proposed specification" once it ends up in the format repository.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1706748620


##########
README.md:
##########
@@ -290,6 +290,46 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions

Review Comment:
   This does not look that small in the context of a README :-) And it seems a bit weird to me to feature it prominently in the README even though it's meant to be a rather obscure feature.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1629831010


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data

Review Comment:
   After thinking some more, I simplified the specification further.
   
   I removed all the fields from the encoding itself except the magic 3 byte disambiguator.
   
   The rest are moved into an example section that describes how one might design a `FileMetaData` replacement.
   
   The extension mechanism is very flexible, one might extend `ColumnMetaData` with some extra information and in that design the extension may be very different than the `FileMetaData` replacement described here.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1635849105


##########
README.md:
##########
@@ -285,6 +285,107 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] PARQUET-2492: Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1640210893


##########
README.md:
##########
@@ -285,6 +285,108 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary` for maximum extensibility and fast skipping by
+thrift parsers.
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";  // long form field header for 32767: binary
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+To facilitate independence of extensions between organizations the last 3 bytes
+of an extension contain a magic number. The current reserved magic numbers are:
+
+| Magic | Organization |
+|-------|--------------|
+| `PAR` | Reserved for the future when an extension replaces `PAR1` |
+| `PER` | Reserved for the future when an extension replaces `PARE` |
+| `ASF` | Apache |
+| `AWS` | Amazon |
+| `CDH` | Cloudera |
+| `CRM` | Salesforce |
+| `DBR` | Databricks |
+| `EXP` | Apache/Experimental |
+

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "emkornfield (via GitHub)" <gi...@apache.org>.
emkornfield commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623175024


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   How do you see ASF different then PAR?  If this is for other projects I think they should probably reserve it.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "alkis (via GitHub)" <gi...@apache.org>.
alkis commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1623189252


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 

Review Comment:
   Done.



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org


Re: [PR] [T3] Add extension points for all thrift messages [parquet-format]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #254:
URL: https://github.com/apache/parquet-format/pull/254#discussion_r1627754719


##########
README.md:
##########
@@ -285,6 +285,61 @@ There are many places in the format for compatible extensions:
 - Encodings: Encodings are specified by enum and more can be added in the future.
 - Page types: Additional page types can be added and safely skipped.
 
+### Thrift extensions
+Thrift is used for metadata. The Thrift spec mandates that unknown fields are
+skipped. To facilitate extensions Parquet reserves field-id `32767` of *every*
+struct as an ignorable extension point. More specifically Parquet guarantees
+that field-id `32767` will *never* be seen in the official Thrift IDL. The type
+of this field is always `binary`. 
+
+Such extensions can easily be appended to an existing Thrift serialized message
+without any special APIs. Sample `C++` implementation is provided:
+
+```c++
+std::string AppendExtension(std::string thrift, std::string ext) {
+  auto append_uleb = [](uint32_t x, std::string* out) {
+    while (true) {
+      int c = x & 0x7F;
+      if ((x >>= 7) == 0) {
+        out->push_back(c);
+        return;
+      } else {
+        out->push_back(c | 0x80);
+      }
+    }
+  };
+  thrift.pop_back();  // remove the trailing 0
+  thrift += "\x08\xFF\xFF\x01";
+  append_uleb(ext.size(), &thrift);
+  thrift += ext;
+  thrift += "\x00";  // add the trailing 0 back
+  return thrift;
+}
+```
+
+Additionally the binary extension MUST have a specific form in order to be
+unambiguously identifiable by parsers that know of it and, as a corollary,
+impossible to be accidentally generated by user data.
+
+```
+N bytes: the extension data
+4 bytes: little endian crc32 of the previous N bytes
+4 bytes: N in little endian 
+4 bytes: little endian crc32 of N
+3 bytes: 3 byte magic extension (after this we have the Thrift stop-field)
+```
+
+The choice of the 3 byte magic is so that the magic plus the `\x00` for the
+stop-field will form a new 4 byte magic which can replace `PAR1` or `PARE` in
+the future when all engines adopt a new format.
+
+Each organization/engine can reserve a magic extension here to avoid clashes.
+
+The current list of extensions are:
+- `PAR`: Reserved for the future when an extension replaces `PAR1`
+- `PER`: Reserved for the future when an extension replaces `PARE`
+- `DBR`: Databricks

Review Comment:
   Should we have an adhoc `ADH` or experimental `EXP` for the development and benchmark use?



-- 
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: issues-unsubscribe@parquet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org