]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/parquet/properties_test.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / parquet / properties_test.cc
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 #include <gtest/gtest.h>
19
20 #include <string>
21
22 #include "arrow/buffer.h"
23 #include "arrow/io/memory.h"
24
25 #include "parquet/file_reader.h"
26 #include "parquet/properties.h"
27
28 namespace parquet {
29
30 using schema::ColumnPath;
31
32 namespace test {
33
34 TEST(TestReaderProperties, Basics) {
35 ReaderProperties props;
36
37 ASSERT_EQ(props.buffer_size(), kDefaultBufferSize);
38 ASSERT_FALSE(props.is_buffered_stream_enabled());
39 }
40
41 TEST(TestWriterProperties, Basics) {
42 std::shared_ptr<WriterProperties> props = WriterProperties::Builder().build();
43
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());
48 }
49
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();
59
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());
69 }
70
71 TEST(TestReaderProperties, GetStreamInsufficientData) {
72 // ARROW-6058
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);
76
77 ReaderProperties props;
78 try {
79 ARROW_UNUSED(props.GetStream(reader, 12, 15));
80 FAIL() << "No exception raised";
81 } catch (const ParquetException& e) {
82 std::string ex_what =
83 ("Tried reading 15 bytes starting at position 12"
84 " from file but only got 9");
85 ASSERT_EQ(ex_what, e.what());
86 }
87 }
88
89 } // namespace test
90 } // namespace parquet