parquet/schema/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! Parquet schema definitions and methods to print and parse schema.
6//!
7//! * [`SchemaDescriptor`] describes the data types of the columns stored in a file
8//! * [`ColumnDescriptor`]: Describes the schema of a single (leaf) column.
9//! * [`ColumnPath`]: Represents the location of a column in the schema (e.g. a nested field)
10//!
11//! Parquet distinguishes
12//! between "logical" and "physical" data types.
13//! For instance, strings (logical type) are stored as byte arrays (physical type).
14//! Likewise, temporal types like dates, times, timestamps, etc. (logical type)
15//! are stored as integers (physical type).
16//!
17//! [`SchemaDescriptor`]: types::SchemaDescriptor
18//! [`ColumnDescriptor`]: types::ColumnDescriptor
19//! [`ColumnPath`]: types::ColumnPath
20//!
21//! # Example
22//!
23//! ```rust
24//! use parquet::{
25//! basic::{ConvertedType, Repetition, Type as PhysicalType},
26//! schema::{parser, printer, types::Type},
27//! };
28//! use std::sync::Arc;
29//!
30//! // Create the following schema:
31//! //
32//! // message schema {
33//! // OPTIONAL BYTE_ARRAY a (UTF8);
34//! // REQUIRED INT32 b;
35//! // }
36//!
37//! let field_a = Type::primitive_type_builder("a", PhysicalType::BYTE_ARRAY)
38//! .with_converted_type(ConvertedType::UTF8)
39//! .with_repetition(Repetition::OPTIONAL)
40//! .build()
41//! .unwrap();
42//!
43//! let field_b = Type::primitive_type_builder("b", PhysicalType::INT32)
44//! .with_repetition(Repetition::REQUIRED)
45//! .build()
46//! .unwrap();
47//!
48//! let schema = Type::group_type_builder("schema")
49//! .with_fields(vec![Arc::new(field_a), Arc::new(field_b)])
50//! .build()
51//! .unwrap();
52//!
53//! let mut buf = Vec::new();
54//!
55//! // Print schema into buffer
56//! printer::print_schema(&mut buf, &schema);
57//!
58//! // Parse schema from the string
59//! let string_schema = String::from_utf8(buf).unwrap();
60//! let parsed_schema = parser::parse_message_type(&string_schema).unwrap();
61//!
62//! assert_eq!(schema, parsed_schema);
63//! ```
64
65pub mod parser;
66pub mod printer;
67pub mod types;
68pub mod visitor;