You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2021/12/30 21:24:27 UTC
[arrow] branch master updated: ARROW-15203: [GLib] garrow_struct_scalar_get_value() for scalar from C++ returns value
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 6f47ba3 ARROW-15203: [GLib] garrow_struct_scalar_get_value() for scalar from C++ returns value
6f47ba3 is described below
commit 6f47ba3d01f49bce29ee0395a0b45ad5be17db6b
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Fri Dec 31 06:22:45 2021 +0900
ARROW-15203: [GLib] garrow_struct_scalar_get_value() for scalar from C++ returns value
We need to convert C++ scalars lazy because there is no change to
convert C++ scalars to GLib scalars.
Closes #12041 from kou/glib-struct-scalar-get-value
Authored-by: Sutou Kouhei <ko...@clear-code.com>
Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
c_glib/arrow-glib/scalar.cpp | 10 ++++++++++
c_glib/test/test-struct-scalar.rb | 15 +++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/c_glib/arrow-glib/scalar.cpp b/c_glib/arrow-glib/scalar.cpp
index 847b486..f2233e5 100644
--- a/c_glib/arrow-glib/scalar.cpp
+++ b/c_glib/arrow-glib/scalar.cpp
@@ -2039,6 +2039,16 @@ GList *
garrow_struct_scalar_get_value(GArrowStructScalar *scalar)
{
auto priv = GARROW_STRUCT_SCALAR_GET_PRIVATE(scalar);
+ if (!priv->value) {
+ auto arrow_scalar =
+ std::static_pointer_cast<arrow::StructScalar>(
+ garrow_scalar_get_raw(GARROW_SCALAR(scalar)));
+ for (auto arrow_element : arrow_scalar->value) {
+ priv->value = g_list_prepend(priv->value,
+ garrow_scalar_new_raw(&arrow_element));
+ }
+ priv->value = g_list_reverse(priv->value);
+ }
return priv->value;
}
diff --git a/c_glib/test/test-struct-scalar.rb b/c_glib/test/test-struct-scalar.rb
index 9774943..5842a21 100644
--- a/c_glib/test/test-struct-scalar.rb
+++ b/c_glib/test/test-struct-scalar.rb
@@ -16,6 +16,8 @@
# under the License.
class TestStructScalar < Test::Unit::TestCase
+ include Helper::Buildable
+
def setup
fields = [
Arrow::Field.new("score", Arrow::Int8DataType.new),
@@ -52,4 +54,17 @@ class TestStructScalar < Test::Unit::TestCase
def test_value
assert_equal(@value, @scalar.value)
end
+
+ def test_from_cpp
+ min_max = Arrow::Function.find("min_max")
+ args = [
+ Arrow::ArrayDatum.new(build_int8_array([0, 2, -4])),
+ ]
+ scalar = min_max.execute(args).value
+ assert_equal([
+ Arrow::Int8Scalar.new(-4),
+ Arrow::Int8Scalar.new(2),
+ ],
+ scalar.value)
+ end
end