paleolimbot commented on code in PR #596:
URL: https://github.com/apache/arrow-nanoarrow/pull/596#discussion_r1766024266


##########
src/nanoarrow/common/array_test.cc:
##########
@@ -3101,6 +3241,89 @@ TEST(ArrayViewTest, ArrayViewTestGetString) {
   TestGetFromBinary<FixedSizeBinaryBuilder>(fixed_size_builder);
 }
 
+template <typename BuilderClass>
+void TestGetFromBinaryView(BuilderClass& builder) {
+  struct ArrowArray array;
+  struct ArrowSchema schema;
+  struct ArrowArrayView array_view;
+  struct ArrowError error;
+
+  auto type = builder.type();
+  ARROW_EXPECT_OK(builder.Append("1234"));
+  ARROW_EXPECT_OK(builder.AppendNulls(2));
+  ARROW_EXPECT_OK(builder.Append("four"));
+
+  std::string str1{"this_is_a_relatively_long_string"};
+  std::string filler(NANOARROW_BINARY_VIEW_BLOCK_SIZE - 34, 'x');
+  std::string str2{"goes_into_second_variadic_buffer"};
+
+  ARROW_EXPECT_OK(builder.Append(str1));
+  ARROW_EXPECT_OK(builder.Append(filler));
+  ARROW_EXPECT_OK(builder.Append(str2));
+
+  auto maybe_arrow_array = builder.Finish();
+  ARROW_EXPECT_OK(maybe_arrow_array);
+  auto arrow_array = maybe_arrow_array.ValueUnsafe();
+
+  ARROW_EXPECT_OK(ExportArray(*arrow_array, &array, &schema));
+  ASSERT_EQ(ArrowArrayViewInitFromSchema(&array_view, &schema, &error), 
NANOARROW_OK);
+  ASSERT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
+  EXPECT_EQ(ArrowArrayViewValidate(&array_view, 
NANOARROW_VALIDATION_LEVEL_FULL, &error),
+            NANOARROW_OK);
+
+  EXPECT_EQ(array_view.n_variadic_buffers, 2);
+  EXPECT_EQ(array_view.variadic_buffer_sizes[0], str1.size() + filler.size());
+
+  // TODO: is this a bug in the Arrow C++ export? Within gdb I see
+  // (gdb) p ((int32_t*)array->buffers[4])[0]
+  // $34 = 32766
+  // (gdb) p ((int32_t*)array->buffers[4])[1]
+  // $35 = 0
+  // (gdb) p ((int32_t*)array->buffers[4])[2]
+  // $36 = 32
+  // where does the 0 for the second array element come from?
+  EXPECT_EQ(array_view.variadic_buffer_sizes[2], str2.size());

Review Comment:
   I think it is intentional! 
https://arrow.apache.org/docs/format/CDataInterface.html#binary-view-arrays



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

Reply via email to