parquet/file/footer.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//! Module for working with Parquet file footers.
19
20use crate::errors::Result;
21use crate::file::{metadata::*, reader::ChunkReader, FOOTER_SIZE};
22
23/// Reads the [ParquetMetaData] from the footer of the parquet file.
24///
25/// # Layout of Parquet file
26/// ```text
27/// +---------------------------+-----+---+
28/// | Rest of file | B | A |
29/// +---------------------------+-----+---+
30/// ```
31/// where
32/// * `A`: parquet footer which stores the length of the metadata.
33/// * `B`: parquet metadata.
34///
35/// # I/O
36///
37/// This method first reads the last 8 bytes of the file via
38/// [`ChunkReader::get_read`] to get the the parquet footer which contains the
39/// metadata length.
40///
41/// It then issues a second `get_read` to read the encoded metadata
42/// metadata.
43///
44/// # See Also
45/// [`decode_metadata`] for decoding the metadata from the bytes.
46/// [`decode_footer`] for decoding the metadata length from the footer.
47#[deprecated(since = "53.1.0", note = "Use ParquetMetaDataReader")]
48pub fn parse_metadata<R: ChunkReader>(chunk_reader: &R) -> Result<ParquetMetaData> {
49 ParquetMetaDataReader::new().parse_and_finish(chunk_reader)
50}
51
52/// Decodes [`ParquetMetaData`] from the provided bytes.
53///
54/// Typically this is used to decode the metadata from the end of a parquet
55/// file. The format of `buf` is the Thrift compact binary protocol, as specified
56/// by the [Parquet Spec].
57///
58/// [Parquet Spec]: https://github.com/apache/parquet-format#metadata
59#[deprecated(since = "53.1.0", note = "Use ParquetMetaDataReader::decode_metadata")]
60pub fn decode_metadata(buf: &[u8]) -> Result<ParquetMetaData> {
61 ParquetMetaDataReader::decode_metadata(buf)
62}
63
64/// Decodes the Parquet footer returning the metadata length in bytes
65///
66/// A parquet footer is 8 bytes long and has the following layout:
67/// * 4 bytes for the metadata length
68/// * 4 bytes for the magic bytes 'PAR1'
69///
70/// ```text
71/// +-----+--------+
72/// | len | 'PAR1' |
73/// +-----+--------+
74/// ```
75#[deprecated(
76 since = "53.1.0",
77 note = "Use ParquetMetaDataReader::decode_footer_tail"
78)]
79pub fn decode_footer(slice: &[u8; FOOTER_SIZE]) -> Result<usize> {
80 ParquetMetaDataReader::decode_footer_tail(slice).map(|f| f.metadata_length())
81}