1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/**
21 * File format description for the parquet file format
22 */
23
24cpp_include "parquet/windows_compatibility.h"
25namespace cpp parquet.format
26namespace java org.apache.parquet.format
27
28/**
29 * Types supported by Parquet.  These types are intended to be used in combination
30 * with the encodings to control the on disk storage format.
31 * For example INT16 is not included as a type since a good encoding of INT32
32 * would handle this.
33 */
34enum Type {
35  BOOLEAN = 0;
36  INT32 = 1;
37  INT64 = 2;
38  INT96 = 3;  // deprecated, only used by legacy implementations.
39  FLOAT = 4;
40  DOUBLE = 5;
41  BYTE_ARRAY = 6;
42  FIXED_LEN_BYTE_ARRAY = 7;
43}
44
45/**
46 * Common types used by frameworks(e.g. hive, pig) using parquet.  This helps map
47 * between types in those frameworks to the base types in parquet.  This is only
48 * metadata and not needed to read or write the data.
49 */
50enum ConvertedType {
51  /** a BYTE_ARRAY actually contains UTF8 encoded chars */
52  UTF8 = 0;
53
54  /** a map is converted as an optional field containing a repeated key/value pair */
55  MAP = 1;
56
57  /** a key/value pair is converted into a group of two fields */
58  MAP_KEY_VALUE = 2;
59
60  /** a list is converted into an optional field containing a repeated field for its
61   * values */
62  LIST = 3;
63
64  /** an enum is converted into a binary field */
65  ENUM = 4;
66
67  /**
68   * A decimal value.
69   *
70   * This may be used to annotate binary or fixed primitive types. The
71   * underlying byte array stores the unscaled value encoded as two's
72   * complement using big-endian byte order (the most significant byte is the
73   * zeroth element). The value of the decimal is the value * 10^{-scale}.
74   *
75   * This must be accompanied by a (maximum) precision and a scale in the
76   * SchemaElement. The precision specifies the number of digits in the decimal
77   * and the scale stores the location of the decimal point. For example 1.23
78   * would have precision 3 (3 total digits) and scale 2 (the decimal point is
79   * 2 digits over).
80   */
81  DECIMAL = 5;
82
83  /**
84   * A Date
85   *
86   * Stored as days since Unix epoch, encoded as the INT32 physical type.
87   *
88   */
89  DATE = 6;
90
91  /**
92   * A time
93   *
94   * The total number of milliseconds since midnight.  The value is stored
95   * as an INT32 physical type.
96   */
97  TIME_MILLIS = 7;
98
99  /**
100   * A time.
101   *
102   * The total number of microseconds since midnight.  The value is stored as
103   * an INT64 physical type.
104   */
105  TIME_MICROS = 8;
106
107  /**
108   * A date/time combination
109   *
110   * Date and time recorded as milliseconds since the Unix epoch.  Recorded as
111   * a physical type of INT64.
112   */
113  TIMESTAMP_MILLIS = 9;
114
115  /**
116   * A date/time combination
117   *
118   * Date and time recorded as microseconds since the Unix epoch.  The value is
119   * stored as an INT64 physical type.
120   */
121  TIMESTAMP_MICROS = 10;
122
123
124  /**
125   * An unsigned integer value.
126   *
127   * The number describes the maximum number of meaningful data bits in
128   * the stored value. 8, 16 and 32 bit values are stored using the
129   * INT32 physical type.  64 bit values are stored using the INT64
130   * physical type.
131   *
132   */
133  UINT_8 = 11;
134  UINT_16 = 12;
135  UINT_32 = 13;
136  UINT_64 = 14;
137
138  /**
139   * A signed integer value.
140   *
141   * The number describes the maximum number of meaningful data bits in
142   * the stored value. 8, 16 and 32 bit values are stored using the
143   * INT32 physical type.  64 bit values are stored using the INT64
144   * physical type.
145   *
146   */
147  INT_8 = 15;
148  INT_16 = 16;
149  INT_32 = 17;
150  INT_64 = 18;
151
152  /**
153   * An embedded JSON document
154   *
155   * A JSON document embedded within a single UTF8 column.
156   */
157  JSON = 19;
158
159  /**
160   * An embedded BSON document
161   *
162   * A BSON document embedded within a single BINARY column.
163   */
164  BSON = 20;
165
166  /**
167   * An interval of time
168   *
169   * This type annotates data stored as a FIXED_LEN_BYTE_ARRAY of length 12
170   * This data is composed of three separate little endian unsigned
171   * integers.  Each stores a component of a duration of time.  The first
172   * integer identifies the number of months associated with the duration,
173   * the second identifies the number of days associated with the duration
174   * and the third identifies the number of milliseconds associated with
175   * the provided duration.  This duration of time is independent of any
176   * particular timezone or date.
177   */
178  INTERVAL = 21;
179}
180
181/**
182 * Representation of Schemas
183 */
184enum FieldRepetitionType {
185  /** This field is required (can not be null) and each record has exactly 1 value. */
186  REQUIRED = 0;
187
188  /** The field is optional (can be null) and each record has 0 or 1 values. */
189  OPTIONAL = 1;
190
191  /** The field is repeated and can contain 0 or more values */
192  REPEATED = 2;
193}
194
195/**
196 * Statistics per row group and per page
197 * All fields are optional.
198 */
199struct Statistics {
200   /**
201    * DEPRECATED: min and max value of the column. Use min_value and max_value.
202    *
203    * Values are encoded using PLAIN encoding, except that variable-length byte
204    * arrays do not include a length prefix.
205    *
206    * These fields encode min and max values determined by signed comparison
207    * only. New files should use the correct order for a column's logical type
208    * and store the values in the min_value and max_value fields.
209    *
210    * To support older readers, these may be set when the column order is
211    * signed.
212    */
213   1: optional binary max;
214   2: optional binary min;
215   /** count of null value in the column */
216   3: optional i64 null_count;
217   /** count of distinct values occurring */
218   4: optional i64 distinct_count;
219   /**
220    * Min and max values for the column, determined by its ColumnOrder.
221    *
222    * Values are encoded using PLAIN encoding, except that variable-length byte
223    * arrays do not include a length prefix.
224    */
225   5: optional binary max_value;
226   6: optional binary min_value;
227}
228
229/** Empty structs to use as logical type annotations */
230struct StringType {}  // allowed for BINARY, must be encoded with UTF-8
231struct UUIDType {}    // allowed for FIXED[16], must encoded raw UUID bytes
232struct MapType {}     // see LogicalTypes.md
233struct ListType {}    // see LogicalTypes.md
234struct EnumType {}    // allowed for BINARY, must be encoded with UTF-8
235struct DateType {}    // allowed for INT32
236
237/**
238 * Logical type to annotate a column that is always null.
239 *
240 * Sometimes when discovering the schema of existing data, values are always
241 * null and the physical type can't be determined. This annotation signals
242 * the case where the physical type was guessed from all null values.
243 */
244struct NullType {}    // allowed for any physical type, only null values stored
245
246/**
247 * Decimal logical type annotation
248 *
249 * To maintain forward-compatibility in v1, implementations using this logical
250 * type must also set scale and precision on the annotated SchemaElement.
251 *
252 * Allowed for physical types: INT32, INT64, FIXED, and BINARY
253 */
254struct DecimalType {
255  1: required i32 scale
256  2: required i32 precision
257}
258
259/** Time units for logical types */
260struct MilliSeconds {}
261struct MicroSeconds {}
262struct NanoSeconds {}
263union TimeUnit {
264  1: MilliSeconds MILLIS
265  2: MicroSeconds MICROS
266  3: NanoSeconds NANOS
267}
268
269/**
270 * Timestamp logical type annotation
271 *
272 * Allowed for physical types: INT64
273 */
274struct TimestampType {
275  1: required bool isAdjustedToUTC
276  2: required TimeUnit unit
277}
278
279/**
280 * Time logical type annotation
281 *
282 * Allowed for physical types: INT32 (millis), INT64 (micros, nanos)
283 */
284struct TimeType {
285  1: required bool isAdjustedToUTC
286  2: required TimeUnit unit
287}
288
289/**
290 * Integer logical type annotation
291 *
292 * bitWidth must be 8, 16, 32, or 64.
293 *
294 * Allowed for physical types: INT32, INT64
295 */
296struct IntType {
297  1: required i8 bitWidth
298  2: required bool isSigned
299}
300
301/**
302 * Embedded JSON logical type annotation
303 *
304 * Allowed for physical types: BINARY
305 */
306struct JsonType {
307}
308
309/**
310 * Embedded BSON logical type annotation
311 *
312 * Allowed for physical types: BINARY
313 */
314struct BsonType {
315}
316
317/**
318 * LogicalType annotations to replace ConvertedType.
319 *
320 * To maintain compatibility, implementations using LogicalType for a
321 * SchemaElement must also set the corresponding ConvertedType from the
322 * following table.
323 */
324union LogicalType {
325  1:  StringType STRING       // use ConvertedType UTF8
326  2:  MapType MAP             // use ConvertedType MAP
327  3:  ListType LIST           // use ConvertedType LIST
328  4:  EnumType ENUM           // use ConvertedType ENUM
329  5:  DecimalType DECIMAL     // use ConvertedType DECIMAL
330  6:  DateType DATE           // use ConvertedType DATE
331
332  // use ConvertedType TIME_MICROS for TIME(isAdjustedToUTC = *, unit = MICROS)
333  // use ConvertedType TIME_MILLIS for TIME(isAdjustedToUTC = *, unit = MILLIS)
334  7:  TimeType TIME
335
336  // use ConvertedType TIMESTAMP_MICROS for TIMESTAMP(isAdjustedToUTC = *, unit = MICROS)
337  // use ConvertedType TIMESTAMP_MILLIS for TIMESTAMP(isAdjustedToUTC = *, unit = MILLIS)
338  8:  TimestampType TIMESTAMP
339
340  // 9: reserved for INTERVAL
341  10: IntType INTEGER         // use ConvertedType INT_* or UINT_*
342  11: NullType UNKNOWN        // no compatible ConvertedType
343  12: JsonType JSON           // use ConvertedType JSON
344  13: BsonType BSON           // use ConvertedType BSON
345  14: UUIDType UUID
346}
347
348/**
349 * Represents a element inside a schema definition.
350 *  - if it is a group (inner node) then type is undefined and num_children is defined
351 *  - if it is a primitive type (leaf) then type is defined and num_children is undefined
352 * the nodes are listed in depth first traversal order.
353 */
354struct SchemaElement {
355  /** Data type for this field. Not set if the current element is a non-leaf node */
356  1: optional Type type;
357
358  /** If type is FIXED_LEN_BYTE_ARRAY, this is the byte length of the vales.
359   * Otherwise, if specified, this is the maximum bit length to store any of the values.
360   * (e.g. a low cardinality INT col could have this set to 3).  Note that this is
361   * in the schema, and therefore fixed for the entire file.
362   */
363  2: optional i32 type_length;
364
365  /** repetition of the field. The root of the schema does not have a repetition_type.
366   * All other nodes must have one */
367  3: optional FieldRepetitionType repetition_type;
368
369  /** Name of the field in the schema */
370  4: required string name;
371
372  /** Nested fields.  Since thrift does not support nested fields,
373   * the nesting is flattened to a single list by a depth-first traversal.
374   * The children count is used to construct the nested relationship.
375   * This field is not set when the element is a primitive type
376   */
377  5: optional i32 num_children;
378
379  /** When the schema is the result of a conversion from another model
380   * Used to record the original type to help with cross conversion.
381   */
382  6: optional ConvertedType converted_type;
383
384  /** Used when this column contains decimal data.
385   * See the DECIMAL converted type for more details.
386   */
387  7: optional i32 scale
388  8: optional i32 precision
389
390  /** When the original schema supports field ids, this will save the
391   * original field id in the parquet schema
392   */
393  9: optional i32 field_id;
394
395  /**
396   * The logical type of this SchemaElement
397   *
398   * LogicalType replaces ConvertedType, but ConvertedType is still required
399   * for some logical types to ensure forward-compatibility in format v1.
400   */
401  10: optional LogicalType logicalType
402}
403
404/**
405 * Encodings supported by Parquet.  Not all encodings are valid for all types.  These
406 * enums are also used to specify the encoding of definition and repetition levels.
407 * See the accompanying doc for the details of the more complicated encodings.
408 */
409enum Encoding {
410  /** Default encoding.
411   * BOOLEAN - 1 bit per value. 0 is false; 1 is true.
412   * INT32 - 4 bytes per value.  Stored as little-endian.
413   * INT64 - 8 bytes per value.  Stored as little-endian.
414   * FLOAT - 4 bytes per value.  IEEE. Stored as little-endian.
415   * DOUBLE - 8 bytes per value.  IEEE. Stored as little-endian.
416   * BYTE_ARRAY - 4 byte length stored as little endian, followed by bytes.
417   * FIXED_LEN_BYTE_ARRAY - Just the bytes.
418   */
419  PLAIN = 0;
420
421  /** Group VarInt encoding for INT32/INT64.
422   * This encoding is deprecated. It was never used
423   */
424  //  GROUP_VAR_INT = 1;
425
426  /**
427   * Deprecated: Dictionary encoding. The values in the dictionary are encoded in the
428   * plain type.
429   * in a data page use RLE_DICTIONARY instead.
430   * in a Dictionary page use PLAIN instead
431   */
432  PLAIN_DICTIONARY = 2;
433
434  /** Group packed run length encoding. Usable for definition/repetition levels
435   * encoding and Booleans (on one bit: 0 is false; 1 is true.)
436   */
437  RLE = 3;
438
439  /** Bit packed encoding.  This can only be used if the data has a known max
440   * width.  Usable for definition/repetition levels encoding.
441   */
442  BIT_PACKED = 4;
443
444  /** Delta encoding for integers. This can be used for int columns and works best
445   * on sorted data
446   */
447  DELTA_BINARY_PACKED = 5;
448
449  /** Encoding for byte arrays to separate the length values and the data. The lengths
450   * are encoded using DELTA_BINARY_PACKED
451   */
452  DELTA_LENGTH_BYTE_ARRAY = 6;
453
454  /** Incremental-encoded byte array. Prefix lengths are encoded using DELTA_BINARY_PACKED.
455   * Suffixes are stored as delta length byte arrays.
456   */
457  DELTA_BYTE_ARRAY = 7;
458
459  /** Dictionary encoding: the ids are encoded using the RLE encoding
460   */
461  RLE_DICTIONARY = 8;
462
463  /** Encoding for floating-point data.
464      K byte-streams are created where K is the size in bytes of the data type.
465      The individual bytes of an FP value are scattered to the corresponding stream and
466      the streams are concatenated.
467      This itself does not reduce the size of the data but can lead to better compression
468      afterwards.
469   */
470  BYTE_STREAM_SPLIT = 9;
471}
472
473/**
474 * Supported compression algorithms.
475 *
476 * Codecs added in format version X.Y can be read by readers based on X.Y and later.
477 * Codec support may vary between readers based on the format version and
478 * libraries available at runtime.
479 *
480 * See Compression.md for a detailed specification of these algorithms.
481 */
482enum CompressionCodec {
483  UNCOMPRESSED = 0;
484  SNAPPY = 1;
485  GZIP = 2;
486  LZO = 3;
487  BROTLI = 4;  // Added in 2.4
488  LZ4 = 5;     // DEPRECATED (Added in 2.4)
489  ZSTD = 6;    // Added in 2.4
490  LZ4_RAW = 7; // Added in 2.9
491}
492
493enum PageType {
494  DATA_PAGE = 0;
495  INDEX_PAGE = 1;
496  DICTIONARY_PAGE = 2;
497  DATA_PAGE_V2 = 3;
498}
499
500/**
501 * Enum to annotate whether lists of min/max elements inside ColumnIndex
502 * are ordered and if so, in which direction.
503 */
504enum BoundaryOrder {
505  UNORDERED = 0;
506  ASCENDING = 1;
507  DESCENDING = 2;
508}
509
510/** Data page header */
511struct DataPageHeader {
512  /** Number of values, including NULLs, in this data page. **/
513  1: required i32 num_values
514
515  /** Encoding used for this data page **/
516  2: required Encoding encoding
517
518  /** Encoding used for definition levels **/
519  3: required Encoding definition_level_encoding;
520
521  /** Encoding used for repetition levels **/
522  4: required Encoding repetition_level_encoding;
523
524  /** Optional statistics for the data in this page**/
525  5: optional Statistics statistics;
526}
527
528struct IndexPageHeader {
529  // TODO
530}
531
532struct DictionaryPageHeader {
533  /** Number of values in the dictionary **/
534  1: required i32 num_values;
535
536  /** Encoding using this dictionary page **/
537  2: required Encoding encoding
538
539  /** If true, the entries in the dictionary are sorted in ascending order **/
540  3: optional bool is_sorted;
541}
542
543/**
544 * New page format allowing reading levels without decompressing the data
545 * Repetition and definition levels are uncompressed
546 * The remaining section containing the data is compressed if is_compressed is true
547 **/
548struct DataPageHeaderV2 {
549  /** Number of values, including NULLs, in this data page. **/
550  1: required i32 num_values
551  /** Number of NULL values, in this data page.
552      Number of non-null = num_values - num_nulls which is also the number of values in the data section **/
553  2: required i32 num_nulls
554  /** Number of rows in this data page. which means pages change on record boundaries (r = 0) **/
555  3: required i32 num_rows
556  /** Encoding used for data in this page **/
557  4: required Encoding encoding
558
559  // repetition levels and definition levels are always using RLE (without size in it)
560
561  /** length of the definition levels */
562  5: required i32 definition_levels_byte_length;
563  /** length of the repetition levels */
564  6: required i32 repetition_levels_byte_length;
565
566  /**  whether the values are compressed.
567  Which means the section of the page between
568  definition_levels_byte_length + repetition_levels_byte_length + 1 and compressed_page_size (included)
569  is compressed with the compression_codec.
570  If missing it is considered compressed */
571  7: optional bool is_compressed = 1;
572
573  /** optional statistics for the data in this page **/
574  8: optional Statistics statistics;
575}
576
577/** Block-based algorithm type annotation. **/
578struct SplitBlockAlgorithm {}
579/** The algorithm used in Bloom filter. **/
580union BloomFilterAlgorithm {
581  /** Block-based Bloom filter. **/
582  1: SplitBlockAlgorithm BLOCK;
583}
584
585/** Hash strategy type annotation. xxHash is an extremely fast non-cryptographic hash
586 * algorithm. It uses 64 bits version of xxHash.
587 **/
588struct XxHash {}
589
590/**
591 * The hash function used in Bloom filter. This function takes the hash of a column value
592 * using plain encoding.
593 **/
594union BloomFilterHash {
595  /** xxHash Strategy. **/
596  1: XxHash XXHASH;
597}
598
599/**
600 * The compression used in the Bloom filter.
601 **/
602struct Uncompressed {}
603union BloomFilterCompression {
604  1: Uncompressed UNCOMPRESSED;
605}
606
607/**
608  * Bloom filter header is stored at beginning of Bloom filter data of each column
609  * and followed by its bitset.
610  **/
611struct BloomFilterHeader {
612  /** The size of bitset in bytes **/
613  1: required i32 numBytes;
614  /** The algorithm for setting bits. **/
615  2: required BloomFilterAlgorithm algorithm;
616  /** The hash function used for Bloom filter. **/
617  3: required BloomFilterHash hash;
618  /** The compression used in the Bloom filter **/
619  4: required BloomFilterCompression compression;
620}
621
622struct PageHeader {
623  /** the type of the page: indicates which of the *_header fields is set **/
624  1: required PageType type
625
626  /** Uncompressed page size in bytes (not including this header) **/
627  2: required i32 uncompressed_page_size
628
629  /** Compressed (and potentially encrypted) page size in bytes, not including this header **/
630  3: required i32 compressed_page_size
631
632  /** The 32bit CRC for the page, to be be calculated as follows:
633   * - Using the standard CRC32 algorithm
634   * - On the data only, i.e. this header should not be included. 'Data'
635   *   hereby refers to the concatenation of the repetition levels, the
636   *   definition levels and the column value, in this exact order.
637   * - On the encoded versions of the repetition levels, definition levels and
638   *   column values
639   * - On the compressed versions of the repetition levels, definition levels
640   *   and column values where possible;
641   *   - For v1 data pages, the repetition levels, definition levels and column
642   *     values are always compressed together. If a compression scheme is
643   *     specified, the CRC shall be calculated on the compressed version of
644   *     this concatenation. If no compression scheme is specified, the CRC
645   *     shall be calculated on the uncompressed version of this concatenation.
646   *   - For v2 data pages, the repetition levels and definition levels are
647   *     handled separately from the data and are never compressed (only
648   *     encoded). If a compression scheme is specified, the CRC shall be
649   *     calculated on the concatenation of the uncompressed repetition levels,
650   *     uncompressed definition levels and the compressed column values.
651   *     If no compression scheme is specified, the CRC shall be calculated on
652   *     the uncompressed concatenation.
653   * - In encrypted columns, CRC is calculated after page encryption; the
654   *   encryption itself is performed after page compression (if compressed)
655   * If enabled, this allows for disabling checksumming in HDFS if only a few
656   * pages need to be read.
657   **/
658  4: optional i32 crc
659
660  // Headers for page specific data.  One only will be set.
661  5: optional DataPageHeader data_page_header;
662  6: optional IndexPageHeader index_page_header;
663  7: optional DictionaryPageHeader dictionary_page_header;
664  8: optional DataPageHeaderV2 data_page_header_v2;
665}
666
667/**
668 * Wrapper struct to store key values
669 */
670 struct KeyValue {
671  1: required string key
672  2: optional string value
673}
674
675/**
676 * Wrapper struct to specify sort order
677 */
678struct SortingColumn {
679  /** The column index (in this row group) **/
680  1: required i32 column_idx
681
682  /** If true, indicates this column is sorted in descending order. **/
683  2: required bool descending
684
685  /** If true, nulls will come before non-null values, otherwise,
686   * nulls go at the end. */
687  3: required bool nulls_first
688}
689
690/**
691 * statistics of a given page type and encoding
692 */
693struct PageEncodingStats {
694
695  /** the page type (data/dic/...) **/
696  1: required PageType page_type;
697
698  /** encoding of the page **/
699  2: required Encoding encoding;
700
701  /** number of pages of this type with this encoding **/
702  3: required i32 count;
703
704}
705
706/**
707 * Description for column metadata
708 */
709struct ColumnMetaData {
710  /** Type of this column **/
711  1: required Type type
712
713  /** Set of all encodings used for this column. The purpose is to validate
714   * whether we can decode those pages. **/
715  2: required list<Encoding> encodings
716
717  /** Path in schema **/
718  3: required list<string> path_in_schema
719
720  /** Compression codec **/
721  4: required CompressionCodec codec
722
723  /** Number of values in this column **/
724  5: required i64 num_values
725
726  /** total byte size of all uncompressed pages in this column chunk (including the headers) **/
727  6: required i64 total_uncompressed_size
728
729  /** total byte size of all compressed, and potentially encrypted, pages
730   *  in this column chunk (including the headers) **/
731  7: required i64 total_compressed_size
732
733  /** Optional key/value metadata **/
734  8: optional list<KeyValue> key_value_metadata
735
736  /** Byte offset from beginning of file to first data page **/
737  9: required i64 data_page_offset
738
739  /** Byte offset from beginning of file to root index page **/
740  10: optional i64 index_page_offset
741
742  /** Byte offset from the beginning of file to first (only) dictionary page **/
743  11: optional i64 dictionary_page_offset
744
745  /** optional statistics for this column chunk */
746  12: optional Statistics statistics;
747
748  /** Set of all encodings used for pages in this column chunk.
749   * This information can be used to determine if all data pages are
750   * dictionary encoded for example **/
751  13: optional list<PageEncodingStats> encoding_stats;
752
753  /** Byte offset from beginning of file to Bloom filter data. **/
754  14: optional i64 bloom_filter_offset;
755}
756
757struct EncryptionWithFooterKey {
758}
759
760struct EncryptionWithColumnKey {
761  /** Column path in schema **/
762  1: required list<string> path_in_schema
763
764  /** Retrieval metadata of column encryption key **/
765  2: optional binary key_metadata
766}
767
768union ColumnCryptoMetaData {
769  1: EncryptionWithFooterKey ENCRYPTION_WITH_FOOTER_KEY
770  2: EncryptionWithColumnKey ENCRYPTION_WITH_COLUMN_KEY
771}
772
773struct ColumnChunk {
774  /** File where column data is stored.  If not set, assumed to be same file as
775    * metadata.  This path is relative to the current file.
776    **/
777  1: optional string file_path
778
779  /** Byte offset in file_path to the ColumnMetaData **/
780  2: required i64 file_offset
781
782  /** Column metadata for this chunk. This is the same content as what is at
783   * file_path/file_offset.  Having it here has it replicated in the file
784   * metadata.
785   **/
786  3: optional ColumnMetaData meta_data
787
788  /** File offset of ColumnChunk's OffsetIndex **/
789  4: optional i64 offset_index_offset
790
791  /** Size of ColumnChunk's OffsetIndex, in bytes **/
792  5: optional i32 offset_index_length
793
794  /** File offset of ColumnChunk's ColumnIndex **/
795  6: optional i64 column_index_offset
796
797  /** Size of ColumnChunk's ColumnIndex, in bytes **/
798  7: optional i32 column_index_length
799
800  /** Crypto metadata of encrypted columns **/
801  8: optional ColumnCryptoMetaData crypto_metadata
802
803  /** Encrypted column metadata for this chunk **/
804  9: optional binary encrypted_column_metadata
805}
806
807struct RowGroup {
808  /** Metadata for each column chunk in this row group.
809   * This list must have the same order as the SchemaElement list in FileMetaData.
810   **/
811  1: required list<ColumnChunk> columns
812
813  /** Total byte size of all the uncompressed column data in this row group **/
814  2: required i64 total_byte_size
815
816  /** Number of rows in this row group **/
817  3: required i64 num_rows
818
819  /** If set, specifies a sort ordering of the rows in this RowGroup.
820   * The sorting columns can be a subset of all the columns.
821   */
822  4: optional list<SortingColumn> sorting_columns
823
824  /** Byte offset from beginning of file to first page (data or dictionary)
825   * in this row group **/
826  5: optional i64 file_offset
827
828  /** Total byte size of all compressed (and potentially encrypted) column data
829   *  in this row group **/
830  6: optional i64 total_compressed_size
831
832  /** Row group ordinal in the file **/
833  7: optional i16 ordinal
834}
835
836/** Empty struct to signal the order defined by the physical or logical type */
837struct TypeDefinedOrder {}
838
839/**
840 * Union to specify the order used for the min_value and max_value fields for a
841 * column. This union takes the role of an enhanced enum that allows rich
842 * elements (which will be needed for a collation-based ordering in the future).
843 *
844 * Possible values are:
845 * * TypeDefinedOrder - the column uses the order defined by its logical or
846 *                      physical type (if there is no logical type).
847 *
848 * If the reader does not support the value of this union, min and max stats
849 * for this column should be ignored.
850 */
851union ColumnOrder {
852
853  /**
854   * The sort orders for logical types are:
855   *   UTF8 - unsigned byte-wise comparison
856   *   INT8 - signed comparison
857   *   INT16 - signed comparison
858   *   INT32 - signed comparison
859   *   INT64 - signed comparison
860   *   UINT8 - unsigned comparison
861   *   UINT16 - unsigned comparison
862   *   UINT32 - unsigned comparison
863   *   UINT64 - unsigned comparison
864   *   DECIMAL - signed comparison of the represented value
865   *   DATE - signed comparison
866   *   TIME_MILLIS - signed comparison
867   *   TIME_MICROS - signed comparison
868   *   TIMESTAMP_MILLIS - signed comparison
869   *   TIMESTAMP_MICROS - signed comparison
870   *   INTERVAL - unsigned comparison
871   *   JSON - unsigned byte-wise comparison
872   *   BSON - unsigned byte-wise comparison
873   *   ENUM - unsigned byte-wise comparison
874   *   LIST - undefined
875   *   MAP - undefined
876   *
877   * In the absence of logical types, the sort order is determined by the physical type:
878   *   BOOLEAN - false, true
879   *   INT32 - signed comparison
880   *   INT64 - signed comparison
881   *   INT96 (only used for legacy timestamps) - undefined
882   *   FLOAT - signed comparison of the represented value (*)
883   *   DOUBLE - signed comparison of the represented value (*)
884   *   BYTE_ARRAY - unsigned byte-wise comparison
885   *   FIXED_LEN_BYTE_ARRAY - unsigned byte-wise comparison
886   *
887   * (*) Because the sorting order is not specified properly for floating
888   *     point values (relations vs. total ordering) the following
889   *     compatibility rules should be applied when reading statistics:
890   *     - If the min is a NaN, it should be ignored.
891   *     - If the max is a NaN, it should be ignored.
892   *     - If the min is +0, the row group may contain -0 values as well.
893   *     - If the max is -0, the row group may contain +0 values as well.
894   *     - When looking for NaN values, min and max should be ignored.
895   */
896  1: TypeDefinedOrder TYPE_ORDER;
897}
898
899struct PageLocation {
900  /** Offset of the page in the file **/
901  1: required i64 offset
902
903  /**
904   * Size of the page, including header. Sum of compressed_page_size and header
905   * length
906   */
907  2: required i32 compressed_page_size
908
909  /**
910   * Index within the RowGroup of the first row of the page; this means pages
911   * change on record boundaries (r = 0).
912   */
913  3: required i64 first_row_index
914}
915
916struct OffsetIndex {
917  /**
918   * PageLocations, ordered by increasing PageLocation.offset. It is required
919   * that page_locations[i].first_row_index < page_locations[i+1].first_row_index.
920   */
921  1: required list<PageLocation> page_locations
922}
923
924/**
925 * Description for ColumnIndex.
926 * Each <array-field>[i] refers to the page at OffsetIndex.page_locations[i]
927 */
928struct ColumnIndex {
929  /**
930   * A list of Boolean values to determine the validity of the corresponding
931   * min and max values. If true, a page contains only null values, and writers
932   * have to set the corresponding entries in min_values and max_values to
933   * byte[0], so that all lists have the same length. If false, the
934   * corresponding entries in min_values and max_values must be valid.
935   */
936  1: required list<bool> null_pages
937
938  /**
939   * Two lists containing lower and upper bounds for the values of each page.
940   * These may be the actual minimum and maximum values found on a page, but
941   * can also be (more compact) values that do not exist on a page. For
942   * example, instead of storing ""Blart Versenwald III", a writer may set
943   * min_values[i]="B", max_values[i]="C". Such more compact values must still
944   * be valid values within the column's logical type. Readers must make sure
945   * that list entries are populated before using them by inspecting null_pages.
946   */
947  2: required list<binary> min_values
948  3: required list<binary> max_values
949
950  /**
951   * Stores whether both min_values and max_values are orderd and if so, in
952   * which direction. This allows readers to perform binary searches in both
953   * lists. Readers cannot assume that max_values[i] <= min_values[i+1], even
954   * if the lists are ordered.
955   */
956  4: required BoundaryOrder boundary_order
957
958  /** A list containing the number of null values for each page **/
959  5: optional list<i64> null_counts
960}
961
962struct AesGcmV1 {
963  /** AAD prefix **/
964  1: optional binary aad_prefix
965
966  /** Unique file identifier part of AAD suffix **/
967  2: optional binary aad_file_unique
968
969  /** In files encrypted with AAD prefix without storing it,
970   * readers must supply the prefix **/
971  3: optional bool supply_aad_prefix
972}
973
974struct AesGcmCtrV1 {
975  /** AAD prefix **/
976  1: optional binary aad_prefix
977
978  /** Unique file identifier part of AAD suffix **/
979  2: optional binary aad_file_unique
980
981  /** In files encrypted with AAD prefix without storing it,
982   * readers must supply the prefix **/
983  3: optional bool supply_aad_prefix
984}
985
986union EncryptionAlgorithm {
987  1: AesGcmV1 AES_GCM_V1
988  2: AesGcmCtrV1 AES_GCM_CTR_V1
989}
990
991/**
992 * Description for file metadata
993 */
994struct FileMetaData {
995  /** Version of this file **/
996  1: required i32 version
997
998  /** Parquet schema for this file.  This schema contains metadata for all the columns.
999   * The schema is represented as a tree with a single root.  The nodes of the tree
1000   * are flattened to a list by doing a depth-first traversal.
1001   * The column metadata contains the path in the schema for that column which can be
1002   * used to map columns to nodes in the schema.
1003   * The first element is the root **/
1004  2: required list<SchemaElement> schema;
1005
1006  /** Number of rows in this file **/
1007  3: required i64 num_rows
1008
1009  /** Row groups in this file **/
1010  4: required list<RowGroup> row_groups
1011
1012  /** Optional key/value metadata **/
1013  5: optional list<KeyValue> key_value_metadata
1014
1015  /** String for application that wrote this file.  This should be in the format
1016   * <Application> version <App Version> (build <App Build Hash>).
1017   * e.g. impala version 1.0 (build 6cf94d29b2b7115df4de2c06e2ab4326d721eb55)
1018   **/
1019  6: optional string created_by
1020
1021  /**
1022   * Sort order used for the min_value and max_value fields of each column in
1023   * this file. Sort orders are listed in the order matching the columns in the
1024   * schema. The indexes are not necessary the same though, because only leaf
1025   * nodes of the schema are represented in the list of sort orders.
1026   *
1027   * Without column_orders, the meaning of the min_value and max_value fields is
1028   * undefined. To ensure well-defined behaviour, if min_value and max_value are
1029   * written to a Parquet file, column_orders must be written as well.
1030   *
1031   * The obsolete min and max fields are always sorted by signed comparison
1032   * regardless of column_orders.
1033   */
1034  7: optional list<ColumnOrder> column_orders;
1035
1036  /**
1037   * Encryption algorithm. This field is set only in encrypted files
1038   * with plaintext footer. Files with encrypted footer store algorithm id
1039   * in FileCryptoMetaData structure.
1040   */
1041  8: optional EncryptionAlgorithm encryption_algorithm
1042
1043  /**
1044   * Retrieval metadata of key used for signing the footer.
1045   * Used only in encrypted files with plaintext footer.
1046   */
1047  9: optional binary footer_signing_key_metadata
1048}
1049
1050/** Crypto metadata for files with encrypted footer **/
1051struct FileCryptoMetaData {
1052  /**
1053   * Encryption algorithm. This field is only used for files
1054   * with encrypted footer. Files with plaintext footer store algorithm id
1055   * inside footer (FileMetaData structure).
1056   */
1057  1: required EncryptionAlgorithm encryption_algorithm
1058
1059  /** Retrieval metadata of key used for encryption of footer,
1060   *  and (possibly) columns **/
1061  2: optional binary key_metadata
1062}
1063
1064