Skip to content

Commit b07e92f

Browse files
author
kinash-varvara
authored
Add result checking function in arrow_ut.cpp (#1109)
1 parent 680271e commit b07e92f

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

ydb/library/yql/parser/pg_wrapper/ut/arrow_ut.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ extern "C" {
1010
#include "utils/fmgrprotos.h"
1111
}
1212

13+
namespace {
14+
15+
void checkResult(const char ** expected, std::shared_ptr<arrow::ArrayData> data) {
16+
17+
NYql::NUdf::TStringBlockReader<arrow::BinaryType, true> reader;
18+
for (int i = 0; i < data->length; i++) {
19+
auto item = reader.GetItem(*data, i);
20+
if (!item) {
21+
UNIT_ASSERT(expected[i] == nullptr);
22+
} else {
23+
const char* addr = item.AsStringRef().Data() + sizeof(void*);
24+
UNIT_ASSERT(expected[i] != nullptr);
25+
UNIT_ASSERT_VALUES_EQUAL(
26+
TString(DatumGetCString(DirectFunctionCall1(numeric_out, (Datum)addr))),
27+
expected[i]
28+
);
29+
}
30+
}
31+
}
32+
33+
} // namespace {
34+
1335
namespace NYql {
1436

1537
Y_UNIT_TEST_SUITE(TArrowUtilsTests) {
@@ -49,25 +71,14 @@ Y_UNIT_TEST(PgConvertNumericDouble) {
4971

5072
auto result = PgConvertNumeric<double>(array);
5173
const auto& data = result->data();
74+
75+
5276

5377
const char* expected[] = {
5478
"1.1", "31.37", nullptr, "-1.337", "0"
5579
};
56-
57-
NUdf::TStringBlockReader<arrow::BinaryType, true> reader;
58-
for (int i = 0; i < 5; i++) {
59-
auto item = reader.GetItem(*data, i);
60-
if (!item) {
61-
UNIT_ASSERT(expected[i] == nullptr);
62-
} else {
63-
const char* addr = item.AsStringRef().Data() + sizeof(void*);
64-
UNIT_ASSERT(expected[i] != nullptr);
65-
UNIT_ASSERT_VALUES_EQUAL(
66-
TString(DatumGetCString(DirectFunctionCall1(numeric_out, (Datum)addr))),
67-
expected[i]
68-
);
69-
}
70-
}
80+
81+
checkResult(expected, data);
7182
}
7283

7384
Y_UNIT_TEST(PgConvertNumericInt) {
@@ -89,21 +100,8 @@ Y_UNIT_TEST(PgConvertNumericInt) {
89100
const char* expected[] = {
90101
"11", "3137", nullptr, "-1337", "0"
91102
};
92-
93-
NUdf::TStringBlockReader<arrow::BinaryType, true> reader;
94-
for (int i = 0; i < 5; i++) {
95-
auto item = reader.GetItem(*data, i);
96-
if (!item) {
97-
UNIT_ASSERT(expected[i] == nullptr);
98-
} else {
99-
const char* addr = item.AsStringRef().Data() + sizeof(void*);
100-
UNIT_ASSERT(expected[i] != nullptr);
101-
UNIT_ASSERT_VALUES_EQUAL(
102-
TString(DatumGetCString(DirectFunctionCall1(numeric_out, (Datum)addr))),
103-
expected[i]
104-
);
105-
}
106-
}
103+
104+
checkResult(expected, data);
107105
}
108106

109107
Y_UNIT_TEST(PgConvertDate32Date) {
@@ -150,5 +148,4 @@ Y_UNIT_TEST(PgConvertDate32Date) {
150148

151149
} // Y_UNIT_TEST_SUITE(TArrowUtilsTests)
152150

153-
} // namespace NYql
154-
151+
} // namespace NYql

0 commit comments

Comments
 (0)