You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/04 21:08:58 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #3269: Add parquet-layout binary

tustvold opened a new pull request, #3269:
URL: https://github.com/apache/arrow-rs/pull/3269

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   Frequently when debugging an issue the first port of call is working out the physical layout of the data in the parquet file, what indexes are present, what encodings are being used, how large the pages are, etc...
   
   I have been unable to find such a tool, so I quickly wrote one up to replace the ad-hoc code I keep having to write :sweat_smile: 
   
   <details>
   <summary>parquet-testing/data/nested_lists.snappy.parquet</summary>
   <pre><code>{
     "row_groups": [
       {
         "columns": [
           {
             "path": "a.list.element.list.element.list.element",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": "snappy",
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 30,
                 "uncompressed_bytes": 30,
                 "header_bytes": 13,
                 "num_values": 6
               },
               {
                 "compression": "snappy",
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 34,
                 "uncompressed_bytes": 33,
                 "header_bytes": 27,
                 "num_values": 18
               }
             ]
           },
           {
             "path": "b",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": "snappy",
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 6,
                 "uncompressed_bytes": 4,
                 "header_bytes": 13,
                 "num_values": 1
               },
               {
                 "compression": "snappy",
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 4,
                 "uncompressed_bytes": 2,
                 "header_bytes": 33,
                 "num_values": 3
               }
             ]
           }
         ]
       }
     ]
   }
   </code></pre>
   </details>
   
   <details>
   <summary>parquet-testing/data/data_index_bloom_encoding_stats.parquet</summary>
   <pre><code>{
     "row_groups": [
       {
         "columns": [
           {
             "path": "String",
             "has_offset_index": true,
             "has_column_index": true,
             "has_bloom_filter": true,
             "pages": [
               {
                 "compression": "gzip",
                 "encoding": "plain",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 127,
                 "uncompressed_bytes": 138,
                 "header_bytes": 25,
                 "num_values": 14
               }
             ]
           }
         ]
       }
     ]
   }
   </code></pre>
   </details>
   
   <details>
   <summary>parquet-testing/data/alltypes_dictionary.parquet</summary>
   <pre><code>{
     "row_groups": [
       {
         "columns": [
           {
             "path": "id",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 8,
                 "uncompressed_bytes": 8,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "bool_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 7,
                 "uncompressed_bytes": 7,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "tinyint_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 8,
                 "uncompressed_bytes": 8,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "smallint_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 8,
                 "uncompressed_bytes": 8,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "int_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 8,
                 "uncompressed_bytes": 8,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "bigint_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 16,
                 "uncompressed_bytes": 16,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "float_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 8,
                 "uncompressed_bytes": 8,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "double_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 16,
                 "uncompressed_bytes": 16,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "date_string_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 12,
                 "uncompressed_bytes": 12,
                 "header_bytes": 13,
                 "num_values": 1
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "string_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 10,
                 "uncompressed_bytes": 10,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           },
           {
             "path": "timestamp_col",
             "has_offset_index": false,
             "has_column_index": false,
             "has_bloom_filter": false,
             "pages": [
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "dictionary",
                 "compressed_bytes": 24,
                 "uncompressed_bytes": 24,
                 "header_bytes": 13,
                 "num_values": 2
               },
               {
                 "compression": null,
                 "encoding": "plain_dictionary",
                 "page_type": "data_page_v1",
                 "compressed_bytes": 9,
                 "uncompressed_bytes": 9,
                 "header_bytes": 17,
                 "num_values": 2
               }
             ]
           }
         ]
       }
     ]
   }
   </code></pre>
   </details>
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] ursabot commented on pull request #3269: Add parquet-layout binary

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3269:
URL: https://github.com/apache/arrow-rs/pull/3269#issuecomment-1338250375

   Benchmark runs are scheduled for baseline = b155461f770eb2ab8cc5d3296f6123582cf5073d and contender = 94d597edab1cb6dd0c84b94ab223ba89901ccfb6. 94d597edab1cb6dd0c84b94ab223ba89901ccfb6 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/a0ccc4b49666428e97aa0d4df1ef4289...9afac8d2efd5407f8664a5cc82b1de5a/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/a096996e49c04323a8af473dc57eae1a...3bb706005c19485b97f90f1bc531b65a/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/09d5e1f7bcbe406787082d066cdcdbb8...422bdbfec1054eb2bd03cc73314a1bc6/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/dd32173feb0f463ea51015e2901d6916...cac4ecc955624a8dac9b52af95ff81ab/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on a diff in pull request #3269: Add parquet-layout binary

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #3269:
URL: https://github.com/apache/arrow-rs/pull/3269#discussion_r1039924077


##########
parquet/src/bin/parquet-layout.rs:
##########
@@ -0,0 +1,234 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Binary that prints the physical layout of a parquet file

Review Comment:
   👍 
   
   As a general musing, I think some of these cli helpers are quite nice and maybe eventually we could make them more discoverable / nicer to people who are not working with the parquet source code.
   
   I didn't find anything other than https://github.com/apache/arrow-rs/tree/master/parquet/src/bin for documentation
   
   Perhaps to `prqs` or something similar 🤔 
   
   



##########
parquet/src/bin/parquet-layout.rs:
##########
@@ -0,0 +1,234 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Binary that prints the physical layout of a parquet file
+//!
+//! # Install
+//!
+//! `parquet-layout` can be installed using `cargo`:
+//! ```
+//! cargo install parquet --features=cli
+//! ```
+//! After this `parquet-layout` should be available:
+//! ```
+//! parquet-layout XYZ.parquet
+//! ```
+//!
+//! The binary can also be built from the source code and run as follows:
+//! ```
+//! cargo run --features=cli --bin parquet-layout XYZ.parquet
+//! ```
+
+use std::fs::File;
+use std::io::Read;
+
+use clap::Parser;
+use serde::Serialize;
+use thrift::protocol::{TCompactInputProtocol, TSerializable};
+
+use parquet::basic::{Compression, Encoding};
+use parquet::errors::Result;
+use parquet::file::reader::ChunkReader;
+use parquet::format::PageHeader;
+
+#[derive(Serialize, Debug)]
+struct ParquetFile {
+    row_groups: Vec<RowGroup>,
+}
+
+#[derive(Serialize, Debug)]
+struct RowGroup {
+    columns: Vec<ColumnChunk>,
+    row_count: i64,
+}
+
+#[derive(Serialize, Debug)]
+struct ColumnChunk {
+    path: String,
+    has_offset_index: bool,
+    has_column_index: bool,
+    has_bloom_filter: bool,
+    pages: Vec<Page>,
+}
+
+#[derive(Serialize, Debug)]
+struct Page {
+    compression: Option<&'static str>,
+    encoding: &'static str,
+    page_type: &'static str,
+    compressed_bytes: i32,
+    uncompressed_bytes: i32,
+    header_bytes: i32,
+    num_values: i32,
+}
+
+fn do_layout<C: ChunkReader>(reader: &C) -> Result<ParquetFile> {
+    let metadata = parquet::file::footer::parse_metadata(reader)?;
+    let schema = metadata.file_metadata().schema_descr();
+
+    let row_groups = (0..metadata.num_row_groups())
+        .map(|row_group_idx| {
+            let row_group = metadata.row_group(row_group_idx);
+            let columns = row_group
+                .columns()
+                .iter()
+                .zip(schema.columns())
+                .map(|(column, column_schema)| {
+                    let compression = compression(column.compression());
+                    let mut pages = vec![];
+
+                    let mut start = column
+                        .dictionary_page_offset()
+                        .unwrap_or_else(|| column.data_page_offset())
+                        as u64;
+
+                    let end = start + column.compressed_size() as u64;
+                    while start != end {
+                        let (header_len, header) = read_page_header(reader, start)?;
+                        if let Some(dictionary) = header.dictionary_page_header {
+                            pages.push(Page {
+                                compression,
+                                encoding: encoding(dictionary.encoding),
+                                page_type: "dictionary",
+                                compressed_bytes: header.compressed_page_size,
+                                uncompressed_bytes: header.uncompressed_page_size,
+                                header_bytes: header_len as _,
+                                num_values: dictionary.num_values,
+                            })
+                        } else if let Some(data_page) = header.data_page_header {
+                            pages.push(Page {
+                                compression,
+                                encoding: encoding(data_page.encoding),
+                                page_type: "data_page_v1",
+                                compressed_bytes: header.compressed_page_size,
+                                uncompressed_bytes: header.uncompressed_page_size,
+                                header_bytes: header_len as _,
+                                num_values: data_page.num_values,
+                            })
+                        } else if let Some(data_page) = header.data_page_header_v2 {
+                            let is_compressed = data_page.is_compressed.unwrap_or(true);

Review Comment:
   is it really compressed by default? I expected `unwrap_or(false)`



##########
parquet/src/bin/parquet-layout.rs:
##########
@@ -0,0 +1,234 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Binary that prints the physical layout of a parquet file
+//!
+//! # Install
+//!
+//! `parquet-layout` can be installed using `cargo`:
+//! ```
+//! cargo install parquet --features=cli
+//! ```
+//! After this `parquet-layout` should be available:
+//! ```
+//! parquet-layout XYZ.parquet
+//! ```
+//!
+//! The binary can also be built from the source code and run as follows:
+//! ```
+//! cargo run --features=cli --bin parquet-layout XYZ.parquet
+//! ```
+
+use std::fs::File;
+use std::io::Read;
+
+use clap::Parser;
+use serde::Serialize;
+use thrift::protocol::{TCompactInputProtocol, TSerializable};
+
+use parquet::basic::{Compression, Encoding};
+use parquet::errors::Result;
+use parquet::file::reader::ChunkReader;
+use parquet::format::PageHeader;
+
+#[derive(Serialize, Debug)]
+struct ParquetFile {
+    row_groups: Vec<RowGroup>,
+}
+
+#[derive(Serialize, Debug)]
+struct RowGroup {
+    columns: Vec<ColumnChunk>,
+    row_count: i64,
+}
+
+#[derive(Serialize, Debug)]
+struct ColumnChunk {
+    path: String,
+    has_offset_index: bool,
+    has_column_index: bool,
+    has_bloom_filter: bool,
+    pages: Vec<Page>,
+}
+
+#[derive(Serialize, Debug)]
+struct Page {
+    compression: Option<&'static str>,
+    encoding: &'static str,
+    page_type: &'static str,
+    compressed_bytes: i32,
+    uncompressed_bytes: i32,
+    header_bytes: i32,
+    num_values: i32,
+}
+
+fn do_layout<C: ChunkReader>(reader: &C) -> Result<ParquetFile> {
+    let metadata = parquet::file::footer::parse_metadata(reader)?;
+    let schema = metadata.file_metadata().schema_descr();
+
+    let row_groups = (0..metadata.num_row_groups())
+        .map(|row_group_idx| {
+            let row_group = metadata.row_group(row_group_idx);
+            let columns = row_group
+                .columns()
+                .iter()
+                .zip(schema.columns())
+                .map(|(column, column_schema)| {
+                    let compression = compression(column.compression());
+                    let mut pages = vec![];
+
+                    let mut start = column
+                        .dictionary_page_offset()
+                        .unwrap_or_else(|| column.data_page_offset())
+                        as u64;
+
+                    let end = start + column.compressed_size() as u64;
+                    while start != end {
+                        let (header_len, header) = read_page_header(reader, start)?;

Review Comment:
   this is neat 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #3269: Add parquet-layout binary

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #3269:
URL: https://github.com/apache/arrow-rs/pull/3269


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3269: Add parquet-layout binary

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3269:
URL: https://github.com/apache/arrow-rs/pull/3269#discussion_r1040148309


##########
parquet/src/bin/parquet-layout.rs:
##########
@@ -0,0 +1,234 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Binary that prints the physical layout of a parquet file
+//!
+//! # Install
+//!
+//! `parquet-layout` can be installed using `cargo`:
+//! ```
+//! cargo install parquet --features=cli
+//! ```
+//! After this `parquet-layout` should be available:
+//! ```
+//! parquet-layout XYZ.parquet
+//! ```
+//!
+//! The binary can also be built from the source code and run as follows:
+//! ```
+//! cargo run --features=cli --bin parquet-layout XYZ.parquet
+//! ```
+
+use std::fs::File;
+use std::io::Read;
+
+use clap::Parser;
+use serde::Serialize;
+use thrift::protocol::{TCompactInputProtocol, TSerializable};
+
+use parquet::basic::{Compression, Encoding};
+use parquet::errors::Result;
+use parquet::file::reader::ChunkReader;
+use parquet::format::PageHeader;
+
+#[derive(Serialize, Debug)]
+struct ParquetFile {
+    row_groups: Vec<RowGroup>,
+}
+
+#[derive(Serialize, Debug)]
+struct RowGroup {
+    columns: Vec<ColumnChunk>,
+    row_count: i64,
+}
+
+#[derive(Serialize, Debug)]
+struct ColumnChunk {
+    path: String,
+    has_offset_index: bool,
+    has_column_index: bool,
+    has_bloom_filter: bool,
+    pages: Vec<Page>,
+}
+
+#[derive(Serialize, Debug)]
+struct Page {
+    compression: Option<&'static str>,
+    encoding: &'static str,
+    page_type: &'static str,
+    compressed_bytes: i32,
+    uncompressed_bytes: i32,
+    header_bytes: i32,
+    num_values: i32,
+}
+
+fn do_layout<C: ChunkReader>(reader: &C) -> Result<ParquetFile> {
+    let metadata = parquet::file::footer::parse_metadata(reader)?;
+    let schema = metadata.file_metadata().schema_descr();
+
+    let row_groups = (0..metadata.num_row_groups())
+        .map(|row_group_idx| {
+            let row_group = metadata.row_group(row_group_idx);
+            let columns = row_group
+                .columns()
+                .iter()
+                .zip(schema.columns())
+                .map(|(column, column_schema)| {
+                    let compression = compression(column.compression());
+                    let mut pages = vec![];
+
+                    let mut start = column
+                        .dictionary_page_offset()
+                        .unwrap_or_else(|| column.data_page_offset())
+                        as u64;
+
+                    let end = start + column.compressed_size() as u64;
+                    while start != end {
+                        let (header_len, header) = read_page_header(reader, start)?;
+                        if let Some(dictionary) = header.dictionary_page_header {
+                            pages.push(Page {
+                                compression,
+                                encoding: encoding(dictionary.encoding),
+                                page_type: "dictionary",
+                                compressed_bytes: header.compressed_page_size,
+                                uncompressed_bytes: header.uncompressed_page_size,
+                                header_bytes: header_len as _,
+                                num_values: dictionary.num_values,
+                            })
+                        } else if let Some(data_page) = header.data_page_header {
+                            pages.push(Page {
+                                compression,
+                                encoding: encoding(data_page.encoding),
+                                page_type: "data_page_v1",
+                                compressed_bytes: header.compressed_page_size,
+                                uncompressed_bytes: header.uncompressed_page_size,
+                                header_bytes: header_len as _,
+                                num_values: data_page.num_values,
+                            })
+                        } else if let Some(data_page) = header.data_page_header_v2 {
+                            let is_compressed = data_page.is_compressed.unwrap_or(true);

Review Comment:
   If the column is compressed, and the header doesn't specify, the default is compressed. I think this was a later extension to make it optional



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on pull request #3269: Add parquet-layout binary

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #3269:
URL: https://github.com/apache/arrow-rs/pull/3269#issuecomment-1336572912

   I will review this tomorrow -- the other one I know of is https://github.com/manojkarthick/pqrs which shows promise


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org