]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow-dataset/lib/arrow-dataset/arrow-table-loadable.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / ruby / red-arrow-dataset / lib / arrow-dataset / arrow-table-loadable.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 module ArrowDataset
19 module ArrowTableLoadable
20 private
21 def path_to_uri(path)
22 absolute_path = ::File.expand_path(path)
23 if absolute_path.start_with?("/")
24 URI("file://#{absolute_path}")
25 else
26 URI("file:///#{absolute_path}")
27 end
28 end
29
30 def load_from_directory
31 internal_load_from_uri(path_to_uri(@input))
32 end
33
34 def load_from_uri
35 internal_load_from_uri(@input)
36 end
37
38 def internal_load_from_uri(uri)
39 format = FileFormat.resolve(@options[:format])
40 dataset = FileSystemDataset.build(format) do |factory|
41 factory.file_system_uri = uri
42 end
43 scanner_builder = dataset.begin_scan
44 @options.each do |key, value|
45 next if key == :format
46 next if value.nil?
47 setter = "#{key}="
48 next unless scanner_builder.respond_to?(setter)
49 scanner_builder.public_send(setter, value)
50 end
51 scanner = scanner_builder.finish
52 scanner.to_table
53 end
54 end
55 end
56
57 module Arrow
58 class TableLoader
59 include ArrowDataset::ArrowTableLoadable
60 end
61 end