kou commented on code in PR #34441:
URL: https://github.com/apache/arrow/pull/34441#discussion_r1125290614
##########
ruby/red-arrow/test/test-record-batch-file-reader.rb:
##########
@@ -112,4 +112,18 @@ class RecordBatchFileReaderTest < Test::Unit::TestCase
end
end
end
+
+ sub_test_case("#each") do
+ test("without block") do
+ buffer = Arrow::ResizableBuffer.new(1024)
+ Arrow::Table.new(number: [1, 2, 3]).save(buffer)
+ Arrow::BufferInputStream.open(buffer) do |input|
+ reader = Arrow::RecordBatchFileReader.new(input)
+ assert_equal([
+ Arrow::RecordBatch.new(number: [1, 2, 3]),
+ ],
+ reader.each.to_a)
Review Comment:
```suggestion
each = reader.each
assert_equal({
size: 1,
to_a: [
Arrow::RecordBatch.new(number: [1, 2, 3]),
],
}.
{
size: each.size,
to_a: each.to_a,
})
```
##########
ruby/red-arrow/test/test-record-batch-file-reader.rb:
##########
@@ -112,4 +112,18 @@ class RecordBatchFileReaderTest < Test::Unit::TestCase
end
end
end
+
+ sub_test_case("#each") do
+ test("without block") do
+ buffer = Arrow::ResizableBuffer.new(1024)
+ Arrow::Table.new(number: [1, 2, 3]).save(buffer)
+ Arrow::BufferInputStream.open(buffer) do |input|
+ reader = Arrow::RecordBatchFileReader.new(input)
+ assert_equal([
+ Arrow::RecordBatch.new(number: [1, 2, 3]),
+ ],
+ reader.each.to_a)
+ end
+ end
Review Comment:
I'll test them at once for easy to debug.
##########
ruby/red-arrow/lib/arrow/record-batch-file-reader.rb:
##########
@@ -20,6 +20,8 @@ class RecordBatchFileReader
include Enumerable
def each
+ return to_enum(__method__) unless block_given?
Review Comment:
It's a good idea!
I don't know any useful use-case of this (and `Enumerator#size`) but this
doesn't have a performance penalty. So it's acceptable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]