This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new f465c345e5 GH-34442: [Ruby][FlightRPC] Add 
`ArrowFlight::RecordBatchReader#each` (#34444)
f465c345e5 is described below

commit f465c345e50afeaf82accfa72e3f2216f64f72e2
Author: Sutou Kouhei <[email protected]>
AuthorDate: Sun Mar 5 06:58:25 2023 +0900

    GH-34442: [Ruby][FlightRPC] Add `ArrowFlight::RecordBatchReader#each` 
(#34444)
    
    ### Rationale for this change
    
    Iteratable object should have `#each`.
    
    ### What changes are included in this PR?
    
    `#each` and its test.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * Closes: #34442
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 ruby/red-arrow-flight/lib/arrow-flight/loader.rb   |  1 +
 .../{loader.rb => record-batch-reader.rb}          | 30 +++++-----------
 .../loader.rb => test/test-record-batch-reader.rb} | 41 ++++++++++------------
 3 files changed, 29 insertions(+), 43 deletions(-)

diff --git a/ruby/red-arrow-flight/lib/arrow-flight/loader.rb 
b/ruby/red-arrow-flight/lib/arrow-flight/loader.rb
index 1d58892070..4fb88d4296 100644
--- a/ruby/red-arrow-flight/lib/arrow-flight/loader.rb
+++ b/ruby/red-arrow-flight/lib/arrow-flight/loader.rb
@@ -32,6 +32,7 @@ module ArrowFlight
       require "arrow-flight/call-options"
       require "arrow-flight/client-options"
       require "arrow-flight/location"
+      require "arrow-flight/record-batch-reader"
       require "arrow-flight/server-options"
       require "arrow-flight/ticket"
     end
diff --git a/ruby/red-arrow-flight/lib/arrow-flight/loader.rb 
b/ruby/red-arrow-flight/lib/arrow-flight/record-batch-reader.rb
similarity index 59%
copy from ruby/red-arrow-flight/lib/arrow-flight/loader.rb
copy to ruby/red-arrow-flight/lib/arrow-flight/record-batch-reader.rb
index 1d58892070..98f631e15b 100644
--- a/ruby/red-arrow-flight/lib/arrow-flight/loader.rb
+++ b/ruby/red-arrow-flight/lib/arrow-flight/record-batch-reader.rb
@@ -16,29 +16,17 @@
 # under the License.
 
 module ArrowFlight
-  class Loader < GObjectIntrospection::Loader
-    class << self
-      def load
-        super("ArrowFlight", ArrowFlight)
-      end
-    end
-
-    private
-    def post_load(repository, namespace)
-      require_libraries
-    end
+  class RecordBatchReader
+    include Enumerable
 
-    def require_libraries
-      require "arrow-flight/call-options"
-      require "arrow-flight/client-options"
-      require "arrow-flight/location"
-      require "arrow-flight/server-options"
-      require "arrow-flight/ticket"
-    end
+    def each
+      return to_enum(__method__) unless block_given?
 
-    def prepare_function_info_lock_gvl(function_info, klass)
-      super
-      function_info.lock_gvl_default = false
+      loop do
+        record_batch = read_next
+        break if record_batch.nil?
+        yield(record_batch)
+      end
     end
   end
 end
diff --git a/ruby/red-arrow-flight/lib/arrow-flight/loader.rb 
b/ruby/red-arrow-flight/test/test-record-batch-reader.rb
similarity index 55%
copy from ruby/red-arrow-flight/lib/arrow-flight/loader.rb
copy to ruby/red-arrow-flight/test/test-record-batch-reader.rb
index 1d58892070..7f8c64c003 100644
--- a/ruby/red-arrow-flight/lib/arrow-flight/loader.rb
+++ b/ruby/red-arrow-flight/test/test-record-batch-reader.rb
@@ -15,30 +15,27 @@
 # specific language governing permissions and limitations
 # under the License.
 
-module ArrowFlight
-  class Loader < GObjectIntrospection::Loader
-    class << self
-      def load
-        super("ArrowFlight", ArrowFlight)
-      end
-    end
-
-    private
-    def post_load(repository, namespace)
-      require_libraries
-    end
+class TestRecordBatchReader < Test::Unit::TestCase
+  def setup
+    @server = nil
+    omit("Unstable on Windows") if Gem.win_platform?
+    @server = Helper::Server.new
+    @server.listen("grpc://127.0.0.1:0")
+    @location = "grpc://127.0.0.1:#{@server.port}"
+  end
 
-    def require_libraries
-      require "arrow-flight/call-options"
-      require "arrow-flight/client-options"
-      require "arrow-flight/location"
-      require "arrow-flight/server-options"
-      require "arrow-flight/ticket"
-    end
+  def teardown
+    return if @server.nil?
+    @server.shutdown
+  end
 
-    def prepare_function_info_lock_gvl(function_info, klass)
-      super
-      function_info.lock_gvl_default = false
+  sub_test_case("#each") do
+    def test_without_block
+      client = ArrowFlight::Client.new(@location)
+      generator = Helper::InfoGenerator.new
+      reader = client.do_get(generator.page_view_ticket)
+      assert_equal(generator.page_view_table.each_record_batch.to_a,
+                   reader.each.collect(&:data))
     end
   end
 end

Reply via email to