You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/06/16 19:22:13 UTC

[GitHub] [arrow] fsaintjacques commented on a change in pull request #7451: ARROW-8769: [C++][R] Add convenience accessor for StructScalar fields

fsaintjacques commented on a change in pull request #7451:
URL: https://github.com/apache/arrow/pull/7451#discussion_r441071413



##########
File path: cpp/src/arrow/scalar_test.cc
##########
@@ -433,4 +433,24 @@ TYPED_TEST(TestNumericScalar, Cast) {
   }
 }
 
+TEST(TestStructScalar, FieldAccess) {
+  StructScalar abc({MakeScalar(true), MakeNullScalar(int32()), MakeScalar("hello")},
+                   struct_({
+                       field("a", boolean()),
+                       field("b", int32()),
+                       field("b", utf8()),
+                   }));
+
+  ASSERT_OK_AND_ASSIGN(auto a, abc.field("a"));
+  AssertScalarsEqual(*a, *abc.value[0]);
+
+  ASSERT_RAISES(Invalid, abc.field("b").status());
+
+  ASSERT_OK_AND_ASSIGN(auto b, abc.field(1));
+  AssertScalarsEqual(*b, *abc.value[1]);
+
+  ASSERT_RAISES(Invalid, abc.field(5).status());
+  ASSERT_RAISES(Invalid, abc.field("c").status());

Review comment:
       Add a nested failure (not implemented).




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org