@@ -10,6 +10,28 @@ extern "C" {
10
10
#include " utils/fmgrprotos.h"
11
11
}
12
12
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
+
13
35
namespace NYql {
14
36
15
37
Y_UNIT_TEST_SUITE (TArrowUtilsTests) {
@@ -49,25 +71,14 @@ Y_UNIT_TEST(PgConvertNumericDouble) {
49
71
50
72
auto result = PgConvertNumeric<double >(array);
51
73
const auto & data = result->data ();
74
+
75
+
52
76
53
77
const char * expected[] = {
54
78
" 1.1" , " 31.37" , nullptr , " -1.337" , " 0"
55
79
};
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);
71
82
}
72
83
73
84
Y_UNIT_TEST (PgConvertNumericInt) {
@@ -89,21 +100,8 @@ Y_UNIT_TEST(PgConvertNumericInt) {
89
100
const char * expected[] = {
90
101
" 11" , " 3137" , nullptr , " -1337" , " 0"
91
102
};
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);
107
105
}
108
106
109
107
Y_UNIT_TEST (PgConvertDate32Date) {
@@ -150,5 +148,4 @@ Y_UNIT_TEST(PgConvertDate32Date) {
150
148
151
149
} // Y_UNIT_TEST_SUITE(TArrowUtilsTests)
152
150
153
- } // namespace NYql
154
-
151
+ } // namespace NYql
0 commit comments