]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/test/dataset/test-scanner-builder.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / c_glib / test / dataset / test-scanner-builder.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 TestDatasetScannerBuilder < Test::Unit::TestCase
19 include Helper::Buildable
20 include Helper::Writable
21
22 def setup
23 omit("Arrow Dataset is required") unless defined?(ArrowDataset)
24 Dir.mktmpdir do |tmpdir|
25 path = File.join(tmpdir, "table.arrow")
26 @table = build_table(visible: [
27 build_boolean_array([true, false, true]),
28 build_boolean_array([false, true, false, true]),
29 ],
30 point: [
31 build_int32_array([1, 2, 3]),
32 build_int32_array([-1, -2, -3, -4]),
33 ])
34 @format = ArrowDataset::IPCFileFormat.new
35 write_table(@table, path)
36 factory = ArrowDataset::FileSystemDatasetFactory.new(@format)
37 factory.file_system_uri = build_file_uri(path)
38 @dataset = factory.finish
39 @builder = @dataset.begin_scan
40 yield
41 end
42 end
43
44 def test_new_record_batch_reader
45 reader = Arrow::TableBatchReader.new(@table)
46 builder = ArrowDataset::ScannerBuilder.new(reader)
47 scanner = builder.finish
48 assert_equal(@table, scanner.to_table)
49 end
50
51 def test_filter
52 visible = Arrow::FieldExpression.new("visible")
53 true_scalar = Arrow::BooleanScalar.new(true)
54 true_datum = Arrow::ScalarDatum.new(true_scalar)
55 true_literal = Arrow::LiteralExpression.new(true_datum)
56 filter = Arrow::CallExpression.new("equal", [visible, true_literal])
57 @builder.filter = filter
58 scanner = @builder.finish
59 assert_equal(build_table(visible: [
60 build_boolean_array([true, true]),
61 build_boolean_array([true, true]),
62 ],
63 point: [
64 build_int32_array([1, 3]),
65 build_int32_array([-2, -4]),
66 ]),
67 scanner.to_table)
68 end
69
70 def test_use_async
71 @builder.use_async = true
72 scanner = @builder.finish
73 assert_equal(@table, scanner.to_table)
74 end
75 end