red-arrow 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/text/news.md +10 -0
- data/lib/arrow/array.rb +4 -0
- data/lib/arrow/{block-openable.rb → block-closable.rb} +2 -3
- data/lib/arrow/compatibility.rb +28 -0
- data/lib/arrow/file-reader.rb +53 -0
- data/lib/arrow/loader.rb +8 -5
- data/lib/arrow/record.rb +8 -0
- data/lib/arrow/{ipc-file-reader.rb → stream-reader.rb} +7 -7
- data/lib/arrow/{ipc-stream-reader.rb → tensor.rb} +3 -11
- data/lib/arrow/version.rb +1 -1
- data/test/helper.rb +2 -0
- data/test/test-file-reader.rb +112 -0
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d66932ddc8b1edd4d0a00a3c44ace6a54eb23509
|
4
|
+
data.tar.gz: d373ca2d306387a5709e8b2b28946e10ec5529ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d018d51d091d4ad37cd608f4bd951a837b385d36cf975a0a0652a5d1173a847aa2f875705e46d66e533b8246d5f3b0b0b75d936fdcdd2e794e1676463759bd66
|
7
|
+
data.tar.gz: 434cd73edc6180de459d9bfa95272703d7d0ffb1a095ea7e7f64462880bae79cdb14ccadbcd8285966462832c80c8837a55c26c79e424c9160ceb9e719989639
|
data/doc/text/news.md
CHANGED
data/lib/arrow/array.rb
CHANGED
@@ -13,11 +13,10 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module Arrow
|
16
|
-
module
|
16
|
+
module BlockClosable
|
17
17
|
def open(*args, &block)
|
18
|
-
io =
|
18
|
+
io = new(*args)
|
19
19
|
return io unless block
|
20
|
-
return yield(io) unless io.respond_to?(:close)
|
21
20
|
|
22
21
|
begin
|
23
22
|
yield(io)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Arrow
|
16
|
+
if const_defined?(:MemoryMappedInputStream)
|
17
|
+
class MemoryMappedFile
|
18
|
+
class << self
|
19
|
+
def open(path, mode, &block)
|
20
|
+
warn("#{self}.#{__method__}(path, mode, &block): " +
|
21
|
+
"use #{MemoryMappedInputStream}.open(path, &block) instead: " +
|
22
|
+
caller(1, 1)[0])
|
23
|
+
MemoryMappedInputStream.open(path, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Arrow
|
16
|
+
class FileReader
|
17
|
+
include Enumerable
|
18
|
+
|
19
|
+
# For backward compatibility
|
20
|
+
if respond_to?(:open)
|
21
|
+
class << self
|
22
|
+
alias_method :open_raw, :open
|
23
|
+
def open(input)
|
24
|
+
warn("#{self}.#{__method__}: use #{self}.new instead: #{caller(1, 1)[0]}")
|
25
|
+
reader = open_raw(input)
|
26
|
+
if block_given?
|
27
|
+
yield(reader)
|
28
|
+
else
|
29
|
+
reader
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
class << self
|
35
|
+
def open(input)
|
36
|
+
warn("#{self}.#{__method__}: use #{self}.new instead #{caller(1, 1)[0]}")
|
37
|
+
reader = new(input)
|
38
|
+
if block_given?
|
39
|
+
yield(reader)
|
40
|
+
else
|
41
|
+
reader
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def each
|
48
|
+
n_record_batches.times do |i|
|
49
|
+
yield(get_record_batch(i))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/arrow/loader.rb
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require "arrow/block-
|
15
|
+
require "arrow/block-closable"
|
16
16
|
|
17
17
|
module Arrow
|
18
18
|
class Loader < GObjectIntrospection::Loader
|
@@ -32,17 +32,20 @@ module Arrow
|
|
32
32
|
require "arrow/array-builder"
|
33
33
|
require "arrow/field"
|
34
34
|
require "arrow/record-batch"
|
35
|
+
require "arrow/tensor"
|
35
36
|
|
36
|
-
require "arrow/
|
37
|
-
require "arrow/
|
37
|
+
require "arrow/file-reader"
|
38
|
+
require "arrow/stream-reader"
|
39
|
+
|
40
|
+
require "arrow/compatibility"
|
38
41
|
end
|
39
42
|
|
40
43
|
def load_object_info(info)
|
41
44
|
super
|
42
45
|
|
43
46
|
klass = @base_module.const_get(rubyish_class_name(info))
|
44
|
-
if klass.
|
45
|
-
klass.
|
47
|
+
if klass.method_defined?(:close)
|
48
|
+
klass.extend(BlockClosable)
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
data/lib/arrow/record.rb
CHANGED
@@ -13,14 +13,14 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module Arrow
|
16
|
-
|
17
|
-
|
18
|
-
include Enumerable
|
16
|
+
class StreamReader
|
17
|
+
include Enumerable
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def each
|
20
|
+
loop do
|
21
|
+
record_batch = next_record_batch
|
22
|
+
break if record_batch.nil?
|
23
|
+
yield(record_batch)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -13,17 +13,9 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module Arrow
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def each
|
21
|
-
loop do
|
22
|
-
record_batch = next_record_batch
|
23
|
-
break if record_batch.nil?
|
24
|
-
yield(record_batch)
|
25
|
-
end
|
26
|
-
end
|
16
|
+
class Tensor
|
17
|
+
def to_arrow
|
18
|
+
self
|
27
19
|
end
|
28
20
|
end
|
29
21
|
end
|
data/lib/arrow/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Copyright 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
class FileReaderTest < Test::Unit::TestCase
|
16
|
+
test("write/read") do
|
17
|
+
fields = [
|
18
|
+
Arrow::Field.new("uint8", :uint8),
|
19
|
+
Arrow::Field.new("uint16", :uint16),
|
20
|
+
Arrow::Field.new("uint32", :uint32),
|
21
|
+
Arrow::Field.new("uint64", :uint64),
|
22
|
+
Arrow::Field.new("int8", :int8),
|
23
|
+
Arrow::Field.new("int16", :int16),
|
24
|
+
Arrow::Field.new("int32", :int32),
|
25
|
+
Arrow::Field.new("int64", :int64),
|
26
|
+
Arrow::Field.new("float", :float),
|
27
|
+
Arrow::Field.new("double", :double),
|
28
|
+
]
|
29
|
+
schema = Arrow::Schema.new(fields)
|
30
|
+
|
31
|
+
tempfile = Tempfile.new(["batch", ".arrow"])
|
32
|
+
Arrow::FileOutputStream.open(tempfile.path, false) do |output|
|
33
|
+
Arrow::FileWriter.open(output, schema) do |writer|
|
34
|
+
uints = [1, 2, 4, 8]
|
35
|
+
ints = [1, -2, 4, -8]
|
36
|
+
floats = [1.1, -2.2, 4.4, -8.8]
|
37
|
+
columns = [
|
38
|
+
Arrow::UInt8Array.new(uints),
|
39
|
+
Arrow::UInt16Array.new(uints),
|
40
|
+
Arrow::UInt32Array.new(uints),
|
41
|
+
Arrow::UInt64Array.new(uints),
|
42
|
+
Arrow::Int8Array.new(ints),
|
43
|
+
Arrow::Int16Array.new(ints),
|
44
|
+
Arrow::Int32Array.new(ints),
|
45
|
+
Arrow::Int64Array.new(ints),
|
46
|
+
Arrow::FloatArray.new(floats),
|
47
|
+
Arrow::DoubleArray.new(floats),
|
48
|
+
]
|
49
|
+
|
50
|
+
record_batch = Arrow::RecordBatch.new(schema, 4, columns)
|
51
|
+
writer.write_record_batch(record_batch)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Arrow::MemoryMappedInputStream.open(tempfile.path) do |input|
|
56
|
+
reader = Arrow::FileReader.new(input)
|
57
|
+
reader.each do |record_batch|
|
58
|
+
assert_equal([
|
59
|
+
{
|
60
|
+
"uint8" => 1,
|
61
|
+
"uint16" => 1,
|
62
|
+
"uint32" => 1,
|
63
|
+
"uint64" => 1,
|
64
|
+
"int8" => 1,
|
65
|
+
"int16" => 1,
|
66
|
+
"int32" => 1,
|
67
|
+
"int64" => 1,
|
68
|
+
"float" => 1.100000023841858,
|
69
|
+
"double" => 1.1,
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"uint8" => 2,
|
73
|
+
"uint16" => 2,
|
74
|
+
"uint32" => 2,
|
75
|
+
"uint64" => 2,
|
76
|
+
"int8" => -2,
|
77
|
+
"int16" => -2,
|
78
|
+
"int32" => -2,
|
79
|
+
"int64" => -2,
|
80
|
+
"float" => -2.200000047683716,
|
81
|
+
"double" => -2.2,
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"uint8" => 4,
|
85
|
+
"uint16" => 4,
|
86
|
+
"uint32" => 4,
|
87
|
+
"uint64" => 4,
|
88
|
+
"int8" => 4,
|
89
|
+
"int16" => 4,
|
90
|
+
"int32" => 4,
|
91
|
+
"int64" => 4,
|
92
|
+
"float" => 4.400000095367432,
|
93
|
+
"double" => 4.4,
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"uint8" => 8,
|
97
|
+
"uint16" => 8,
|
98
|
+
"uint32" => 8,
|
99
|
+
"uint64" => 8,
|
100
|
+
"int8" => -8,
|
101
|
+
"int16" => -8,
|
102
|
+
"int32" => -8,
|
103
|
+
"int64" => -8,
|
104
|
+
"float" => -8.800000190734863,
|
105
|
+
"double" => -8.8,
|
106
|
+
},
|
107
|
+
],
|
108
|
+
record_batch.collect(&:to_h))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red-arrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gobject-introspection
|
@@ -111,18 +111,21 @@ files:
|
|
111
111
|
- lib/arrow.rb
|
112
112
|
- lib/arrow/array-builder.rb
|
113
113
|
- lib/arrow/array.rb
|
114
|
-
- lib/arrow/block-
|
114
|
+
- lib/arrow/block-closable.rb
|
115
|
+
- lib/arrow/compatibility.rb
|
115
116
|
- lib/arrow/field.rb
|
116
|
-
- lib/arrow/
|
117
|
-
- lib/arrow/ipc-stream-reader.rb
|
117
|
+
- lib/arrow/file-reader.rb
|
118
118
|
- lib/arrow/loader.rb
|
119
119
|
- lib/arrow/record-batch.rb
|
120
120
|
- lib/arrow/record.rb
|
121
|
+
- lib/arrow/stream-reader.rb
|
122
|
+
- lib/arrow/tensor.rb
|
121
123
|
- lib/arrow/version.rb
|
122
124
|
- red-arrow.gemspec
|
123
125
|
- test/helper.rb
|
124
126
|
- test/run-test.rb
|
125
127
|
- test/test-array.rb
|
128
|
+
- test/test-file-reader.rb
|
126
129
|
- test/test-record-batch.rb
|
127
130
|
homepage: https://github.com/red-data-tools/red-arrow
|
128
131
|
licenses:
|
@@ -154,3 +157,4 @@ test_files:
|
|
154
157
|
- test/helper.rb
|
155
158
|
- test/run-test.rb
|
156
159
|
- test/test-array.rb
|
160
|
+
- test/test-file-reader.rb
|