Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions ydb/public/lib/value/ut/value_ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#include <ydb/public/lib/value/value.h>
#include <ydb/library/mkql_proto/protos/minikql.pb.h>

#include <library/cpp/testing/gtest/gtest.h>

TEST(TValue, FieldsCount) {
ASSERT_EQ(NKikimrMiniKQL::TValue::GetDescriptor()->field_count(), 18) << "update the NKikimr::NClient::TValue wrapper to support new fields";
}
13 changes: 13 additions & 0 deletions ydb/public/lib/value/ut/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GTEST()

SIZE(SMALL)

PEERDIR(
ydb/public/lib/value
)

SRCS(
value_ut.cpp
)

END()
42 changes: 40 additions & 2 deletions ydb/public/lib/value/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

#include <library/cpp/string_utils/base64/base64.h>

#include <google/protobuf/text_format.h>

#include <util/charset/utf8.h>
#include <util/string/builder.h>
#include <util/string/cast.h>
#include <util/string/escape.h>
#include <util/string/printf.h>
#include <util/stream/output.h>
#include <ydb-cpp-sdk/client/value/value.h>

namespace NKikimr {
Expand All @@ -28,14 +32,33 @@ TValue TValue::Create(const NKikimrMiniKQL::TResult& result) {
return TValue::Create(result.GetValue(), result.GetType());
}

static bool ValueProtobufHasEmptyPayload(const NKikimrMiniKQL::TValue& value) {
bool emptyPayload = true;
emptyPayload &= (value.value_value_case() == value.VALUE_VALUE_NOT_SET);
emptyPayload &= value.GetList().empty();
emptyPayload &= value.GetTuple().empty();
emptyPayload &= value.GetStruct().empty();
emptyPayload &= value.GetDict().empty();
emptyPayload &= !value.HasHi128();
emptyPayload &= !value.HasVariantIndex();
// Non-empty unknown fields are a weird case, as they are not accessible through the wrapper and can only be viewed in the debug dump.
// If the value is not considered empty, the wrapper will return a non-empty value, for which no accessor can return a meaningful value.
constexpr bool checkUnknownFields = false;
if (checkUnknownFields) {
emptyPayload = emptyPayload && value.unknown_fields().empty();
}
return emptyPayload;
}

bool TValue::HaveValue() const {
return !IsNull();
}

bool TValue::IsNull() const {
if (&Value == &Null)
return true;
return Value.ByteSize() == 0;

return ValueProtobufHasEmptyPayload(Value);
}

TValue TValue::operator [](const char* name) const {
Expand Down Expand Up @@ -108,6 +131,21 @@ TVector<TString> TValue::GetMembersNames() const {
return members;
}

TString TValue::DumpToString() const {
TStringBuilder dump;
TString res;
::google::protobuf::TextFormat::PrintToString(Type, &res);
dump << "Type:" << Endl << res << Endl;
::google::protobuf::TextFormat::PrintToString(Value, &res);
dump << "Value:" << Endl << res << Endl;
return std::move(dump);
}

void TValue::DumpValue() const {
Cerr << DumpToString();
}


TWriteValue TWriteValue::Create(NKikimrMiniKQL::TValue& value, NKikimrMiniKQL::TType& type) {
return TWriteValue(value, type);
}
Expand Down Expand Up @@ -453,7 +491,7 @@ TString TValue::GetDataText() const {
case NScheme::NTypeIds::Datetime64:
case NScheme::NTypeIds::Timestamp64:
case NScheme::NTypeIds::Interval64:
return ToString(Value.GetInt64());
return ToString(Value.GetInt64());
case NScheme::NTypeIds::JsonDocument:
return "\"<JsonDocument>\"";
case NScheme::NTypeIds::Uuid:
Expand Down
17 changes: 2 additions & 15 deletions ydb/public/lib/value/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <ydb/public/lib/scheme_types/scheme_type_id.h>

#include <util/generic/vector.h>
#include <util/string/builder.h>

#include <google/protobuf/text_format.h>

namespace NKikimr {
namespace NClient {
Expand Down Expand Up @@ -106,19 +103,9 @@ class TValue {
// returns member index by name
int GetMemberIndex(TStringBuf name) const;

TString DumpToString() const {
TStringBuilder dump;
TString res;
::google::protobuf::TextFormat::PrintToString(Type, &res);
dump << "Type:" << Endl << res << Endl;
::google::protobuf::TextFormat::PrintToString(Value, &res);
dump << "Value:" << Endl << res << Endl;
return std::move(dump);
}
TString DumpToString() const;

void DumpValue() const {
Cerr << DumpToString();
}
void DumpValue() const; // dump value to stderr

const NKikimrMiniKQL::TType& GetType() const { return Type; };
const NKikimrMiniKQL::TValue& GetValue() const { return Value; };
Expand Down
4 changes: 4 additions & 0 deletions ydb/public/lib/value/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ PEERDIR(
)

END()

RECURSE_FOR_TESTS(
ut
)
Loading