Skip to content

Commit 8be911b

Browse files
authored
25-1: ReadTable and ReadRows RPC fixes (#15721, #15850) (#16799)
1 parent 0099b9c commit 8be911b

File tree

6 files changed

+151
-27
lines changed

6 files changed

+151
-27
lines changed

ydb/core/grpc_services/rpc_read_rows.cpp

+39-10
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,11 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
585585
for (const auto& colMeta : RequestedColumnsMeta) {
586586
const auto type = getTypeFromColMeta(colMeta);
587587
auto* col = resultSet->Addcolumns();
588-
*col->mutable_type() = NYdb::TProtoAccessor::GetProto(type);
588+
if (colMeta.IsNotNullColumn || colMeta.Type.GetTypeId() == NScheme::NTypeIds::Pg) { // pg type in nullable itself
589+
*col->mutable_type() = NYdb::TProtoAccessor::GetProto(type);
590+
} else {
591+
*col->mutable_type()->mutable_optional_type()->mutable_item() = NYdb::TProtoAccessor::GetProto(type);
592+
}
589593
*col->mutable_name() = colMeta.Name;
590594
}
591595

@@ -615,18 +619,41 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
615619
}
616620
case NScheme::NTypeIds::Decimal: {
617621
using namespace NYql::NDecimal;
618-
619-
const auto loHi = cell.AsValue<std::pair<ui64, i64>>();
620-
Ydb::Value valueProto;
621-
valueProto.set_low_128(loHi.first);
622-
valueProto.set_high_128(loHi.second);
623-
const NYdb::TDecimalValue decimal(valueProto,
624-
{static_cast<ui8>(colMeta.Type.GetDecimalType().GetPrecision()), static_cast<ui8>(colMeta.Type.GetDecimalType().GetScale())});
625-
vb.Decimal(decimal);
622+
623+
NYdb::TDecimalType decimalType{
624+
static_cast<ui8>(colMeta.Type.GetDecimalType().GetPrecision()),
625+
static_cast<ui8>(colMeta.Type.GetDecimalType().GetScale())
626+
};
627+
628+
if (cell.IsNull()) {
629+
vb.EmptyOptional(NYdb::TTypeBuilder().Decimal(decimalType).Build());
630+
} else {
631+
const auto loHi = cell.AsValue<std::pair<ui64, i64>>();
632+
Ydb::Value valueProto;
633+
valueProto.set_low_128(loHi.first);
634+
valueProto.set_high_128(loHi.second);
635+
if (colMeta.IsNotNullColumn) {
636+
vb.Decimal({valueProto, decimalType});
637+
} else {
638+
vb.BeginOptional();
639+
vb.Decimal({valueProto, decimalType});
640+
vb.EndOptional();
641+
}
642+
}
626643
break;
627644
}
628645
default: {
629-
ProtoValueFromCell(vb, colMeta.Type, cell);
646+
if (cell.IsNull()) {
647+
vb.EmptyOptional((NYdb::EPrimitiveType)colMeta.Type.GetTypeId());
648+
} else {
649+
if (colMeta.IsNotNullColumn) {
650+
ProtoValueFromCell(vb, colMeta.Type, cell);
651+
} else {
652+
vb.BeginOptional();
653+
ProtoValueFromCell(vb, colMeta.Type, cell);
654+
vb.EndOptional();
655+
}
656+
}
630657
break;
631658
}
632659
}
@@ -722,13 +749,15 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
722749
, Name(colInfo.Name)
723750
, Type(colInfo.PType)
724751
, PTypeMod(colInfo.PTypeMod)
752+
, IsNotNullColumn(colInfo.IsNotNullColumn)
725753
{
726754
}
727755

728756
ui32 Id;
729757
TString Name;
730758
NScheme::TTypeInfo Type;
731759
TString PTypeMod;
760+
bool IsNotNullColumn;
732761
};
733762
TVector<TColumnMeta> RequestedColumnsMeta;
734763

ydb/core/kqp/ut/opt/kqp_kv_ut.cpp

+69-15
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ Y_UNIT_TEST_SUITE(KqpKv) {
151151
auto res = FormatResultSetYson(selectResult.GetResultSet());
152152
CompareYson(R"(
153153
[
154-
[1858343823u;0u;"abcde"];
155-
[1921763476782200957u;1u;"abcde"];
156-
[3843526951706058091u;2u;"abcde"];
157-
[5765290426629915225u;3u;"abcde"];
158-
[7687053901553772359u;4u;"abcde"]
154+
[[1858343823u];[0u];["abcde"]];
155+
[[1921763476782200957u];[1u];["abcde"]];
156+
[[3843526951706058091u];[2u];["abcde"]];
157+
[[5765290426629915225u];[3u];["abcde"]];
158+
[[7687053901553772359u];[4u];["abcde"]]
159159
]
160160
)", TString{res});
161161
}
@@ -262,11 +262,11 @@ Y_UNIT_TEST_SUITE(KqpKv) {
262262
UNIT_ASSERT_C(selectResult.IsSuccess(), selectResult.GetIssues().ToString());
263263
auto res = FormatResultSetYson(selectResult.GetResultSet());
264264
CompareYson(R"([
265-
[10u;0u;"abcde"];
266-
[11u;1u;"abcde"];
267-
[12u;2u;"abcde"];
268-
[13u;3u;"abcde"];
269-
[14u;4u;"abcde"]
265+
[[10u];[0u];["abcde"]];
266+
[[11u];[1u];["abcde"]];
267+
[[12u];[2u];["abcde"]];
268+
[[13u];[3u];["abcde"]];
269+
[[14u];[4u];["abcde"]]
270270
])", TString{res});
271271
}
272272
{
@@ -363,7 +363,7 @@ Y_UNIT_TEST_SUITE(KqpKv) {
363363
UNIT_ASSERT_C(selectResult.IsSuccess(), selectResult.GetIssues().ToString());
364364

365365
auto res = FormatResultSetYson(selectResult.GetResultSet());
366-
CompareYson(Sprintf("[[%du;%du]]", valueToReturn_1, valueToReturn_2), TString{res});
366+
CompareYson(Sprintf("[[[%du];[%du]]]", valueToReturn_1, valueToReturn_2), TString{res});
367367
}
368368

369369
TVector<::ReadRowsPgParam> readRowsPgParams
@@ -729,9 +729,9 @@ Y_UNIT_TEST_SUITE(KqpKv) {
729729
auto res = FormatResultSetYson(selectResult.GetResultSet());
730730
CompareYson(R"(
731731
[
732-
["0.123456789";"0.123456789";"0.123456789";"0.123456789";0u];
733-
["1.123456789";"1000.123456789";"10.123456789";"1000000.123456789";1u];
734-
["2.123456789";"2000.123456789";"20.123456789";"2000000.123456789";2u]
732+
[["0.123456789"];["0.123456789"];["0.123456789"];["0.123456789"];[0u]];
733+
[["1.123456789"];["1000.123456789"];["10.123456789"];["1000000.123456789"];[1u]];
734+
[["2.123456789"];["2000.123456789"];["20.123456789"];["2000000.123456789"];[2u]]
735735
]
736736
)", TString{res});
737737
}
@@ -749,10 +749,64 @@ Y_UNIT_TEST_SUITE(KqpKv) {
749749
auto selectResult = db.ReadRows("/Root/TestTable", keys.Build()).GetValueSync();
750750
UNIT_ASSERT_C(selectResult.IsSuccess(), selectResult.GetIssues().ToString());
751751
auto res = FormatResultSetYson(selectResult.GetResultSet());
752-
CompareYson(R"([["inf";"inf";"inf";"inf";999999999u];])", TString{res});
752+
CompareYson(R"([[["inf"];["inf"];["inf"];["inf"];[999999999u]];])", TString{res});
753753
}
754754
}
755755

756+
Y_UNIT_TEST(ReadRows_Nulls) {
757+
auto settings = TKikimrSettings()
758+
.SetWithSampleTables(false);
759+
auto kikimr = TKikimrRunner{settings};
760+
auto db = kikimr.GetTableClient();
761+
auto session = db.CreateSession().GetValueSync().GetSession();
762+
763+
auto schemeResult = session.ExecuteSchemeQuery(R"(
764+
CREATE TABLE TestTable (
765+
Key Uint64,
766+
Data Uint32,
767+
Value Utf8,
768+
PRIMARY KEY (Key)
769+
);
770+
)").GetValueSync();
771+
UNIT_ASSERT_C(schemeResult.IsSuccess(), schemeResult.GetIssues().ToString());
772+
773+
NYdb::TValueBuilder rows;
774+
rows.BeginList();
775+
for (size_t i = 0; i < 5; ++i) {
776+
rows.AddListItem()
777+
.BeginStruct()
778+
.AddMember("Key").Uint64(i * 1921763474923857134ull + 1858343823)
779+
.EndStruct();
780+
}
781+
rows.EndList();
782+
783+
auto upsertResult = db.BulkUpsert("/Root/TestTable", rows.Build()).GetValueSync();
784+
UNIT_ASSERT_C(upsertResult.IsSuccess(), upsertResult.GetIssues().ToString());
785+
786+
NYdb::TValueBuilder keys;
787+
keys.BeginList();
788+
for (size_t i = 0; i < 5; ++i) {
789+
keys.AddListItem()
790+
.BeginStruct()
791+
.AddMember("Key").Uint64(i * 1921763474923857134ull + 1858343823)
792+
.EndStruct();
793+
}
794+
keys.EndList();
795+
auto selectResult = db.ReadRows("/Root/TestTable", keys.Build()).GetValueSync();
796+
Cerr << "IsSuccess(): " << selectResult.IsSuccess() << " GetStatus(): " << selectResult.GetStatus() << Endl;
797+
UNIT_ASSERT_C(selectResult.IsSuccess(), selectResult.GetIssues().ToString());
798+
auto res = FormatResultSetYson(selectResult.GetResultSet());
799+
CompareYson(R"(
800+
[
801+
[[1858343823u];#;#];
802+
[[1921763476782200957u];#;#];
803+
[[3843526951706058091u];#;#];
804+
[[5765290426629915225u];#;#];
805+
[[7687053901553772359u];#;#]
806+
]
807+
)", TString{res});
808+
}
809+
756810

757811
}
758812

ydb/core/statistics/service/service_impl.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,10 @@ class TStatService : public TActorBootstrapped<TStatService> {
695695

696696
while(parser.TryNextRow()) {
697697
auto& col = parser.ColumnParser("data");
698-
query_response->Data = col.GetString();
698+
// may be not optional from versions before fix of bug https://github.com/ydb-platform/ydb/issues/15701
699+
query_response->Data = col.GetKind() == NYdb::TTypeParser::ETypeKind::Optional
700+
? col.GetOptionalString()
701+
: col.GetString();
699702
}
700703
} else {
701704
SA_LOG_E("[TStatService::ReadRowsResponse] QueryId[ "

ydb/core/tx/datashard/datashard_ut_read_table.cpp

+35-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,41 @@ Y_UNIT_TEST_SUITE(DataShardReadTableSnapshots) {
598598

599599
UNIT_ASSERT(table1state.IsError);
600600
UNIT_ASSERT_VALUES_EQUAL(table1state.LastResult, "ERROR: ExecError\n");
601-
}
601+
}
602+
603+
Y_UNIT_TEST(ReadTableUUID) {
604+
TPortManager pm;
605+
TServerSettings serverSettings(pm.GetPort(2134));
606+
serverSettings.SetDomainName("Root")
607+
.SetUseRealThreads(false);
608+
609+
Tests::TServer::TPtr server = new TServer(serverSettings);
610+
auto &runtime = *server->GetRuntime();
611+
auto sender = runtime.AllocateEdgeActor();
612+
613+
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
614+
runtime.SetLogPriority(NKikimrServices::TX_PROXY, NLog::PRI_DEBUG);
615+
616+
InitRoot(server, sender);
617+
618+
CreateShardedTable(server, sender, "/Root", "table-1",
619+
TShardedTableOptions().Columns({
620+
{"key", "Uuid", true, false},
621+
{"value", "Uuid", false, false}
622+
}));
623+
auto shards = GetTableShards(server, sender, "/Root/table-1");
624+
625+
ExecSQL(server, sender, "UPSERT INTO `/Root/table-1` (key, value) VALUES "
626+
"(Uuid('5e32442b-4613-40b7-8506-b14d86b74ef1'), Uuid('65d4d0aa-1612-4887-86dd-834e4cfc3df5')), "
627+
"(Uuid('bbf1d45a-af5f-4939-b58a-2be39fd2f06e'), Uuid('710c9ea5-9fa2-4606-a35f-608d0556eb6f')), "
628+
"(Uuid('303f21b5-3805-4133-b706-bfc0e071c528'), Uuid('522e048c-9b4b-4d38-8c89-3996cdaa1c8d'));");
629+
630+
auto table1 = TReadTableState(server, MakeReadTableSettings("/Root/table-1")).All();
631+
UNIT_ASSERT_VALUES_EQUAL(table1,
632+
"key = 5e32442b-4613-40b7-8506-b14d86b74ef1, value = 65d4d0aa-1612-4887-86dd-834e4cfc3df5\n"
633+
"key = bbf1d45a-af5f-4939-b58a-2be39fd2f06e, value = 710c9ea5-9fa2-4606-a35f-608d0556eb6f\n"
634+
"key = 303f21b5-3805-4133-b706-bfc0e071c528, value = 522e048c-9b4b-4d38-8c89-3996cdaa1c8d\n");
635+
}
602636

603637
} // Y_UNIT_TEST_SUITE(DataShardReadTableSnapshots)
604638

ydb/core/tx/datashard/datashard_ut_read_table.h

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ namespace NDataShardReadTableTest {
178178
case NYdb::EPrimitiveType::Timestamp:
179179
out << parser.GetTimestamp();
180180
break;
181+
case NYdb::EPrimitiveType::Uuid:
182+
out << parser.GetUuid().ToString();
183+
break;
181184

182185
default:
183186
Y_ABORT("Unhandled");

ydb/core/tx/datashard/read_table_scan.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Y_FORCE_INLINE bool AddCell(TOutValue& row, NScheme::TTypeInfo type, const TCell
117117
val.set_bytes_value(cell.Data(), cell.Size());
118118
break;
119119
}
120+
case NUdf::TDataType<NUdf::TUuid>::Id:
120121
case NUdf::TDataType<NUdf::TDecimal>::Id: {
121122
struct TCellData {
122123
ui64 Low;

0 commit comments

Comments
 (0)