Skip to content

Commit 9f96d24

Browse files
authored
chore(ci): Ensure tests pass for Arrow C++ <12 and on C++11 (#514)
Tests for #507 and #501 and/or #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.
1 parent 761ead5 commit 9f96d24

File tree

3 files changed

+52
-39
lines changed

3 files changed

+52
-39
lines changed

src/nanoarrow/array.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,11 @@ static int ArrowArrayViewValidateMinimal(struct ArrowArrayView* array_view,
888888
// uint64_t is used here to avoid overflow when adding the offset and length
889889
if ((uint64_t)array_view->offset + (uint64_t)array_view->length >
890890
(uint64_t)max_length) {
891-
ArrowErrorSet(
892-
error,
893-
"Offset + length of a run-end encoded array must fit in a value"
894-
" of the run end type %s, but offset + length is %lu while the "
895-
"allowed maximum is %lu",
896-
ArrowTypeString(run_ends_view->storage_type),
897-
(unsigned long)array_view->offset + (unsigned long)array_view->length,
898-
(unsigned long)max_length);
891+
ArrowErrorSet(error,
892+
"Offset + length of a run-end encoded array must fit in a value"
893+
" of the run end type %s, but offset + length is %ld",
894+
ArrowTypeString(run_ends_view->storage_type),
895+
(long)array_view->offset + (long)array_view->length);
899896
return EINVAL;
900897
}
901898
if (run_ends_view->length > values_view->length) {

src/nanoarrow/array_test.cc

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
#include <arrow/array/builder_decimal.h>
2727
#include <arrow/array/builder_nested.h>
2828
#include <arrow/array/builder_primitive.h>
29-
#include <arrow/array/builder_run_end.h>
3029
#include <arrow/array/builder_time.h>
3130
#include <arrow/array/builder_union.h>
3231
#include <arrow/c/bridge.h>
3332
#include <arrow/compare.h>
33+
#include <arrow/config.h>
3434
#include <arrow/util/decimal.h>
3535

36+
#if defined(ARROW_VERSION_MAJOR) && ARROW_VERSION_MAJOR >= 12
37+
#include <arrow/array/builder_run_end.h>
38+
#endif
39+
3640
#include "nanoarrow/nanoarrow.hpp"
3741

3842
using namespace arrow;
@@ -1482,11 +1486,9 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
14821486
array.offset = INT32_MAX;
14831487
EXPECT_EQ(ArrowArrayFinishBuilding(&array, NANOARROW_VALIDATION_LEVEL_FULL, &error),
14841488
EINVAL);
1485-
EXPECT_STREQ(
1486-
ArrowErrorMessage(&error),
1487-
"Offset + length of a run-end encoded array must fit in a value of the "
1488-
"run end type int32, but offset + length is 2147483654 while the allowed "
1489-
"maximum is 2147483647");
1489+
EXPECT_STREQ(ArrowErrorMessage(&error),
1490+
"Offset + length of a run-end encoded array must fit in a value of the "
1491+
"run end type int32, but offset + length is 2147483654");
14901492

14911493
((struct ArrowArrayPrivateData*)(array.children[0]->private_data))->storage_type =
14921494
NANOARROW_TYPE_INT16;
@@ -1496,18 +1498,17 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
14961498
EXPECT_STREQ(
14971499
ArrowErrorMessage(&error),
14981500
"Offset + length of a run-end encoded array must fit in a value of the run end "
1499-
"type int16, but offset + length is 32774 while the allowed maximum is 32767");
1501+
"type int16, but offset + length is 32774");
15001502

15011503
((struct ArrowArrayPrivateData*)(array.children[0]->private_data))->storage_type =
15021504
NANOARROW_TYPE_INT64;
15031505
array.offset = INT64_MAX;
15041506
EXPECT_EQ(ArrowArrayFinishBuilding(&array, NANOARROW_VALIDATION_LEVEL_FULL, &error),
15051507
EINVAL);
1506-
EXPECT_STREQ(ArrowErrorMessage(&error),
1507-
"Offset + length of a run-end encoded array must fit in a value of the "
1508-
"run end type int64, but offset + length is 9223372036854775814 while "
1509-
"the allowed "
1510-
"maximum is 9223372036854775807");
1508+
EXPECT_THAT(
1509+
ArrowErrorMessage(&error),
1510+
::testing::StartsWith("Offset + length of a run-end encoded array must fit in a "
1511+
"value of the run end type int64, but offset + length is"));
15111512
}
15121513
((struct ArrowArrayPrivateData*)(array.children[0]->private_data))->storage_type =
15131514
NANOARROW_TYPE_INT32;
@@ -1572,6 +1573,10 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
15721573
EXPECT_EQ(ArrowArrayFinishBuilding(&array, NANOARROW_VALIDATION_LEVEL_FULL, &error),
15731574
NANOARROW_OK);
15741575

1576+
#if !defined(ARROW_VERSION_MAJOR) || ARROW_VERSION_MAJOR < 12
1577+
ArrowSchemaRelease(&schema);
1578+
ArrowArrayRelease(&array);
1579+
#else
15751580
auto arrow_array = ImportArray(&array, &schema);
15761581
ARROW_EXPECT_OK(arrow_array);
15771582

@@ -1591,6 +1596,7 @@ TEST(ArrayTest, ArrayTestAppendToRunEndEncodedArray) {
15911596

15921597
EXPECT_STREQ(arrow_array.ValueUnsafe()->ToString().c_str(),
15931598
expected_array.ValueUnsafe()->ToString().c_str());
1599+
#endif
15941600
}
15951601

15961602
TEST(ArrayTest, ArrayTestUnionUtils) {
@@ -2577,20 +2583,6 @@ TEST(ArrayTest, ArrayViewTestSparseUnionGet) {
25772583
ArrowArrayRelease(&array);
25782584
}
25792585

2580-
template <
2581-
typename TypeClass, typename ValueType,
2582-
typename std::enable_if<std::is_same_v<TypeClass, HalfFloatType>, bool>::type = true>
2583-
auto transform_value(ValueType t) -> uint16_t {
2584-
return ArrowFloatToHalfFloat(t);
2585-
}
2586-
2587-
template <
2588-
typename TypeClass, typename ValueType,
2589-
typename std::enable_if<!std::is_same_v<TypeClass, HalfFloatType>, bool>::type = true>
2590-
auto transform_value(ValueType t) -> ValueType {
2591-
return t;
2592-
}
2593-
25942586
template <typename TypeClass>
25952587
void TestGetFromNumericArrayView() {
25962588
struct ArrowArray array;
@@ -2602,9 +2594,17 @@ void TestGetFromNumericArrayView() {
26022594

26032595
// Array with nulls
26042596
auto builder = NumericBuilder<TypeClass>();
2605-
ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(1)));
2606-
ARROW_EXPECT_OK(builder.AppendNulls(2));
2607-
ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(4)));
2597+
2598+
if (type->id() == Type::HALF_FLOAT) {
2599+
ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(1)));
2600+
ARROW_EXPECT_OK(builder.AppendNulls(2));
2601+
ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(4)));
2602+
} else {
2603+
ARROW_EXPECT_OK(builder.Append(1));
2604+
ARROW_EXPECT_OK(builder.AppendNulls(2));
2605+
ARROW_EXPECT_OK(builder.Append(4));
2606+
}
2607+
26082608
auto maybe_arrow_array = builder.Finish();
26092609
ARROW_EXPECT_OK(maybe_arrow_array);
26102610
auto arrow_array = maybe_arrow_array.ValueUnsafe();
@@ -2635,8 +2635,15 @@ void TestGetFromNumericArrayView() {
26352635

26362636
// Array without nulls (Arrow does not allocate the validity buffer)
26372637
builder = NumericBuilder<TypeClass>();
2638-
ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(1)));
2639-
ARROW_EXPECT_OK(builder.Append(transform_value<TypeClass>(2)));
2638+
2639+
if (type->id() == Type::HALF_FLOAT) {
2640+
ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(1)));
2641+
ARROW_EXPECT_OK(builder.Append(ArrowFloatToHalfFloat(2)));
2642+
} else {
2643+
ARROW_EXPECT_OK(builder.Append(1));
2644+
ARROW_EXPECT_OK(builder.Append(2));
2645+
}
2646+
26402647
maybe_arrow_array = builder.Finish();
26412648
ARROW_EXPECT_OK(maybe_arrow_array);
26422649
arrow_array = maybe_arrow_array.ValueUnsafe();

src/nanoarrow/schema_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <gtest/gtest.h>
1919

2020
#include <arrow/c/bridge.h>
21+
#include <arrow/config.h>
2122
#include <arrow/testing/gtest_util.h>
2223
#include <arrow/util/key_value_metadata.h>
2324

@@ -235,6 +236,9 @@ TEST(SchemaTest, SchemaInitRunEndEncoded) {
235236

236237
ASSERT_EQ(ArrowSchemaSetType(schema.children[1], NANOARROW_TYPE_FLOAT), NANOARROW_OK);
237238

239+
#if !defined(ARROW_VERSION_MAJOR) || ARROW_VERSION_MAJOR < 12
240+
ArrowSchemaRelease(&schema);
241+
#else
238242
auto arrow_type = ImportType(&schema);
239243
ARROW_EXPECT_OK(arrow_type);
240244
EXPECT_TRUE(arrow_type.ValueUnsafe()->Equals(run_end_encoded(int16(), float32())));
@@ -258,6 +262,7 @@ TEST(SchemaTest, SchemaInitRunEndEncoded) {
258262
arrow_type = ImportType(&schema);
259263
ARROW_EXPECT_OK(arrow_type);
260264
EXPECT_TRUE(arrow_type.ValueUnsafe()->Equals(run_end_encoded(int64(), float32())));
265+
#endif
261266
}
262267

263268
TEST(SchemaTest, SchemaInitDateTime) {
@@ -543,6 +548,9 @@ TEST(SchemaTest, SchemaCopyDictType) {
543548
}
544549

545550
TEST(SchemaTest, SchemaCopyRunEndEncodedType) {
551+
#if !defined(ARROW_VERSION_MAJOR) || ARROW_VERSION_MAJOR < 12
552+
GTEST_SKIP() << "Arrow C++ REE integration test requires ARROW_VERSION_MAJOR >= 12";
553+
#else
546554
struct ArrowSchema schema;
547555
auto struct_type = run_end_encoded(int32(), float32());
548556
ARROW_EXPECT_OK(ExportType(*struct_type, &schema));
@@ -560,6 +568,7 @@ TEST(SchemaTest, SchemaCopyRunEndEncodedType) {
560568

561569
ArrowSchemaRelease(&schema);
562570
ArrowSchemaRelease(&schema_copy);
571+
#endif
563572
}
564573

565574
TEST(SchemaTest, SchemaCopyFlags) {

0 commit comments

Comments
 (0)