Skip to content

Commit

Permalink
add result checking function in arrow_ut.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
--list committed Jan 17, 2024
1 parent bc9e922 commit f22bb11
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions ydb/library/yql/parser/pg_wrapper/ut/arrow_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ extern "C" {
#include "utils/fmgrprotos.h"
}

namespace {
void check_result(const char ** expected, std::shared_ptr<arrow::ArrayData> data) {

NYql::NUdf::TStringBlockReader<arrow::BinaryType, true> reader;
for (int i = 0; i < data->length; i++) {
auto item = reader.GetItem(*data, i);
if (!item) {
UNIT_ASSERT(expected[i] == nullptr);
} else {
const char* addr = item.AsStringRef().Data() + sizeof(void*);
UNIT_ASSERT(expected[i] != nullptr);
UNIT_ASSERT_VALUES_EQUAL(
TString(DatumGetCString(DirectFunctionCall1(numeric_out, (Datum)addr))),
expected[i]
);
}
}
}

}

namespace NYql {

Y_UNIT_TEST_SUITE(TArrowUtilsTests) {
Expand Down Expand Up @@ -49,25 +70,14 @@ Y_UNIT_TEST(PgConvertNumericDouble) {

auto result = PgConvertNumeric<double>(array);
const auto& data = result->data();



const char* expected[] = {
"1.1", "31.37", nullptr, "-1.337", "0"
};

NUdf::TStringBlockReader<arrow::BinaryType, true> reader;
for (int i = 0; i < 5; i++) {
auto item = reader.GetItem(*data, i);
if (!item) {
UNIT_ASSERT(expected[i] == nullptr);
} else {
const char* addr = item.AsStringRef().Data() + sizeof(void*);
UNIT_ASSERT(expected[i] != nullptr);
UNIT_ASSERT_VALUES_EQUAL(
TString(DatumGetCString(DirectFunctionCall1(numeric_out, (Datum)addr))),
expected[i]
);
}
}

check_result(expected, data);
}

Y_UNIT_TEST(PgConvertNumericInt) {
Expand All @@ -89,21 +99,8 @@ Y_UNIT_TEST(PgConvertNumericInt) {
const char* expected[] = {
"11", "3137", nullptr, "-1337", "0"
};

NUdf::TStringBlockReader<arrow::BinaryType, true> reader;
for (int i = 0; i < 5; i++) {
auto item = reader.GetItem(*data, i);
if (!item) {
UNIT_ASSERT(expected[i] == nullptr);
} else {
const char* addr = item.AsStringRef().Data() + sizeof(void*);
UNIT_ASSERT(expected[i] != nullptr);
UNIT_ASSERT_VALUES_EQUAL(
TString(DatumGetCString(DirectFunctionCall1(numeric_out, (Datum)addr))),
expected[i]
);
}
}

check_result(expected, data);
}

Y_UNIT_TEST(PgConvertDate32Date) {
Expand Down

0 comments on commit f22bb11

Please sign in to comment.