red-arrow-format 23.0.0 → 24.0.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/Gemfile +7 -2
- data/NOTICE.txt +1 -1
- data/Rakefile +23 -1
- data/lib/arrow-format/array.rb +486 -117
- data/lib/arrow-format/bitmap.rb +25 -6
- data/lib/arrow-format/buffer-alignable.rb +35 -0
- data/lib/arrow-format/dictionary.rb +29 -0
- data/lib/arrow-format/error.rb +1 -1
- data/lib/arrow-format/field.rb +24 -3
- data/lib/arrow-format/file-reader.rb +47 -25
- data/lib/arrow-format/file-writer.rb +56 -0
- data/lib/arrow-format/flatbuffers.rb +67 -0
- data/lib/arrow-format/org/apache/arrow/flatbuf/binary.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/binary_view.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/block.rb +10 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/body_compression.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/body_compression_method.rb +3 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/bool.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/buffer.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/compression_type.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/date.rb +7 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/date_unit.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/decimal.rb +9 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/dictionary_batch.rb +9 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/dictionary_encoding.rb +11 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/dictionary_kind.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/duration.rb +7 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/endianness.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/feature.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/field.rb +13 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/field_node.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/fixed_size_binary.rb +7 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/fixed_size_list.rb +7 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/floating_point.rb +7 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/footer.rb +22 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/int.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/interval.rb +7 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/interval_unit.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/key_value.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/large_binary.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/large_list.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/large_list_view.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/large_utf8.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/list.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/list_view.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/map.rb +8 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/message.rb +22 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/message_header.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/metadata_version.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/null.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/precision.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/record_batch.rb +12 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/run_end_encoded.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/schema.rb +10 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/sparse_matrix_compressed_axis.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/sparse_matrix_index_csx.rb +12 -2
- data/lib/arrow-format/org/apache/arrow/flatbuf/sparse_tensor.rb +13 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/sparse_tensor_index.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/sparse_tensor_index_coo.rb +13 -4
- data/lib/arrow-format/org/apache/arrow/flatbuf/sparse_tensor_index_csf.rb +14 -4
- data/lib/arrow-format/org/apache/arrow/flatbuf/struct_.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/tensor.rb +11 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/tensor_dim.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/time.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/time_unit.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/timestamp.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/type.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/union.rb +8 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/union_mode.rb +1 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/utf8.rb +5 -1
- data/lib/arrow-format/org/apache/arrow/flatbuf/utf8view.rb +5 -1
- data/lib/arrow-format/readable.rb +151 -96
- data/lib/arrow-format/record-batch.rb +70 -1
- data/lib/arrow-format/schema.rb +14 -1
- data/lib/arrow-format/streaming-pull-reader.rb +49 -23
- data/lib/arrow-format/streaming-reader.rb +51 -14
- data/lib/arrow-format/streaming-writer.rb +156 -0
- data/lib/arrow-format/type.rb +397 -34
- data/lib/arrow-format/version.rb +1 -1
- data/lib/arrow-format.rb +2 -0
- data/red-arrow-format.gemspec +2 -1
- metadata +9 -4
data/lib/arrow-format/bitmap.rb
CHANGED
|
@@ -18,27 +18,46 @@ module ArrowFormat
|
|
|
18
18
|
class Bitmap
|
|
19
19
|
include Enumerable
|
|
20
20
|
|
|
21
|
-
def initialize(buffer, n_values)
|
|
21
|
+
def initialize(buffer, offset, n_values)
|
|
22
22
|
@buffer = buffer
|
|
23
|
+
@offset = offset
|
|
23
24
|
@n_values = n_values
|
|
24
25
|
end
|
|
25
26
|
|
|
27
|
+
def [](i)
|
|
28
|
+
i += @offset
|
|
29
|
+
(@buffer.get_value(:U8, i / 8) & (1 << (i % 8))) > 0
|
|
30
|
+
end
|
|
31
|
+
|
|
26
32
|
def each
|
|
27
33
|
return to_enum(__method__) unless block_given?
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
# TODO: Optimize
|
|
36
|
+
current = -1
|
|
37
|
+
n_bytes = (@offset + @n_values) / 8
|
|
30
38
|
@buffer.each(:U8, 0, n_bytes) do |offset, value|
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
8.times do |i|
|
|
40
|
+
current += 1
|
|
41
|
+
next if current < @offset
|
|
42
|
+
yield((value & (1 << (i % 8))) > 0)
|
|
33
43
|
end
|
|
34
44
|
end
|
|
35
|
-
remained_bits = @n_values % 8
|
|
45
|
+
remained_bits = (@offset + @n_values) % 8
|
|
36
46
|
unless remained_bits.zero?
|
|
37
47
|
value = @buffer.get_value(:U8, n_bytes)
|
|
38
48
|
remained_bits.times do |i|
|
|
39
|
-
|
|
49
|
+
current += 1
|
|
50
|
+
next if current < @offset
|
|
51
|
+
yield((value & (1 << (i % 8))) > 0)
|
|
40
52
|
end
|
|
41
53
|
end
|
|
42
54
|
end
|
|
55
|
+
|
|
56
|
+
def popcount
|
|
57
|
+
# TODO: Optimize
|
|
58
|
+
count do |flaged|
|
|
59
|
+
flaged
|
|
60
|
+
end
|
|
61
|
+
end
|
|
43
62
|
end
|
|
44
63
|
end
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
require_relative "flatbuffers"
|
|
19
|
+
|
|
20
|
+
module ArrowFormat
|
|
21
|
+
module BufferAlignable
|
|
22
|
+
include FlatBuffers::Alignable
|
|
23
|
+
|
|
24
|
+
BUFFER_ALIGNMENT_SIZE = 64
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
def buffer_padding_size(buffer)
|
|
28
|
+
compute_padding_size(buffer.size, BUFFER_ALIGNMENT_SIZE)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def aligned_buffer_size(buffer)
|
|
32
|
+
buffer.size + buffer_padding_size(buffer)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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 ArrowFormat
|
|
19
|
+
class Dictionary
|
|
20
|
+
attr_reader :id
|
|
21
|
+
attr_reader :array
|
|
22
|
+
attr_reader :message_metadata
|
|
23
|
+
def initialize(id, array, message_metadata: nil)
|
|
24
|
+
@id = id
|
|
25
|
+
@array = array
|
|
26
|
+
@message_metadata = message_metadata
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/arrow-format/error.rb
CHANGED
data/lib/arrow-format/field.rb
CHANGED
|
@@ -18,16 +18,37 @@ module ArrowFormat
|
|
|
18
18
|
class Field
|
|
19
19
|
attr_reader :name
|
|
20
20
|
attr_reader :type
|
|
21
|
-
attr_reader :
|
|
22
|
-
def initialize(name,
|
|
21
|
+
attr_reader :metadata
|
|
22
|
+
def initialize(name,
|
|
23
|
+
type,
|
|
24
|
+
nullable: true,
|
|
25
|
+
metadata: nil)
|
|
23
26
|
@name = name
|
|
24
27
|
@type = type
|
|
25
28
|
@nullable = nullable
|
|
26
|
-
@
|
|
29
|
+
@metadata = metadata
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def nullable?
|
|
30
33
|
@nullable
|
|
31
34
|
end
|
|
35
|
+
|
|
36
|
+
def to_flatbuffers
|
|
37
|
+
fb_field = FB::Field::Data.new
|
|
38
|
+
fb_field.name = @name
|
|
39
|
+
fb_field.nullable = @nullable
|
|
40
|
+
if @type.respond_to?(:build_fb_field)
|
|
41
|
+
@type.build_fb_field(fb_field)
|
|
42
|
+
else
|
|
43
|
+
fb_field.type = @type.to_flatbuffers
|
|
44
|
+
end
|
|
45
|
+
if @type.respond_to?(:child)
|
|
46
|
+
fb_field.children = [@type.child.to_flatbuffers]
|
|
47
|
+
elsif @type.respond_to?(:children)
|
|
48
|
+
fb_field.children = @type.children.collect(&:to_flatbuffers)
|
|
49
|
+
end
|
|
50
|
+
fb_field.custom_metadata = FB.build_custom_metadata(@metadata)
|
|
51
|
+
fb_field
|
|
52
|
+
end
|
|
32
53
|
end
|
|
33
54
|
end
|
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
require_relative "streaming-reader"
|
|
19
19
|
|
|
20
|
-
require_relative "org/apache/arrow/flatbuf/block"
|
|
21
|
-
require_relative "org/apache/arrow/flatbuf/footer"
|
|
22
|
-
|
|
23
20
|
module ArrowFormat
|
|
24
21
|
class FileReader
|
|
25
22
|
include Enumerable
|
|
@@ -37,6 +34,8 @@ module ArrowFormat
|
|
|
37
34
|
FOOTER_SIZE_FORMAT = :s32
|
|
38
35
|
FOOTER_SIZE_SIZE = IO::Buffer.size_of(FOOTER_SIZE_FORMAT)
|
|
39
36
|
|
|
37
|
+
attr_reader :schema
|
|
38
|
+
attr_reader :metadata
|
|
40
39
|
def initialize(input)
|
|
41
40
|
case input
|
|
42
41
|
when IO
|
|
@@ -49,7 +48,8 @@ module ArrowFormat
|
|
|
49
48
|
|
|
50
49
|
validate
|
|
51
50
|
@footer = read_footer
|
|
52
|
-
@
|
|
51
|
+
@metadata = read_custom_metadata(@footer.custom_metadata)
|
|
52
|
+
@record_batch_blocks = @footer.record_batches || []
|
|
53
53
|
@schema = read_schema(@footer.schema)
|
|
54
54
|
@dictionaries = read_dictionaries
|
|
55
55
|
end
|
|
@@ -59,14 +59,18 @@ module ArrowFormat
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def read(i)
|
|
62
|
-
fb_message, body = read_block(@record_batch_blocks[i])
|
|
62
|
+
fb_message, body = read_block(@record_batch_blocks[i], :record_batch, i)
|
|
63
63
|
fb_header = fb_message.header
|
|
64
|
-
unless fb_header.is_a?(
|
|
64
|
+
unless fb_header.is_a?(FB::RecordBatch)
|
|
65
65
|
raise FileReadError.new(@buffer,
|
|
66
66
|
"Not a record batch message: #{i}: " +
|
|
67
67
|
fb_header.class.name)
|
|
68
68
|
end
|
|
69
|
-
read_record_batch(
|
|
69
|
+
read_record_batch(fb_message.version,
|
|
70
|
+
fb_header,
|
|
71
|
+
fb_message.custom_metadata,
|
|
72
|
+
@schema,
|
|
73
|
+
body)
|
|
70
74
|
end
|
|
71
75
|
|
|
72
76
|
def each
|
|
@@ -104,17 +108,21 @@ module ArrowFormat
|
|
|
104
108
|
footer_size = @buffer.get_value(FOOTER_SIZE_FORMAT, footer_size_offset)
|
|
105
109
|
footer_data = @buffer.slice(footer_size_offset - footer_size,
|
|
106
110
|
footer_size)
|
|
107
|
-
|
|
111
|
+
FB::Footer.new(footer_data)
|
|
108
112
|
end
|
|
109
113
|
|
|
110
|
-
def read_block(block)
|
|
114
|
+
def read_block(block, type, i)
|
|
111
115
|
offset = block.offset
|
|
112
116
|
|
|
113
|
-
# If we can report
|
|
117
|
+
# If we can report error information correctly, we can use
|
|
114
118
|
# MessagePullReader here.
|
|
115
119
|
#
|
|
116
120
|
# message_pull_reader = MessagePullReader.new do |message, body|
|
|
117
|
-
# return read_record_batch(message.
|
|
121
|
+
# return read_record_batch(message.version,
|
|
122
|
+
# message.header,
|
|
123
|
+
# message.custom_metadata,
|
|
124
|
+
# @schema,
|
|
125
|
+
# body)
|
|
118
126
|
# end
|
|
119
127
|
# chunk = @buffer.slice(offset,
|
|
120
128
|
# MessagePullReader::CONTINUATION_SIZE +
|
|
@@ -125,12 +133,18 @@ module ArrowFormat
|
|
|
125
133
|
|
|
126
134
|
continuation_size = CONTINUATION_BUFFER.size
|
|
127
135
|
continuation = @buffer.slice(offset, continuation_size)
|
|
128
|
-
|
|
136
|
+
if continuation == CONTINUATION_BUFFER
|
|
137
|
+
offset += continuation_size
|
|
138
|
+
elsif continuation.get_value(MessagePullReader::CONTINUATION_TYPE, 0) < 0
|
|
129
139
|
raise FileReadError.new(@buffer,
|
|
130
|
-
"Invalid continuation: #{i}: " +
|
|
140
|
+
"Invalid continuation: #{type}: #{i}: " +
|
|
131
141
|
continuation.inspect)
|
|
142
|
+
else
|
|
143
|
+
# For backward compatibility of data produced prior to version
|
|
144
|
+
# 0.15.0. It doesn't have continuation token. Ignore it and
|
|
145
|
+
# re-read it as metadata length.
|
|
146
|
+
continuation_size = 0
|
|
132
147
|
end
|
|
133
|
-
offset += continuation_size
|
|
134
148
|
|
|
135
149
|
metadata_length_type = MessagePullReader::METADATA_LENGTH_TYPE
|
|
136
150
|
metadata_length_size = MessagePullReader::METADATA_LENGTH_SIZE
|
|
@@ -141,14 +155,14 @@ module ArrowFormat
|
|
|
141
155
|
metadata_length_size
|
|
142
156
|
unless metadata_length == expected_metadata_length
|
|
143
157
|
raise FileReadError.new(@buffer,
|
|
144
|
-
"Invalid metadata length #{i}: " +
|
|
158
|
+
"Invalid metadata length: #{type}: #{i}: " +
|
|
145
159
|
"expected:#{expected_metadata_length} " +
|
|
146
160
|
"actual:#{metadata_length}")
|
|
147
161
|
end
|
|
148
162
|
offset += metadata_length_size
|
|
149
163
|
|
|
150
164
|
metadata = @buffer.slice(offset, metadata_length)
|
|
151
|
-
fb_message =
|
|
165
|
+
fb_message = FB::Message.new(metadata)
|
|
152
166
|
offset += metadata_length
|
|
153
167
|
|
|
154
168
|
body = @buffer.slice(offset, block.body_length)
|
|
@@ -163,14 +177,14 @@ module ArrowFormat
|
|
|
163
177
|
dictionary_fields = {}
|
|
164
178
|
@schema.fields.each do |field|
|
|
165
179
|
next unless field.type.is_a?(DictionaryType)
|
|
166
|
-
dictionary_fields[field.
|
|
180
|
+
dictionary_fields[field.type.id] = field
|
|
167
181
|
end
|
|
168
182
|
|
|
169
183
|
dictionaries = {}
|
|
170
|
-
dictionary_blocks.
|
|
171
|
-
fb_message, body = read_block(block)
|
|
184
|
+
dictionary_blocks.each_with_index do |block, i|
|
|
185
|
+
fb_message, body = read_block(block, :dictionary_block, i)
|
|
172
186
|
fb_header = fb_message.header
|
|
173
|
-
unless fb_header.is_a?(
|
|
187
|
+
unless fb_header.is_a?(FB::DictionaryBatch)
|
|
174
188
|
raise FileReadError.new(@buffer,
|
|
175
189
|
"Not a dictionary batch message: " +
|
|
176
190
|
fb_header.inspect)
|
|
@@ -195,18 +209,26 @@ module ArrowFormat
|
|
|
195
209
|
end
|
|
196
210
|
|
|
197
211
|
value_type = dictionary_fields[id].type.value_type
|
|
198
|
-
schema = Schema.new([Field.new("dummy", value_type
|
|
199
|
-
record_batch = read_record_batch(
|
|
212
|
+
schema = Schema.new([Field.new("dummy", value_type)])
|
|
213
|
+
record_batch = read_record_batch(fb_message.version,
|
|
214
|
+
fb_header.data,
|
|
215
|
+
nil,
|
|
216
|
+
schema,
|
|
217
|
+
body)
|
|
218
|
+
message_metadata = read_custom_metadata(fb_message.custom_metadata)
|
|
219
|
+
dictionary = Dictionary.new(fb_header.id,
|
|
220
|
+
record_batch.columns[0],
|
|
221
|
+
message_metadata: message_metadata)
|
|
200
222
|
if fb_header.delta?
|
|
201
|
-
dictionaries[id] <<
|
|
223
|
+
dictionaries[id] << dictionary
|
|
202
224
|
else
|
|
203
|
-
dictionaries[id] = [
|
|
225
|
+
dictionaries[id] = [dictionary]
|
|
204
226
|
end
|
|
205
227
|
end
|
|
206
228
|
dictionaries
|
|
207
229
|
end
|
|
208
230
|
|
|
209
|
-
def
|
|
231
|
+
def find_dictionaries(id)
|
|
210
232
|
@dictionaries[id]
|
|
211
233
|
end
|
|
212
234
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
require_relative "streaming-writer"
|
|
19
|
+
|
|
20
|
+
module ArrowFormat
|
|
21
|
+
class FileWriter < StreamingWriter
|
|
22
|
+
MAGIC = "ARROW1".b
|
|
23
|
+
MAGIC_PADDING = "\x00\x00"
|
|
24
|
+
|
|
25
|
+
def start(schema)
|
|
26
|
+
@fb_schema = schema.to_flatbuffers
|
|
27
|
+
write_data(MAGIC)
|
|
28
|
+
write_data(MAGIC_PADDING)
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def finish(metadata=nil)
|
|
33
|
+
super()
|
|
34
|
+
write_footer(metadata)
|
|
35
|
+
write_data(MAGIC)
|
|
36
|
+
@output
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
def build_footer(metadata)
|
|
41
|
+
fb_footer = FB::Footer::Data.new
|
|
42
|
+
fb_footer.version = FB::MetadataVersion::V5
|
|
43
|
+
fb_footer.schema = @fb_schema
|
|
44
|
+
fb_footer.dictionaries = @fb_dictionary_blocks
|
|
45
|
+
fb_footer.record_batches = @fb_record_batch_blocks
|
|
46
|
+
fb_footer.custom_metadata = FB.build_custom_metadata(metadata)
|
|
47
|
+
FB::Footer.serialize(fb_footer)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def write_footer(metadata)
|
|
51
|
+
footer = build_footer(metadata)
|
|
52
|
+
write_data(footer)
|
|
53
|
+
write_data([footer.bytesize].pack("l<"))
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
require_relative "org/apache/arrow/flatbuf/binary"
|
|
19
|
+
require_relative "org/apache/arrow/flatbuf/block"
|
|
20
|
+
require_relative "org/apache/arrow/flatbuf/bool"
|
|
21
|
+
require_relative "org/apache/arrow/flatbuf/date"
|
|
22
|
+
require_relative "org/apache/arrow/flatbuf/date_unit"
|
|
23
|
+
require_relative "org/apache/arrow/flatbuf/decimal"
|
|
24
|
+
require_relative "org/apache/arrow/flatbuf/dictionary_encoding"
|
|
25
|
+
require_relative "org/apache/arrow/flatbuf/dictionary_batch"
|
|
26
|
+
require_relative "org/apache/arrow/flatbuf/duration"
|
|
27
|
+
require_relative "org/apache/arrow/flatbuf/fixed_size_binary"
|
|
28
|
+
require_relative "org/apache/arrow/flatbuf/fixed_size_list"
|
|
29
|
+
require_relative "org/apache/arrow/flatbuf/floating_point"
|
|
30
|
+
require_relative "org/apache/arrow/flatbuf/footer"
|
|
31
|
+
require_relative "org/apache/arrow/flatbuf/int"
|
|
32
|
+
require_relative "org/apache/arrow/flatbuf/interval"
|
|
33
|
+
require_relative "org/apache/arrow/flatbuf/interval_unit"
|
|
34
|
+
require_relative "org/apache/arrow/flatbuf/large_binary"
|
|
35
|
+
require_relative "org/apache/arrow/flatbuf/large_list"
|
|
36
|
+
require_relative "org/apache/arrow/flatbuf/large_utf8"
|
|
37
|
+
require_relative "org/apache/arrow/flatbuf/list"
|
|
38
|
+
require_relative "org/apache/arrow/flatbuf/map"
|
|
39
|
+
require_relative "org/apache/arrow/flatbuf/message"
|
|
40
|
+
require_relative "org/apache/arrow/flatbuf/null"
|
|
41
|
+
require_relative "org/apache/arrow/flatbuf/precision"
|
|
42
|
+
require_relative "org/apache/arrow/flatbuf/record_batch"
|
|
43
|
+
require_relative "org/apache/arrow/flatbuf/schema"
|
|
44
|
+
require_relative "org/apache/arrow/flatbuf/struct_"
|
|
45
|
+
require_relative "org/apache/arrow/flatbuf/time"
|
|
46
|
+
require_relative "org/apache/arrow/flatbuf/time_unit"
|
|
47
|
+
require_relative "org/apache/arrow/flatbuf/timestamp"
|
|
48
|
+
require_relative "org/apache/arrow/flatbuf/union"
|
|
49
|
+
require_relative "org/apache/arrow/flatbuf/union_mode"
|
|
50
|
+
require_relative "org/apache/arrow/flatbuf/utf8"
|
|
51
|
+
|
|
52
|
+
module ArrowFormat
|
|
53
|
+
FB = Org::Apache::Arrow::Flatbuf
|
|
54
|
+
|
|
55
|
+
class << FB
|
|
56
|
+
def build_custom_metadata(custom_metadata)
|
|
57
|
+
return nil if custom_metadata.nil?
|
|
58
|
+
|
|
59
|
+
custom_metadata.collect do |key, value|
|
|
60
|
+
fb_key_value = FB::KeyValue::Data.new
|
|
61
|
+
fb_key_value.key = key
|
|
62
|
+
fb_key_value.value = value
|
|
63
|
+
fb_key_value
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Schema.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -13,6 +13,10 @@ module ArrowFormat
|
|
|
13
13
|
module Flatbuf
|
|
14
14
|
# Opaque binary data
|
|
15
15
|
class Binary < ::FlatBuffers::Table
|
|
16
|
+
FIELDS = {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Data = define_data_class
|
|
16
20
|
end
|
|
17
21
|
end
|
|
18
22
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Schema.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -19,6 +19,10 @@ module ArrowFormat
|
|
|
19
19
|
# Since it uses a variable number of data buffers, each Field with this type
|
|
20
20
|
# must have a corresponding entry in `variadicBufferCounts`.
|
|
21
21
|
class BinaryView < ::FlatBuffers::Table
|
|
22
|
+
FIELDS = {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Data = define_data_class
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //File.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Footer (//File.fbs)
|
|
6
6
|
|
|
@@ -12,6 +12,14 @@ module ArrowFormat
|
|
|
12
12
|
module Arrow
|
|
13
13
|
module Flatbuf
|
|
14
14
|
class Block < ::FlatBuffers::Struct
|
|
15
|
+
FIELDS = {
|
|
16
|
+
offset: ::FlatBuffers::Field.new(:offset, 0, 0, :long, 0),
|
|
17
|
+
meta_data_length: ::FlatBuffers::Field.new(:meta_data_length, 1, 8, :int, 4),
|
|
18
|
+
body_length: ::FlatBuffers::Field.new(:body_length, 2, 16, :long, 0),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Data = define_data_class
|
|
22
|
+
|
|
15
23
|
# Length of the data (this is aligned so there can be a gap between this and
|
|
16
24
|
# the metadata).
|
|
17
25
|
def body_length
|
|
@@ -25,7 +33,7 @@ module ArrowFormat
|
|
|
25
33
|
@view.unpack_int(field_offset)
|
|
26
34
|
end
|
|
27
35
|
|
|
28
|
-
# Index to the start of the
|
|
36
|
+
# Index to the start of the RecordBatch (note this is past the Message header)
|
|
29
37
|
def offset
|
|
30
38
|
field_offset = 0
|
|
31
39
|
@view.unpack_long(field_offset)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Message.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -17,6 +17,13 @@ module ArrowFormat
|
|
|
17
17
|
# bodies. Intended for use with RecordBatch but could be used for other
|
|
18
18
|
# message types
|
|
19
19
|
class BodyCompression < ::FlatBuffers::Table
|
|
20
|
+
FIELDS = {
|
|
21
|
+
codec: ::FlatBuffers::Field.new(:codec, 0, 4, :byte, 0),
|
|
22
|
+
method: ::FlatBuffers::Field.new(:method, 1, 6, :byte, 0),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Data = define_data_class
|
|
26
|
+
|
|
20
27
|
# Compressor library.
|
|
21
28
|
# For LZ4_FRAME, each compressed buffer must consist of a single frame.
|
|
22
29
|
def codec
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Message.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -22,6 +22,8 @@ module ArrowFormat
|
|
|
22
22
|
# uncompressed length may be set to -1 to indicate that the data that
|
|
23
23
|
# follows is not compressed, which can be useful for cases where
|
|
24
24
|
# compression does not yield appreciable savings.
|
|
25
|
+
# Also, empty buffers can optionally be written out as 0-byte compressed
|
|
26
|
+
# buffers, thereby omitting the 8-bytes length header.
|
|
25
27
|
BUFFER = register("BUFFER", 0)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Schema.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -12,6 +12,10 @@ module ArrowFormat
|
|
|
12
12
|
module Arrow
|
|
13
13
|
module Flatbuf
|
|
14
14
|
class Bool < ::FlatBuffers::Table
|
|
15
|
+
FIELDS = {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Data = define_data_class
|
|
15
19
|
end
|
|
16
20
|
end
|
|
17
21
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Schema.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -14,6 +14,13 @@ module ArrowFormat
|
|
|
14
14
|
# ----------------------------------------------------------------------
|
|
15
15
|
# A Buffer represents a single contiguous memory segment
|
|
16
16
|
class Buffer < ::FlatBuffers::Struct
|
|
17
|
+
FIELDS = {
|
|
18
|
+
offset: ::FlatBuffers::Field.new(:offset, 0, 0, :long, 0),
|
|
19
|
+
length: ::FlatBuffers::Field.new(:length, 1, 8, :long, 0),
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Data = define_data_class
|
|
23
|
+
|
|
17
24
|
# The absolute length (in bytes) of the memory buffer. The memory is found
|
|
18
25
|
# from offset (inclusive) to offset + length (non-inclusive). When building
|
|
19
26
|
# messages using the encapsulated IPC message, padding bytes may be written
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Schema.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -19,6 +19,12 @@ module ArrowFormat
|
|
|
19
19
|
# leap seconds), where the values are evenly divisible by 86400000
|
|
20
20
|
# * Days (32 bits) since the UNIX epoch
|
|
21
21
|
class Date < ::FlatBuffers::Table
|
|
22
|
+
FIELDS = {
|
|
23
|
+
unit: ::FlatBuffers::Field.new(:unit, 0, 4, :short, 0),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Data = define_data_class
|
|
27
|
+
|
|
22
28
|
def unit
|
|
23
29
|
field_offset = @view.unpack_virtual_offset(4)
|
|
24
30
|
if field_offset.zero?
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Automatically generated. Don't modify manually.
|
|
2
2
|
#
|
|
3
|
-
# Red FlatBuffers version: 0.0.
|
|
3
|
+
# Red FlatBuffers version: 0.0.4
|
|
4
4
|
# Declared by: //Schema.fbs
|
|
5
5
|
# Rooting type: org.apache.arrow.flatbuf.Message (//Message.fbs)
|
|
6
6
|
|
|
@@ -16,6 +16,14 @@ module ArrowFormat
|
|
|
16
16
|
# 128-bit (16-byte) and 256-bit (32-byte) integers are used.
|
|
17
17
|
# The representation uses the endianness indicated in the Schema.
|
|
18
18
|
class Decimal < ::FlatBuffers::Table
|
|
19
|
+
FIELDS = {
|
|
20
|
+
precision: ::FlatBuffers::Field.new(:precision, 0, 4, :int, 0),
|
|
21
|
+
scale: ::FlatBuffers::Field.new(:scale, 1, 6, :int, 0),
|
|
22
|
+
bit_width: ::FlatBuffers::Field.new(:bit_width, 2, 8, :int, 0),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Data = define_data_class
|
|
26
|
+
|
|
19
27
|
# Number of bits per value. The accepted widths are 32, 64, 128 and 256.
|
|
20
28
|
# We use bitWidth for consistency with Int::bitWidth.
|
|
21
29
|
def bit_width
|