Skip to content

Commit 1b6039c

Browse files
fix casting in test
1 parent 88a6140 commit 1b6039c

File tree

1 file changed

+137
-130
lines changed

1 file changed

+137
-130
lines changed

cpp/src/arrow/record_batch_test.cc

+137-130
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ Result<std::shared_ptr<Array>> BuildArray(const std::vector<ValueType>& values)
10941094
return std::visit(builder, values[0]);
10951095
}
10961096

1097-
Result<std::shared_ptr<Array>> MakeStatisticsArray(
1097+
Result<std::shared_ptr<Array>> MakeMockStatisticsArray(
10981098
const std::string& columns_json,
10991099
const std::vector<std::vector<std::string>>& nested_statistics_keys,
11001100
const std::vector<std::vector<ArrayStatistics::ValueType>>&
@@ -1233,13 +1233,13 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayRowCount) {
12331233
ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray());
12341234

12351235
ASSERT_OK_AND_ASSIGN(auto expected_statistics_array,
1236-
MakeStatisticsArray("[null]",
1237-
{{
1238-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1239-
}},
1240-
{{
1241-
ArrayStatistics::ValueType{int64_t{3}},
1242-
}}));
1236+
MakeMockStatisticsArray("[null]",
1237+
{{
1238+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1239+
}},
1240+
{{
1241+
ArrayStatistics::ValueType{int64_t{3}},
1242+
}}));
12431243
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
12441244
}
12451245

@@ -1256,20 +1256,21 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayNullCount) {
12561256

12571257
ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray());
12581258

1259-
ASSERT_OK_AND_ASSIGN(auto expected_statistics_array,
1260-
MakeStatisticsArray("[null, 1]",
1261-
{{
1262-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1263-
},
1264-
{
1265-
ARROW_STATISTICS_KEY_NULL_COUNT_EXACT,
1266-
}},
1267-
{{
1268-
ArrayStatistics::ValueType{int64_t{3}},
1269-
},
1270-
{
1271-
ArrayStatistics::ValueType{int64_t{1}},
1272-
}}));
1259+
ASSERT_OK_AND_ASSIGN(
1260+
auto expected_statistics_array,
1261+
MakeMockStatisticsArray("[null, 1]",
1262+
{{
1263+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1264+
},
1265+
{
1266+
ARROW_STATISTICS_KEY_NULL_COUNT_EXACT,
1267+
}},
1268+
{{
1269+
ArrayStatistics::ValueType{int64_t{3}},
1270+
},
1271+
{
1272+
ArrayStatistics::ValueType{int64_t{1}},
1273+
}}));
12731274
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
12741275
}
12751276

@@ -1287,22 +1288,23 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayDistinctCount) {
12871288

12881289
ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray());
12891290

1290-
ASSERT_OK_AND_ASSIGN(auto expected_statistics_array,
1291-
MakeStatisticsArray("[null, 1]",
1292-
{{
1293-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1294-
},
1295-
{
1296-
ARROW_STATISTICS_KEY_NULL_COUNT_EXACT,
1297-
ARROW_STATISTICS_KEY_DISTINCT_COUNT_EXACT,
1298-
}},
1299-
{{
1300-
ArrayStatistics::ValueType{int64_t{3}},
1301-
},
1302-
{
1303-
ArrayStatistics::ValueType{int64_t{1}},
1304-
ArrayStatistics::ValueType{int64_t{2}},
1305-
}}));
1291+
ASSERT_OK_AND_ASSIGN(
1292+
auto expected_statistics_array,
1293+
MakeMockStatisticsArray("[null, 1]",
1294+
{{
1295+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1296+
},
1297+
{
1298+
ARROW_STATISTICS_KEY_NULL_COUNT_EXACT,
1299+
ARROW_STATISTICS_KEY_DISTINCT_COUNT_EXACT,
1300+
}},
1301+
{{
1302+
ArrayStatistics::ValueType{int64_t{3}},
1303+
},
1304+
{
1305+
ArrayStatistics::ValueType{int64_t{1}},
1306+
ArrayStatistics::ValueType{int64_t{2}},
1307+
}}));
13061308
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
13071309
}
13081310

@@ -1320,20 +1322,21 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayMinExact) {
13201322

13211323
ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray());
13221324

1323-
ASSERT_OK_AND_ASSIGN(auto expected_statistics_array,
1324-
MakeStatisticsArray("[null, 1]",
1325-
{{
1326-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1327-
},
1328-
{
1329-
ARROW_STATISTICS_KEY_MIN_VALUE_EXACT,
1330-
}},
1331-
{{
1332-
ArrayStatistics::ValueType{int64_t{3}},
1333-
},
1334-
{
1335-
ArrayStatistics::ValueType{uint64_t{1}},
1336-
}}));
1325+
ASSERT_OK_AND_ASSIGN(
1326+
auto expected_statistics_array,
1327+
MakeMockStatisticsArray("[null, 1]",
1328+
{{
1329+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1330+
},
1331+
{
1332+
ARROW_STATISTICS_KEY_MIN_VALUE_EXACT,
1333+
}},
1334+
{{
1335+
ArrayStatistics::ValueType{int64_t{3}},
1336+
},
1337+
{
1338+
ArrayStatistics::ValueType{uint64_t{1}},
1339+
}}));
13371340
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
13381341
}
13391342

@@ -1352,19 +1355,19 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayMinApproximate) {
13521355

13531356
ASSERT_OK_AND_ASSIGN(
13541357
auto expected_statistics_array,
1355-
MakeStatisticsArray("[null, 1]",
1356-
{{
1357-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1358-
},
1359-
{
1360-
ARROW_STATISTICS_KEY_MIN_VALUE_APPROXIMATE,
1361-
}},
1362-
{{
1363-
ArrayStatistics::ValueType{int64_t{3}},
1364-
},
1365-
{
1366-
ArrayStatistics::ValueType{-1.0},
1367-
}}));
1358+
MakeMockStatisticsArray("[null, 1]",
1359+
{{
1360+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1361+
},
1362+
{
1363+
ARROW_STATISTICS_KEY_MIN_VALUE_APPROXIMATE,
1364+
}},
1365+
{{
1366+
ArrayStatistics::ValueType{int64_t{3}},
1367+
},
1368+
{
1369+
ArrayStatistics::ValueType{-1.0},
1370+
}}));
13681371
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
13691372
}
13701373

@@ -1383,20 +1386,21 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayMaxExact) {
13831386

13841387
ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray());
13851388

1386-
ASSERT_OK_AND_ASSIGN(auto expected_statistics_array,
1387-
MakeStatisticsArray("[null, 1]",
1388-
{{
1389-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1390-
},
1391-
{
1392-
ARROW_STATISTICS_KEY_MAX_VALUE_EXACT,
1393-
}},
1394-
{{
1395-
ArrayStatistics::ValueType{int64_t{3}},
1396-
},
1397-
{
1398-
ArrayStatistics::ValueType{true},
1399-
}}));
1389+
ASSERT_OK_AND_ASSIGN(
1390+
auto expected_statistics_array,
1391+
MakeMockStatisticsArray("[null, 1]",
1392+
{{
1393+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1394+
},
1395+
{
1396+
ARROW_STATISTICS_KEY_MAX_VALUE_EXACT,
1397+
}},
1398+
{{
1399+
ArrayStatistics::ValueType{int64_t{3}},
1400+
},
1401+
{
1402+
ArrayStatistics::ValueType{true},
1403+
}}));
14001404
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
14011405
}
14021406

@@ -1415,19 +1419,19 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayMaxApproximate) {
14151419

14161420
ASSERT_OK_AND_ASSIGN(
14171421
auto expected_statistics_array,
1418-
MakeStatisticsArray("[null, 1]",
1419-
{{
1420-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1421-
},
1422-
{
1423-
ARROW_STATISTICS_KEY_MAX_VALUE_APPROXIMATE,
1424-
}},
1425-
{{
1426-
ArrayStatistics::ValueType{int64_t{3}},
1427-
},
1428-
{
1429-
ArrayStatistics::ValueType{1.0},
1430-
}}));
1422+
MakeMockStatisticsArray("[null, 1]",
1423+
{{
1424+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1425+
},
1426+
{
1427+
ARROW_STATISTICS_KEY_MAX_VALUE_APPROXIMATE,
1428+
}},
1429+
{{
1430+
ArrayStatistics::ValueType{int64_t{3}},
1431+
},
1432+
{
1433+
ArrayStatistics::ValueType{1.0},
1434+
}}));
14311435
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
14321436
}
14331437

@@ -1445,20 +1449,21 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayString) {
14451449

14461450
ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray());
14471451

1448-
ASSERT_OK_AND_ASSIGN(auto expected_statistics_array,
1449-
MakeStatisticsArray("[null, 1]",
1450-
{{
1451-
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1452-
},
1453-
{
1454-
ARROW_STATISTICS_KEY_MAX_VALUE_EXACT,
1455-
}},
1456-
{{
1457-
ArrayStatistics::ValueType{int64_t{3}},
1458-
},
1459-
{
1460-
ArrayStatistics::ValueType{"c"},
1461-
}}));
1452+
ASSERT_OK_AND_ASSIGN(
1453+
auto expected_statistics_array,
1454+
MakeMockStatisticsArray("[null, 1]",
1455+
{{
1456+
ARROW_STATISTICS_KEY_ROW_COUNT_EXACT,
1457+
},
1458+
{
1459+
ARROW_STATISTICS_KEY_MAX_VALUE_EXACT,
1460+
}},
1461+
{{
1462+
ArrayStatistics::ValueType{int64_t{3}},
1463+
},
1464+
{
1465+
ArrayStatistics::ValueType{"c"},
1466+
}}));
14621467
AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
14631468
}
14641469

@@ -1474,16 +1479,16 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayNestedType) {
14741479
statistics_struct->null_count = 0;
14751480
auto struct_array_data = struct_array->data();
14761481
auto statistics_struct_child_a = std::make_shared<ArrayStatistics>();
1477-
statistics_struct_child_a->min = 1;
1482+
statistics_struct_child_a->min = int64_t{1};
14781483
struct_array_data->statistics = statistics_struct;
14791484
struct_array_data->child_data[0]->statistics = statistics_struct_child_a;
14801485
auto array_c = ArrayFromJSON(int64(), R"([11,12,13,14,15])");
14811486
array_c->data()->statistics = std::make_shared<ArrayStatistics>();
1482-
array_c->data()->statistics->max = 15;
1487+
array_c->data()->statistics->max = int64_t{15};
14831488
auto array_d = ArrayFromJSON(int64(), R"([16,17,18,19,20])");
14841489
auto nested_child = struct_nested_stat->data()->child_data[0];
14851490
nested_child->statistics = std::make_shared<ArrayStatistics>();
1486-
nested_child->statistics->max = 5;
1491+
nested_child->statistics->max = int64_t{5};
14871492
nested_child->statistics->is_max_exact = true;
14881493

14891494
auto rb_schema =
@@ -1498,20 +1503,20 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayNestedType) {
14981503

14991504
ASSERT_OK_AND_ASSIGN(
15001505
auto expected_array,
1501-
MakeStatisticsArray("[null,0,1,3,6]",
1502-
{{ARROW_STATISTICS_KEY_ROW_COUNT_EXACT},
1503-
{ARROW_STATISTICS_KEY_NULL_COUNT_EXACT,
1504-
ARROW_STATISTICS_KEY_MAX_VALUE_APPROXIMATE},
1505-
{ARROW_STATISTICS_KEY_MIN_VALUE_APPROXIMATE},
1506-
{ARROW_STATISTICS_KEY_MAX_VALUE_APPROXIMATE},
1507-
{ARROW_STATISTICS_KEY_MAX_VALUE_EXACT}},
1508-
{{ArrayStatistics::ValueType{int64_t{5}}},
1509-
{ArrayStatistics::ValueType{int64_t{0}},
1510-
ArrayStatistics::ValueType{
1511-
std::static_pointer_cast<Scalar>(expected_scalar)}},
1512-
{ArrayStatistics::ValueType{int64_t{1}}},
1513-
{ArrayStatistics::ValueType{int64_t{15}}},
1514-
{ArrayStatistics::ValueType{int64_t{5}}}}));
1506+
MakeMockStatisticsArray("[null,0,1,3,6]",
1507+
{{ARROW_STATISTICS_KEY_ROW_COUNT_EXACT},
1508+
{ARROW_STATISTICS_KEY_NULL_COUNT_EXACT,
1509+
ARROW_STATISTICS_KEY_MAX_VALUE_APPROXIMATE},
1510+
{ARROW_STATISTICS_KEY_MIN_VALUE_APPROXIMATE},
1511+
{ARROW_STATISTICS_KEY_MAX_VALUE_APPROXIMATE},
1512+
{ARROW_STATISTICS_KEY_MAX_VALUE_EXACT}},
1513+
{{ArrayStatistics::ValueType{int64_t{5}}},
1514+
{ArrayStatistics::ValueType{int64_t{0}},
1515+
ArrayStatistics::ValueType{
1516+
std::static_pointer_cast<Scalar>(expected_scalar)}},
1517+
{ArrayStatistics::ValueType{int64_t{1}}},
1518+
{ArrayStatistics::ValueType{int64_t{15}}},
1519+
{ArrayStatistics::ValueType{int64_t{5}}}}));
15151520
ASSERT_OK_AND_ASSIGN(auto rb_stat, rb->MakeStatisticsArray());
15161521
AssertArraysEqual(*expected_array, *rb_stat, true);
15171522
}
@@ -1540,13 +1545,15 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayNestedNestedType) {
15401545
new StructScalar({MakeScalar(int32_t{5}), MakeScalar(int32_t{10})}, struct_type)));
15411546
auto rb_schema = schema({field("struct", struct_parent->type())});
15421547
auto rb = RecordBatch::Make(rb_schema, 5, {struct_parent});
1543-
1544-
ASSERT_OK_AND_ASSIGN(auto expected_array,
1545-
MakeStatisticsArray(R"([null,4])",
1546-
{{ARROW_STATISTICS_KEY_ROW_COUNT_EXACT},
1547-
{ARROW_STATISTICS_KEY_MAX_VALUE_EXACT}},
1548-
{{5}, {expected_scalar}}));
1549-
AssertArraysEqual(*expected_array, *rb->MakeStatisticsArray().ValueOrDie(), true);
1548+
ASSERT_OK_AND_ASSIGN(auto rb_stat, rb->MakeStatisticsArray())
1549+
ASSERT_OK_AND_ASSIGN(
1550+
auto expected_array,
1551+
MakeMockStatisticsArray(R"([null,4])",
1552+
{{ARROW_STATISTICS_KEY_ROW_COUNT_EXACT},
1553+
{ARROW_STATISTICS_KEY_MAX_VALUE_EXACT}},
1554+
{{ArrayStatistics::ValueType{int64_t{5}}},
1555+
{ArrayStatistics::ValueType{expected_scalar}}}));
1556+
AssertArraysEqual(*expected_array, *rb_stat, true);
15501557
}
15511558

15521559
template <typename DataType>

0 commit comments

Comments
 (0)