44
55#include < library/cpp/string_utils/base64/base64.h>
66
7+ #include < google/protobuf/text_format.h>
8+
79#include < util/charset/utf8.h>
10+ #include < util/string/builder.h>
811#include < util/string/cast.h>
912#include < util/string/escape.h>
1013#include < util/string/printf.h>
14+ #include < util/stream/output.h>
1115#include < ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/value/value.h>
1216
1317namespace NKikimr {
@@ -28,14 +32,33 @@ TValue TValue::Create(const NKikimrMiniKQL::TResult& result) {
2832 return TValue::Create (result.GetValue (), result.GetType ());
2933}
3034
35+ static bool ValueProtobufHasEmptyPayload (const NKikimrMiniKQL::TValue& value) {
36+ bool emptyPayload = true ;
37+ emptyPayload &= (value.value_value_case () == value.VALUE_VALUE_NOT_SET );
38+ emptyPayload &= value.GetList ().empty ();
39+ emptyPayload &= value.GetTuple ().empty ();
40+ emptyPayload &= value.GetStruct ().empty ();
41+ emptyPayload &= value.GetDict ().empty ();
42+ emptyPayload &= !value.HasHi128 ();
43+ emptyPayload &= !value.HasVariantIndex ();
44+ // 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.
45+ // If the value is not considered empty, the wrapper will return a non-empty value, for which no accessor can return a meaningful value.
46+ constexpr bool checkUnknownFields = false ;
47+ if (checkUnknownFields) {
48+ emptyPayload = emptyPayload && value.unknown_fields ().empty ();
49+ }
50+ return emptyPayload;
51+ }
52+
3153bool TValue::HaveValue () const {
3254 return !IsNull ();
3355}
3456
3557bool TValue::IsNull () const {
3658 if (&Value == &Null)
3759 return true ;
38- return Value.ByteSize () == 0 ;
60+
61+ return ValueProtobufHasEmptyPayload (Value);
3962}
4063
4164TValue TValue::operator [](const char * name) const {
@@ -108,6 +131,21 @@ TVector<TString> TValue::GetMembersNames() const {
108131 return members;
109132}
110133
134+ TString TValue::DumpToString () const {
135+ TStringBuilder dump;
136+ TString res;
137+ ::google::protobuf::TextFormat::PrintToString (Type, &res);
138+ dump << " Type:" << Endl << res << Endl;
139+ ::google::protobuf::TextFormat::PrintToString (Value, &res);
140+ dump << " Value:" << Endl << res << Endl;
141+ return std::move (dump);
142+ }
143+
144+ void TValue::DumpValue () const {
145+ Cerr << DumpToString ();
146+ }
147+
148+
111149TWriteValue TWriteValue::Create (NKikimrMiniKQL::TValue& value, NKikimrMiniKQL::TType& type) {
112150 return TWriteValue (value, type);
113151}
@@ -453,7 +491,7 @@ TString TValue::GetDataText() const {
453491 case NScheme::NTypeIds::Datetime64:
454492 case NScheme::NTypeIds::Timestamp64:
455493 case NScheme::NTypeIds::Interval64:
456- return ToString (Value.GetInt64 ());
494+ return ToString (Value.GetInt64 ());
457495 case NScheme::NTypeIds::JsonDocument:
458496 return " \" <JsonDocument>\" " ;
459497 case NScheme::NTypeIds::Uuid:
0 commit comments