]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/test/parquet/test-arrow-file-reader.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / c_glib / test / parquet / test-arrow-file-reader.rb
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 class TestParquetArrowFileReader < Test::Unit::TestCase
19 include Helper::Buildable
20
21 def setup
22 omit("Parquet is required") unless defined?(::Parquet)
23 @file = Tempfile.open(["data", ".parquet"])
24 @a_array = build_string_array(["foo", "bar"])
25 @b_array = build_int32_array([123, 456])
26 @table = build_table("a" => @a_array,
27 "b" => @b_array)
28 writer = Parquet::ArrowFileWriter.new(@table.schema, @file.path)
29 chunk_size = 1
30 writer.write_table(@table, chunk_size)
31 writer.close
32 @reader = Parquet::ArrowFileReader.new(@file.path)
33 end
34
35 def test_schema
36 assert_equal(<<-SCHEMA.chomp, @reader.schema.to_s)
37 a: string
38 b: int32
39 SCHEMA
40 end
41
42 sub_test_case("#read_row_group") do
43 test("with column indices") do
44 assert_equal(build_table("b" => @b_array.slice(0, 1)),
45 @reader.read_row_group(0, [-1]))
46 end
47
48 test("without column indices") do
49 assert_equal(build_table("a" => @a_array.slice(1, 1),
50 "b" => @b_array.slice(1, 1)),
51 @reader.read_row_group(1))
52 end
53 end
54
55 def test_read_column
56 assert_equal([
57 Arrow::ChunkedArray.new([@a_array]),
58 Arrow::ChunkedArray.new([@b_array]),
59 ],
60 [
61 @reader.read_column_data(0),
62 @reader.read_column_data(-1),
63 ])
64 end
65
66 def test_n_rows
67 assert_equal(2, @reader.n_rows)
68 end
69 end