/// Encode [Apache Parquet] metadata as freestanding [Apache Thrift]-encoded bytes.
///
/// This can be used to store metadata separate from the related payload data. The usage of [Apache Thrift] allows the
/// same stability guarantees as the usage of an ordinary [Apache Parquet] file. To encode a thrift message into bytes
/// the [Thrift Compact Protocol] is used. See [`thrift_to_parquet_metadata`] for decoding.
///
/// [Apache Parquet]: https://parquet.apache.org/
/// [Apache Thrift]: https://thrift.apache.org/
/// [Thrift Compact Protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
Encode [Apache Parquet] metadata as freestanding [Apache Thrift]-encoded bytes.
This can be used to store metadata separate from the related payload data. The usage of [Apache Thrift] allows the
same stability guarantees as the usage of an ordinary [Apache Parquet] file. To encode a thrift message into bytes
the [Thrift Compact Protocol] is used. See [`thrift_to_parquet_metadata`] for decoding.


Encode [ Apache Parquet ] metadata as freestanding [ Apache Thrift ] - encoded bytes . This can be used to store metadata separate from the related payload data . The usage of [ Apache Thrift ] allows the same stability guarantees as the usage of an ordinary [ Apache Parquet ] file . To encode a thrift message into bytes the [ Thrift Compact Protocol ] is used . See [ ` thrift_to_parquet_metadata ` ] for decoding .
pub fn parquet_metadata_to_thrift(parquet_md: &ParquetMetaData) -> Result<Vec<u8>> {
    // step 1: assemble a thrift-compatible struct
    use parquet::schema::types::to_thrift as schema_to_thrift;
    let file_metadata = parquet_md.file_metadata();
    let thrift_schema =
        schema_to_thrift(file_metadata.schema()).context(ParquetSchemaToThrift {})?;
    let thrift_row_groups: Vec<_> = parquet_md
        .row_groups()
        .iter()
        .map(|rg| rg.to_thrift())
        .collect();
    let thrift_file_metadata = parquet_format::FileMetaData {
        version: file_metadata.version(),
        schema: thrift_schema,
        // TODO: column order thrift wrapper (https://github.com/influxdata/influxdb_iox/issues/1408)
        // NOTE: currently the column order is `None` for all written files, see https://github.com/apache/arrow-rs/blob/4dfbca6e5791be400d2fd3ae863655445327650e/parquet/src/file/writer.rs#L193
        column_orders: None,
        num_rows: file_metadata.num_rows(),
        row_groups: thrift_row_groups,
        key_value_metadata: file_metadata.key_value_metadata().clone(),
        created_by: file_metadata.created_by().clone(),
    };
    // step 2: serialize the thrift struct into bytes
    let mut buffer = Vec::new();
    {
        let mut protocol = TCompactOutputProtocol::new(&mut buffer);
        thrift_file_metadata
            .write_to_out_protocol(&mut protocol)
            .context(ThriftWriteFailure {})?;
        protocol.flush().context(ThriftWriteFailure {})?;
    }
    Ok(buffer)
}
pub fn parquet_metadata_to_thrift ( parquet_md : & ParquetMetaData ) -> Result < Vec < u8 > > { // step 1: assemble a thrift-compatible struct use parquet :: schema :: types :: to_thrift as schema_to_thrift ; let file_metadata = parquet_md . file_metadata ( ) ; let thrift_schema = schema_to_thrift ( file_metadata . schema ( ) ) . context ( ParquetSchemaToThrift { } ) ? ; let thrift_row_groups : Vec < _ > = parquet_md . row_groups ( ) . iter ( ) . map ( | rg | rg . to_thrift ( ) ) . collect ( ) ; let thrift_file_metadata = parquet_format :: FileMetaData { version : file_metadata . version ( ) , schema : thrift_schema , // TODO: column order thrift wrapper (https://github.com/influxdata/influxdb_iox/issues/1408) // NOTE: currently the column order is `None` for all written files, see https://github.com/apache/arrow-rs/blob/4dfbca6e5791be400d2fd3ae863655445327650e/parquet/src/file/writer.rs#L193 column_orders : None , num_rows : file_metadata . num_rows ( ) , row_groups : thrift_row_groups , key_value_metadata : file_metadata . key_value_metadata ( ) . clone ( ) , created_by : file_metadata . created_by ( ) . clone ( ) , } ; // step 2: serialize the thrift struct into bytes let mut buffer = Vec :: new ( ) ; { let mut protocol = TCompactOutputProtocol :: new ( & mut buffer ) ; thrift_file_metadata . write_to_out_protocol ( & mut protocol ) . context ( ThriftWriteFailure { } ) ? ; protocol . flush ( ) . context ( ThriftWriteFailure { } ) ? ; } Ok ( buffer ) }
Encode [Apache Parquet] metadata as freestanding [Apache Thrift]-encoded bytes.
Encode [ Apache Parquet ] metadata as freestanding [ Apache Thrift ] - encoded bytes .
parquet_md
&ParquetMetaData