|
| 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 | +//! This file contains an end to end test for verifying checksums when reading parquet files. |
| 19 | +
|
| 20 | +use std::path::PathBuf; |
| 21 | + |
| 22 | +use arrow::util::test_util::parquet_test_data; |
| 23 | +use parquet::arrow::arrow_reader::ArrowReaderBuilder; |
| 24 | + |
| 25 | +#[test] |
| 26 | +fn test_datapage_v1_corrupt_checksum() { |
| 27 | + let errors = read_file_batch_errors("datapage_v1-corrupt-checksum.parquet"); |
| 28 | + assert_eq!(errors, [ |
| 29 | + Err("Parquet argument error: Parquet error: Page CRC checksum mismatch".to_string()), |
| 30 | + Ok(()), |
| 31 | + Ok(()), |
| 32 | + Err("Parquet argument error: Parquet error: Page CRC checksum mismatch".to_string()), |
| 33 | + Err("Parquet argument error: Parquet error: Not all children array length are the same!".to_string()) |
| 34 | + ]); |
| 35 | +} |
| 36 | + |
| 37 | +#[test] |
| 38 | +fn test_datapage_v1_uncompressed_checksum() { |
| 39 | + let errors = read_file_batch_errors("datapage_v1-uncompressed-checksum.parquet"); |
| 40 | + assert_eq!(errors, [Ok(()), Ok(()), Ok(()), Ok(()), Ok(())]); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn test_datapage_v1_snappy_compressed_checksum() { |
| 45 | + let errors = read_file_batch_errors("datapage_v1-snappy-compressed-checksum.parquet"); |
| 46 | + assert_eq!(errors, [Ok(()), Ok(()), Ok(()), Ok(()), Ok(())]); |
| 47 | +} |
| 48 | + |
| 49 | +#[test] |
| 50 | +fn test_plain_dict_uncompressed_checksum() { |
| 51 | + let errors = read_file_batch_errors("plain-dict-uncompressed-checksum.parquet"); |
| 52 | + assert_eq!(errors, [Ok(())]); |
| 53 | +} |
| 54 | +#[test] |
| 55 | +fn test_rle_dict_snappy_checksum() { |
| 56 | + let errors = read_file_batch_errors("rle-dict-snappy-checksum.parquet"); |
| 57 | + assert_eq!(errors, [Ok(())]); |
| 58 | +} |
| 59 | + |
| 60 | +/// Reads a file and returns a vector with one element per record batch. |
| 61 | +/// The record batch data is replaced with () and errors are stringified. |
| 62 | +fn read_file_batch_errors(name: &str) -> Vec<Result<(), String>> { |
| 63 | + let path = PathBuf::from(parquet_test_data()).join(name); |
| 64 | + println!("Reading file: {:?}", path); |
| 65 | + let file = std::fs::File::open(&path).unwrap(); |
| 66 | + let reader = ArrowReaderBuilder::try_new(file).unwrap().build().unwrap(); |
| 67 | + reader |
| 68 | + .map(|x| match x { |
| 69 | + Ok(_) => Ok(()), |
| 70 | + Err(e) => Err(e.to_string()), |
| 71 | + }) |
| 72 | + .collect() |
| 73 | +} |
0 commit comments