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

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


The following commit(s) were added to refs/heads/master by this push:
     new d130a00  ARROW-2812: [Ruby] Fix Arrow::Array#[] interface for 
Arrow::StructArray
d130a00 is described below

commit d130a0006fc21b5e80301f126e44e01fafc28c63
Author: joker1007 <[email protected]>
AuthorDate: Tue Jul 10 15:51:49 2018 +0900

    ARROW-2812: [Ruby] Fix Arrow::Array#[] interface for Arrow::StructArray
    
    `Arrow::StructArray` does not have `#get_value` method, and 
`Arrow::Array#[]` interface depends on `#get_value` method.
    
    And so, `StructArray` cannot access internal columns via `#[]` interface.
    
    Error message is following.
    
    ```
    NoMethodError: undefined method `get_value' for 
#<Arrow::StructArray:0x0000000001859ac0>
    ```
    
    This patch fixes it.
    
    Author: joker1007 <[email protected]>
    Author: Kouhei Sutou <[email protected]>
    
    Closes #2233 from joker1007/fix-array-interface-for-struct-array and 
squashes the following commits:
    
    36d1d819 [Kouhei Sutou] Fix wrong affected check
    1083e843 [joker1007] ARROW-2812: [Ruby] Fix Arrow::Array#[] interface for 
Arrow::StructArray
---
 ci/travis_install_osx.sh                           |  2 +-
 ruby/red-arrow/lib/arrow/loader.rb                 |  1 +
 .../red-arrow/lib/arrow/struct-array.rb            | 15 ++++++------
 .../red-arrow/test/test-struct-array.rb            | 27 +++++++++++++++-------
 4 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/ci/travis_install_osx.sh b/ci/travis_install_osx.sh
index ce31460..271c5c1 100755
--- a/ci/travis_install_osx.sh
+++ b/ci/travis_install_osx.sh
@@ -17,7 +17,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if [ "$ARROW_CI_C_GLIB_AFFECTED" = "1" ]; then
+if [ "$ARROW_CI_RUBY_AFFECTED" = "1" ]; then
     brew update
     brew upgrade python
     brew upgrade hg
diff --git a/ruby/red-arrow/lib/arrow/loader.rb 
b/ruby/red-arrow/lib/arrow/loader.rb
index 2366393..4cb633b 100644
--- a/ruby/red-arrow/lib/arrow/loader.rb
+++ b/ruby/red-arrow/lib/arrow/loader.rb
@@ -46,6 +46,7 @@ module Arrow
       require "arrow/record-batch"
       require "arrow/rolling-window"
       require "arrow/slicer"
+      require "arrow/struct-array"
       require "arrow/table"
       require "arrow/table-formatter"
       require "arrow/table-list-formatter"
diff --git a/ci/travis_install_osx.sh b/ruby/red-arrow/lib/arrow/struct-array.rb
old mode 100755
new mode 100644
similarity index 80%
copy from ci/travis_install_osx.sh
copy to ruby/red-arrow/lib/arrow/struct-array.rb
index ce31460..4f9834c
--- a/ci/travis_install_osx.sh
+++ b/ruby/red-arrow/lib/arrow/struct-array.rb
@@ -1,5 +1,3 @@
-#!/usr/bin/env bash
-
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -17,9 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if [ "$ARROW_CI_C_GLIB_AFFECTED" = "1" ]; then
-    brew update
-    brew upgrade python
-    brew upgrade hg
-    brew bundle --file=$TRAVIS_BUILD_DIR/c_glib/Brewfile
-fi
+module Arrow
+  class StructArray
+    def [](i)
+      get_field(i)
+    end
+  end
+end
diff --git a/ci/travis_install_osx.sh b/ruby/red-arrow/test/test-struct-array.rb
old mode 100755
new mode 100644
similarity index 57%
copy from ci/travis_install_osx.sh
copy to ruby/red-arrow/test/test-struct-array.rb
index ce31460..1957db4
--- a/ci/travis_install_osx.sh
+++ b/ruby/red-arrow/test/test-struct-array.rb
@@ -1,5 +1,3 @@
-#!/usr/bin/env bash
-
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -17,9 +15,22 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if [ "$ARROW_CI_C_GLIB_AFFECTED" = "1" ]; then
-    brew update
-    brew upgrade python
-    brew upgrade hg
-    brew bundle --file=$TRAVIS_BUILD_DIR/c_glib/Brewfile
-fi
+class StructArrayTest < Test::Unit::TestCase
+  test("#[]") do
+    type = Arrow::StructDataType.new([
+      Arrow::Field.new("field1", :boolean),
+      Arrow::Field.new("field2", :uint64),
+    ])
+    builder = Arrow::StructArrayBuilder.new(type)
+    builder.append
+    builder.get_field_builder(0).append(true)
+    builder.get_field_builder(1).append(1)
+    builder.append
+    builder.get_field_builder(0).append(false)
+    builder.get_field_builder(1).append(2)
+    array = builder.finish
+
+    assert_equal([[true, false], [1, 2]],
+                 [array[0].to_a, array[1].to_a])
+  end
+end

Reply via email to