Skip to content

Commit 05c1534

Browse files
adameatKamil Khamitov
authored andcommitted
correctly handle inf values in streaming query (ydb-platform#14875)
1 parent 671ed92 commit 05c1534

File tree

6 files changed

+17
-35
lines changed

6 files changed

+17
-35
lines changed

ydb/core/viewer/json_pipe_req.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ TString TViewerPipeClient::GetHTTPOKJSON(const NJson::TJsonValue& response, TIns
764764

765765
TString TViewerPipeClient::GetHTTPOKJSON(const google::protobuf::Message& response, TInstant lastModified) {
766766
TStringStream json;
767-
NProtobufJson::Proto2Json(response, json, Proto2JsonConfig);
767+
Proto2Json(response, json);
768768
return GetHTTPOKJSON(json.Str(), lastModified);
769769
}
770770

ydb/core/viewer/json_pipe_req.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ class TViewerPipeClient : public TActorBootstrapped<TViewerPipeClient> {
281281
void InitConfig(const TRequestSettings& settings);
282282
void BuildParamsFromJson(TStringBuf data);
283283
void SetupTracing(const TString& handlerName);
284+
285+
template<typename TJson>
286+
void Proto2Json(const NProtoBuf::Message& proto, TJson& json) {
287+
try {
288+
NProtobufJson::Proto2Json(proto, json, Proto2JsonConfig);
289+
}
290+
catch (const std::exception& e) {
291+
json = TStringBuilder() << "error converting " << proto.GetTypeName() << " to json: " << e.what();
292+
}
293+
}
294+
284295
void ClosePipes();
285296
ui32 FailPipeConnect(TTabletId tabletId);
286297

ydb/core/viewer/storage_groups.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
#include "json_pipe_req.h"
44
#include "log.h"
55
#include "viewer_helper.h"
6-
#include <library/cpp/protobuf/json/proto2json.h>
76
#include <ydb/library/actors/interconnect/interconnect.h>
87

98
namespace NKikimr::NViewer {
109

11-
using namespace NProtobufJson;
12-
1310
using TNodeId = ui32;
1411
using TGroupId = ui32;
1512

@@ -2180,14 +2177,7 @@ class TStorageGroups : public TViewerPipeClient {
21802177
}
21812178
}
21822179
AddEvent("RenderingResult");
2183-
TStringStream out;
2184-
Proto2Json(json, out, {
2185-
.EnumMode = TProto2JsonConfig::EnumValueMode::EnumName,
2186-
.StringifyNumbers = TProto2JsonConfig::EStringifyNumbersMode::StringifyInt64Always,
2187-
.WriteNanAsString = true,
2188-
});
2189-
AddEvent("ResultReady");
2190-
TBase::ReplyAndPassAway(GetHTTPOKJSON(out.Str()));
2180+
TBase::ReplyAndPassAway(GetHTTPOKJSON(json));
21912181
}
21922182

21932183
static YAML::Node GetSwagger() {

ydb/core/viewer/viewer_cluster.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
#include "viewer.h"
55
#include "viewer_helper.h"
66
#include "viewer_tabletinfo.h"
7-
#include <library/cpp/protobuf/json/proto2json.h>
87

98
namespace NKikimr::NViewer {
109

11-
using namespace NProtobufJson;
1210
using namespace NActors;
1311
using namespace NNodeWhiteboard;
1412

@@ -849,14 +847,7 @@ class TJsonCluster : public TViewerPipeClient {
849847
worstNodes += nodes;
850848
}
851849
ClusterInfo.SetOverall(GetViewerFlag(worstState));
852-
TStringStream out;
853-
Proto2Json(ClusterInfo, out, {
854-
.EnumMode = TProto2JsonConfig::EnumValueMode::EnumName,
855-
.MapAsObject = true,
856-
.StringifyNumbers = TProto2JsonConfig::EStringifyNumbersMode::StringifyInt64Always,
857-
.WriteNanAsString = true,
858-
});
859-
TBase::ReplyAndPassAway(GetHTTPOKJSON(out.Str()));
850+
TBase::ReplyAndPassAway(GetHTTPOKJSON(ClusterInfo));
860851
}
861852

862853
public:

ydb/core/viewer/viewer_nodes.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
#include "viewer_helper.h"
77
#include "viewer_tabletinfo.h"
88
#include "wb_group.h"
9-
#include <library/cpp/protobuf/json/proto2json.h>
109

1110
namespace NKikimr::NViewer {
1211

13-
using namespace NProtobufJson;
1412
using namespace NActors;
1513
using namespace NNodeWhiteboard;
1614

@@ -3230,15 +3228,7 @@ class TJsonNodes : public TViewerPipeClient {
32303228
}
32313229
}
32323230
AddEvent("RenderingResult");
3233-
TStringStream out;
3234-
Proto2Json(json, out, {
3235-
.EnumMode = TProto2JsonConfig::EnumValueMode::EnumName,
3236-
.MapAsObject = true,
3237-
.StringifyNumbers = TProto2JsonConfig::EStringifyNumbersMode::StringifyInt64Always,
3238-
.WriteNanAsString = true,
3239-
});
3240-
AddEvent("ResultReady");
3241-
TBase::ReplyAndPassAway(GetHTTPOKJSON(out.Str()));
3231+
TBase::ReplyAndPassAway(GetHTTPOKJSON(json));
32423232
}
32433233

32443234
static YAML::Node GetSwagger() {

ydb/core/viewer/viewer_query.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class TJsonQuery : public TViewerPipeClient {
603603
NJson::ReadJsonTree(progress.GetQueryPlan(), &(json["plan"]));
604604
}
605605
if (progress.HasQueryStats()) {
606-
NProtobufJson::Proto2Json(progress.GetQueryStats(), json["stats"]);
606+
Proto2Json(progress.GetQueryStats(), json["stats"]);
607607
}
608608
StreamJsonResponse(json);
609609
}
@@ -830,7 +830,7 @@ class TJsonQuery : public TViewerPipeClient {
830830
NJson::ReadJsonTree(response.GetQueryPlan(), &(jsonResponse["plan"]));
831831
}
832832
if (response.HasQueryStats()) {
833-
NProtobufJson::Proto2Json(response.GetQueryStats(), jsonResponse["stats"]);
833+
Proto2Json(response.GetQueryStats(), jsonResponse["stats"]);
834834
}
835835
}
836836
catch (const std::exception& ex) {

0 commit comments

Comments
 (0)