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 class TestDatasetScannerBuilder
< Test
::Unit::TestCase
19 include Helper
::Buildable
20 include Helper
::Writable
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]),
31 build_int32_array([1, 2, 3]),
32 build_int32_array([-1, -2, -3, -4]),
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
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
)
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]),
64 build_int32_array([1, 3]),
65 build_int32_array([-2, -4]),
71 @builder.use_async
= true
72 scanner
= @builder.finish
73 assert_equal(@table, scanner
.to_table
)