This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new 9f96d245 chore(ci): Ensure tests pass for Arrow C++ <12 and on C++11
(#514)
9f96d245 is described below
commit 9f96d2459bea480d2aaff23210541d2ae0548839
Author: Dewey Dunnington <[email protected]>
AuthorDate: Mon Jun 10 14:38:45 2024 +0000
chore(ci): Ensure tests pass for Arrow C++ <12 and on C++11 (#514)
Tests for https://github.com/apache/arrow-nanoarrow/pull/507 and
https://github.com/apache/arrow-nanoarrow/pull/501 and/or
https://github.com/apache/arrow-nanoarrow/pull/503 either used C++17 or
features from Arrow C++ > 12. Our test suite still supports these
(although perhaps parts of this support should be dropped soon).
On Windows, formatting with `%lu` was doing some unexpected formatting.
We could do a better job formatting 64-bit integers in error messages
(e.g., using `PRId64` and the requisite defines to ensure it works on
mingw); however, we probably won't ever be able to support properly
formatting an unsigned 64-bit integer on every platform we support. I
changed the error message (and its test) slightly to reflect that.
---
src/nanoarrow/array.c | 13 ++++-----
src/nanoarrow/array_test.cc | 69 ++++++++++++++++++++++++--------------------
src/nanoarrow/schema_test.cc | 9 ++++++
3 files changed, 52 insertions(+), 39 deletions(-)
diff --git a/src/nanoarrow/array.c b/src/nanoarrow/array.c
index 82236490..36df998f 100644
--- a/src/nanoarrow/array.c
+++ b/src/nanoarrow/array.c
@@ -888,14 +888,11 @@ static int ArrowArrayViewValidateMinimal(struct
ArrowArrayView* array_view,
// uint64_t is used here to avoid overflow when adding the offset and
length
if ((uint64_t)array_view->offset + (uint64_t)array_view->length >
(uint64_t)max_length) {
- ArrowErrorSet(
- error,
- "Offset + length of a run-end encoded array must fit in a value"
- " of the run end type %s, but offset + length is %lu while the "
- "allowed maximum is %lu",
- ArrowTypeString(run_ends_view->storage_type),
- (unsigned long)array_view->offset + (unsigned
long)array_view->length,
- (unsigned long)max_length);
+ ArrowErrorSet(error,
+ "Offset + length of a run-end encoded array must fit in
a value"
+ " of the run end type %s, but offset + length is %ld",
+ ArrowTypeString(run_ends_view->storage_type),
+ (long)array_view->offset + (long)array_view->length);
return EINVAL;
}
if (run_ends_view->length > values_view->length) {
diff --git a/src/nanoarrow/array_test.cc b/src/nanoarrow/array_test.cc
index 4cc1bd08..846c5f80 100644
--- a/src/nanoarrow/array_test.cc
+++ b/src/nanoarrow/array_test.cc
@@ -26,13 +26,17 @@
#include <arrow/array/builder_decimal.h>
#include <arrow/array/builder_nested.h>
#include <arrow/array/builder_primitive.h>
-#include <arrow/array/builder_run_end.h>
#include <arrow/array/builder_time.h>
#include <arrow/array/builder_union.h>
#include <arrow/c/bridge.h>
#include <arrow/compare.h>
+#include <arrow/config.h>
#include <arrow/util/decimal.h>
+#if defined(ARROW_VERSION_MAJOR) && ARROW_VERSION_MAJOR >= 12
+#include <arrow/array/builder_run_end.h>
+#endif
+
#include "nanoarrow/nanoarrow.hpp"
using namespace arrow;
@@ -1482,11 +1486,9 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
array.offset = INT32_MAX;
EXPECT_EQ(ArrowArrayFinishBuilding(&array,
NANOARROW_VALIDATION_LEVEL_FULL, &error),
EINVAL);
- EXPECT_STREQ(
- ArrowErrorMessage(&error),
- "Offset + length of a run-end encoded array must fit in a value of the
"
- "run end type int32, but offset + length is 2147483654 while the
allowed "
- "maximum is 2147483647");
+ EXPECT_STREQ(ArrowErrorMessage(&error),
+ "Offset + length of a run-end encoded array must fit in a
value of the "
+ "run end type int32, but offset + length is 2147483654");
((struct
ArrowArrayPrivateData*)(array.children[0]->private_data))->storage_type =
NANOARROW_TYPE_INT16;
@@ -1496,18 +1498,17 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
EXPECT_STREQ(
ArrowErrorMessage(&error),
"Offset + length of a run-end encoded array must fit in a value of the
run end "
- "type int16, but offset + length is 32774 while the allowed maximum is
32767");
+ "type int16, but offset + length is 32774");
((struct
ArrowArrayPrivateData*)(array.children[0]->private_data))->storage_type =
NANOARROW_TYPE_INT64;
array.offset = INT64_MAX;
EXPECT_EQ(ArrowArrayFinishBuilding(&array,
NANOARROW_VALIDATION_LEVEL_FULL, &error),
EINVAL);
- EXPECT_STREQ(ArrowErrorMessage(&error),
- "Offset + length of a run-end encoded array must fit in a
value of the "
- "run end type int64, but offset + length is
9223372036854775814 while "
- "the allowed "
- "maximum is 9223372036854775807");
+ EXPECT_THAT(
+ ArrowErrorMessage(&error),
+ ::testing::StartsWith("Offset + length of a run-end encoded array must
fit in a "
+ "value of the run end type int64, but offset +
length is"));
}
((struct
ArrowArrayPrivateData*)(array.children[0]->private_data))->storage_type =
NANOARROW_TYPE_INT32;
@@ -1572,6 +1573,10 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
EXPECT_EQ(ArrowArrayFinishBuilding(&array, NANOARROW_VALIDATION_LEVEL_FULL,
&error),
NANOARROW_OK);
+#if !defined(ARROW_VERSION_MAJOR) || ARROW_VERSION_MAJOR < 12
+ ArrowSchemaRelease(&schema);
+ ArrowArrayRelease(&array);
+#else
auto arrow_array = ImportArray(&array, &schema);
ARROW_EXPECT_OK(arrow_array);
@@ -1591,6 +1596,7 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
EXPECT_STREQ(arrow_array.ValueUnsafe()->ToString().c_str(),
expected_array.ValueUnsafe()->ToString().c_str());
+#endif
}
TEST(ArrayTest, ArrayTestUnionUtils) {
@@ -2577,20 +2583,6 @@ TEST(ArrayTest, ArrayViewTestSparseUnionGet) {
ArrowArrayRelease(&array);
}
-template <
- typename TypeClass, typename ValueType,
- typename std::enable_if<std::is_same_v<TypeClass, HalfFloatType>,
bool>::type = true>
-auto transform_value(ValueType t) -> uint16_t {
- return ArrowFloatToHalfFloat(t);
-}
-
-template <
- typename TypeClass, typename ValueType,
- typename std::enable_if<!std::is_same_v<TypeClass, HalfFloatType>,
bool>::type = true>
-auto transform_value(ValueType t) -> ValueType {
- return t;
-}
-
template <typename TypeClass>
void TestGetFromNumericArrayView() {
struct ArrowArray array;
@@ -2602,9 +2594,17 @@ void TestGetFromNumericArrayView() {
// Array with nulls
auto builder = NumericBuilder<TypeClass>();
- ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(1)));
- ARROW_EXPECT_OK(builder.AppendNulls(2));
- ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(4)));
+
+ if (type->id() == Type::HALF_FLOAT) {
+ ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(1)));
+ ARROW_EXPECT_OK(builder.AppendNulls(2));
+ ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(4)));
+ } else {
+ ARROW_EXPECT_OK(builder.Append(1));
+ ARROW_EXPECT_OK(builder.AppendNulls(2));
+ ARROW_EXPECT_OK(builder.Append(4));
+ }
+
auto maybe_arrow_array = builder.Finish();
ARROW_EXPECT_OK(maybe_arrow_array);
auto arrow_array = maybe_arrow_array.ValueUnsafe();
@@ -2635,8 +2635,15 @@ void TestGetFromNumericArrayView() {
// Array without nulls (Arrow does not allocate the validity buffer)
builder = NumericBuilder<TypeClass>();
- ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(1)));
- ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(2)));
+
+ if (type->id() == Type::HALF_FLOAT) {
+ ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(1)));
+ ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(2)));
+ } else {
+ ARROW_EXPECT_OK(builder.Append(1));
+ ARROW_EXPECT_OK(builder.Append(2));
+ }
+
maybe_arrow_array = builder.Finish();
ARROW_EXPECT_OK(maybe_arrow_array);
arrow_array = maybe_arrow_array.ValueUnsafe();
diff --git a/src/nanoarrow/schema_test.cc b/src/nanoarrow/schema_test.cc
index da8c6a1e..8c23e606 100644
--- a/src/nanoarrow/schema_test.cc
+++ b/src/nanoarrow/schema_test.cc
@@ -18,6 +18,7 @@
#include <gtest/gtest.h>
#include <arrow/c/bridge.h>
+#include <arrow/config.h>
#include <arrow/testing/gtest_util.h>
#include <arrow/util/key_value_metadata.h>
@@ -235,6 +236,9 @@ TEST(SchemaTest, SchemaInitRunEndEncoded) {
ASSERT_EQ(ArrowSchemaSetType(schema.children[1], NANOARROW_TYPE_FLOAT),
NANOARROW_OK);
+#if !defined(ARROW_VERSION_MAJOR) || ARROW_VERSION_MAJOR < 12
+ ArrowSchemaRelease(&schema);
+#else
auto arrow_type = ImportType(&schema);
ARROW_EXPECT_OK(arrow_type);
EXPECT_TRUE(arrow_type.ValueUnsafe()->Equals(run_end_encoded(int16(),
float32())));
@@ -258,6 +262,7 @@ TEST(SchemaTest, SchemaInitRunEndEncoded) {
arrow_type = ImportType(&schema);
ARROW_EXPECT_OK(arrow_type);
EXPECT_TRUE(arrow_type.ValueUnsafe()->Equals(run_end_encoded(int64(),
float32())));
+#endif
}
TEST(SchemaTest, SchemaInitDateTime) {
@@ -543,6 +548,9 @@ TEST(SchemaTest, SchemaCopyDictType) {
}
TEST(SchemaTest, SchemaCopyRunEndEncodedType) {
+#if !defined(ARROW_VERSION_MAJOR) || ARROW_VERSION_MAJOR < 12
+ GTEST_SKIP() << "Arrow C++ REE integration test requires ARROW_VERSION_MAJOR
>= 12";
+#else
struct ArrowSchema schema;
auto struct_type = run_end_encoded(int32(), float32());
ARROW_EXPECT_OK(ExportType(*struct_type, &schema));
@@ -560,6 +568,7 @@ TEST(SchemaTest, SchemaCopyRunEndEncodedType) {
ArrowSchemaRelease(&schema);
ArrowSchemaRelease(&schema_copy);
+#endif
}
TEST(SchemaTest, SchemaCopyFlags) {