Skip to content

Commit 3296632

Browse files
authored
YMQ: a couple of fixes (for stable-24-3) (#10082)
1 parent dcbe1a9 commit 3296632

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

ydb/core/http_proxy/json_proto_conversion.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ inline TString ProxyFieldNameConverter(const google::protobuf::FieldDescriptor&
2323

2424
class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
2525
public:
26-
TYdsProtoToJsonPrinter(const google::protobuf::Reflection* reflection,
27-
const NProtobufJson::TProto2JsonConfig& config,
26+
TYdsProtoToJsonPrinter(const NProtobufJson::TProto2JsonConfig& config,
2827
bool skipBase64Encode)
2928
: NProtobufJson::TProto2JsonPrinter(config)
30-
, ProtoReflection(reflection)
3129
, SkipBase64Encode(skipBase64Encode)
3230
{}
3331

@@ -61,14 +59,15 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
6159
return Base64Encode(str);
6260
};
6361

62+
auto* reflection = proto.GetReflection();
6463
if (field.is_repeated()) {
65-
for (int i = 0, endI = ProtoReflection->FieldSize(proto, &field); i < endI; ++i) {
64+
for (int i = 0, endI = reflection->FieldSize(proto, &field); i < endI; ++i) {
6665
PrintStringValue<false>(field, TStringBuf(),
67-
maybeBase64Encode(proto.GetReflection()->GetRepeatedString(proto, &field, i)), json);
66+
maybeBase64Encode(reflection->GetRepeatedString(proto, &field, i)), json);
6867
}
6968
} else {
7069
PrintStringValue<true>(field, key,
71-
maybeBase64Encode(proto.GetReflection()->GetString(proto, &field)), json);
70+
maybeBase64Encode(reflection->GetString(proto, &field)), json);
7271
}
7372
return;
7473
}
@@ -82,13 +81,14 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
8281
key = MakeKey(field);
8382
}
8483

84+
auto* reflection = proto.GetReflection();
8585
if (field.is_repeated()) {
86-
for (int i = 0, endI = ProtoReflection->FieldSize(proto, &field); i < endI; ++i) {
87-
double value = proto.GetReflection()->GetRepeatedInt64(proto, &field, i) / 1000.0;
86+
for (int i = 0, endI = reflection->FieldSize(proto, &field); i < endI; ++i) {
87+
double value = reflection->GetRepeatedInt64(proto, &field, i) / 1000.0;
8888
PrintDoubleValue<false>(TStringBuf(), value, json);
8989
}
9090
} else {
91-
double value = proto.GetReflection()->GetInt64(proto, &field) / 1000.0;
91+
double value = reflection->GetInt64(proto, &field) / 1000.0;
9292
PrintDoubleValue<true>(key, value, json);
9393
}
9494
return;
@@ -103,19 +103,20 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
103103
key = MakeKey(field);
104104
}
105105

106+
auto* reflection = proto.GetReflection();
106107
if (field.is_repeated()) {
107-
for (int i = 0, endI = ProtoReflection->FieldSize(proto, &field); i < endI; ++i) {
108-
auto value = proto.GetReflection()->GetRepeatedString(proto, &field, i);
108+
for (int i = 0, endI = reflection->FieldSize(proto, &field); i < endI; ++i) {
109+
auto value = reflection->GetRepeatedString(proto, &field, i);
109110
if (!value.empty()) {
110111
PrintStringValue<false>(field, TStringBuf(),
111-
proto.GetReflection()->GetRepeatedString(proto, &field, i), json);
112+
reflection->GetRepeatedString(proto, &field, i), json);
112113
}
113114
}
114115
} else {
115-
auto value = proto.GetReflection()->GetString(proto, &field);
116+
auto value = reflection->GetString(proto, &field);
116117
if (!value.empty()) {
117118
PrintStringValue<true>(field, key,
118-
proto.GetReflection()->GetString(proto, &field), json);
119+
reflection->GetString(proto, &field), json);
119120
}
120121
}
121122
return;
@@ -126,7 +127,6 @@ class TYdsProtoToJsonPrinter : public NProtobufJson::TProto2JsonPrinter {
126127
}
127128

128129
private:
129-
const google::protobuf::Reflection* ProtoReflection = nullptr;
130130
bool SkipBase64Encode;
131131
};
132132

@@ -137,7 +137,7 @@ inline void ProtoToJson(const NProtoBuf::Message& resp, NJson::TJsonValue& value
137137
.SetNameGenerator(ProxyFieldNameConverter)
138138
.SetMapAsObject(true)
139139
.SetEnumMode(NProtobufJson::TProto2JsonConfig::EnumName);
140-
TYdsProtoToJsonPrinter printer(resp.GetReflection(), config, skipBase64Encode);
140+
TYdsProtoToJsonPrinter printer(config, skipBase64Encode);
141141
printer.Print(resp, *NProtobufJson::CreateJsonMapOutput(value));
142142
}
143143

ydb/core/http_proxy/ut/http_proxy_ut.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,10 @@ Y_UNIT_TEST_SUITE(TestHttpProxy) {
19701970
UNIT_ASSERT(!GetByPath<TString>(succesful0, "MD5OfMessageAttributes").empty());
19711971
UNIT_ASSERT(!GetByPath<TString>(succesful0, "MD5OfMessageBody").empty());
19721972
UNIT_ASSERT(!GetByPath<TString>(succesful0, "MessageId").empty());
1973+
1974+
NJson::TJsonValue receiveMessageReq;
1975+
receiveMessageReq["QueueUrl"] = resultQueueUrl;
1976+
res = SendHttpRequest("/Root", "AmazonSQS.ReceiveMessage", std::move(receiveMessageReq), FormAuthorizationStr("ru-central1"));
19731977
}
19741978

19751979
Y_UNIT_TEST_F(TestDeleteMessageBatch, THttpProxyTestMock) {

ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ Y_UNIT_TEST(ProtoMapToJson) {
202202
}
203203
}
204204

205+
Y_UNIT_TEST(ProtoMapToJson_ReceiveMessageResult) {
206+
// Test using ReceiveMessageResult that has a repeated field with TRANSFORM_BASE64.
207+
// Before fix it failed on messages with attributes.
208+
{
209+
Ydb::Ymq::V1::ReceiveMessageResult message;
210+
message.add_messages()->mutable_message_attributes()->insert({google::protobuf::MapPair<TString, Ydb::Ymq::V1::MessageAttribute>("a", {})});
211+
212+
NJson::TJsonValue jsonObject;
213+
NKikimr::NHttpProxy::ProtoToJson(message, jsonObject, false);
214+
}
215+
}
216+
205217
Y_UNIT_TEST(NlohmannJsonToProtoMap) {
206218
{
207219
nlohmann::json jsonObject;

ydb/public/api/protos/draft/ymq.proto

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ message ReceiveMessageResponse {
194194
message Message {
195195
map<string, string> attributes = 1;
196196
string body = 2;
197-
string m_d_5_of_body = 3;
198-
string m_d_5_of_message_attributes = 4;
197+
string m_d_5_of_body = 3 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
198+
string m_d_5_of_message_attributes = 4 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
199199
map<string, MessageAttribute> message_attributes = 5;
200200
string message_id = 6;
201201
string receipt_handle = 7;
@@ -221,9 +221,9 @@ message SendMessageResponse {
221221
}
222222

223223
message SendMessageResult {
224-
string m_d_5_of_message_attributes = 1;
225-
string m_d_5_of_message_body= 2;
226-
string m_d_5_of_message_system_attributes= 3;
224+
string m_d_5_of_message_attributes = 1 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
225+
string m_d_5_of_message_body= 2 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
226+
string m_d_5_of_message_system_attributes= 3 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
227227
string message_id = 4;
228228
string sequence_number = 5;
229229
}
@@ -248,10 +248,10 @@ message SendMessageBatchRequestEntry {
248248

249249
message SendMessageBatchResultEntry {
250250
string id = 1;
251-
string m_d_5_of_message_body = 2;
251+
string m_d_5_of_message_body = 2 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
252252
string message_id = 3;
253-
string m_d_5_of_message_attributes = 4;
254-
string m_d_5_of_message_system_attributes = 5;
253+
string m_d_5_of_message_attributes = 4 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
254+
string m_d_5_of_message_system_attributes = 5 [(Ydb.FieldTransformation.FieldTransformer) = TRANSFORM_EMPTY_TO_NOTHING];
255255
string sequence_number = 6;
256256
}
257257

0 commit comments

Comments
 (0)