Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 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,28 @@ extern "C" {
#include "utils/fmgrprotos.h"
}

namespace {

void checkResult(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 {

namespace NYql {

Y_UNIT_TEST_SUITE(TArrowUtilsTests) {
Expand Down Expand Up @@ -49,25 +71,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]
);
}
}

checkResult(expected, data);
}

Y_UNIT_TEST(PgConvertNumericInt) {
Expand All @@ -89,21 +100,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]
);
}
}

checkResult(expected, data);
}

Y_UNIT_TEST(PgConvertDate32Date) {
Expand Down Expand Up @@ -150,5 +148,4 @@ Y_UNIT_TEST(PgConvertDate32Date) {

} // Y_UNIT_TEST_SUITE(TArrowUtilsTests)

} // namespace NYql

} // namespace NYql