parquet/schema/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Parquet schema definitions and methods to print and parse schema.
19//!
20//! * [`SchemaDescriptor`] describes the data types of the columns stored in a file
21//! * [`ColumnDescriptor`]: Describes the schema of a single (leaf) column.
22//! * [`ColumnPath`]: Represents the location of a column in the schema (e.g. a nested field)
23//!
24//! Parquet distinguishes
25//! between "logical" and "physical" data types.
26//! For instance, strings (logical type) are stored as byte arrays (physical type).
27//! Likewise, temporal types like dates, times, timestamps, etc. (logical type)
28//! are stored as integers (physical type).
29//!
30//! [`SchemaDescriptor`]: types::SchemaDescriptor
31//! [`ColumnDescriptor`]: types::ColumnDescriptor
32//! [`ColumnPath`]: types::ColumnPath
33//!
34//! # Example
35//!
36//! ```rust
37//! use parquet::{
38//!     basic::{ConvertedType, Repetition, Type as PhysicalType},
39//!     schema::{parser, printer, types::Type},
40//! };
41//! use std::sync::Arc;
42//!
43//! // Create the following schema:
44//! //
45//! // message schema {
46//! //   OPTIONAL BYTE_ARRAY a (UTF8);
47//! //   REQUIRED INT32 b;
48//! // }
49//!
50//! let field_a = Type::primitive_type_builder("a", PhysicalType::BYTE_ARRAY)
51//!     .with_converted_type(ConvertedType::UTF8)
52//!     .with_repetition(Repetition::OPTIONAL)
53//!     .build()
54//!     .unwrap();
55//!
56//! let field_b = Type::primitive_type_builder("b", PhysicalType::INT32)
57//!     .with_repetition(Repetition::REQUIRED)
58//!     .build()
59//!     .unwrap();
60//!
61//! let schema = Type::group_type_builder("schema")
62//!     .with_fields(vec![Arc::new(field_a), Arc::new(field_b)])
63//!     .build()
64//!     .unwrap();
65//!
66//! let mut buf = Vec::new();
67//!
68//! // Print schema into buffer
69//! printer::print_schema(&mut buf, &schema);
70//!
71//! // Parse schema from the string
72//! let string_schema = String::from_utf8(buf).unwrap();
73//! let parsed_schema = parser::parse_message_type(&string_schema).unwrap();
74//!
75//! assert_eq!(schema, parsed_schema);
76//! ```
77
78pub mod parser;
79pub mod printer;
80pub mod types;
81pub mod visitor;