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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
18 #include <gtest/gtest.h>
22 #include "arrow/buffer.h"
23 #include "arrow/io/memory.h"
25 #include "parquet/file_reader.h"
26 #include "parquet/properties.h"
30 using schema::ColumnPath
;
34 TEST(TestReaderProperties
, Basics
) {
35 ReaderProperties props
;
37 ASSERT_EQ(props
.buffer_size(), kDefaultBufferSize
);
38 ASSERT_FALSE(props
.is_buffered_stream_enabled());
41 TEST(TestWriterProperties
, Basics
) {
42 std::shared_ptr
<WriterProperties
> props
= WriterProperties::Builder().build();
44 ASSERT_EQ(kDefaultDataPageSize
, props
->data_pagesize());
45 ASSERT_EQ(DEFAULT_DICTIONARY_PAGE_SIZE_LIMIT
, props
->dictionary_pagesize_limit());
46 ASSERT_EQ(ParquetVersion::PARQUET_1_0
, props
->version());
47 ASSERT_EQ(ParquetDataPageVersion::V1
, props
->data_page_version());
50 TEST(TestWriterProperties
, AdvancedHandling
) {
51 WriterProperties::Builder builder
;
52 builder
.compression("gzip", Compression::GZIP
);
53 builder
.compression("zstd", Compression::ZSTD
);
54 builder
.compression(Compression::SNAPPY
);
55 builder
.encoding(Encoding::DELTA_BINARY_PACKED
);
56 builder
.encoding("delta-length", Encoding::DELTA_LENGTH_BYTE_ARRAY
);
57 builder
.data_page_version(ParquetDataPageVersion::V2
);
58 std::shared_ptr
<WriterProperties
> props
= builder
.build();
60 ASSERT_EQ(Compression::GZIP
, props
->compression(ColumnPath::FromDotString("gzip")));
61 ASSERT_EQ(Compression::ZSTD
, props
->compression(ColumnPath::FromDotString("zstd")));
62 ASSERT_EQ(Compression::SNAPPY
,
63 props
->compression(ColumnPath::FromDotString("delta-length")));
64 ASSERT_EQ(Encoding::DELTA_BINARY_PACKED
,
65 props
->encoding(ColumnPath::FromDotString("gzip")));
66 ASSERT_EQ(Encoding::DELTA_LENGTH_BYTE_ARRAY
,
67 props
->encoding(ColumnPath::FromDotString("delta-length")));
68 ASSERT_EQ(ParquetDataPageVersion::V2
, props
->data_page_version());
71 TEST(TestReaderProperties
, GetStreamInsufficientData
) {
73 std::string data
= "shorter than expected";
74 auto buf
= std::make_shared
<Buffer
>(data
);
75 auto reader
= std::make_shared
<::arrow::io::BufferReader
>(buf
);
77 ReaderProperties props
;
79 ARROW_UNUSED(props
.GetStream(reader
, 12, 15));
80 FAIL() << "No exception raised";
81 } catch (const ParquetException
& e
) {
83 ("Tried reading 15 bytes starting at position 12"
84 " from file but only got 9");
85 ASSERT_EQ(ex_what
, e
.what());
90 } // namespace parquet