Skip to content

Commit 947652f

Browse files
authored
Merge b11fe2f into 423d2b7
2 parents 423d2b7 + b11fe2f commit 947652f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

ydb/core/viewer/viewer_query.h

+6
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,13 @@ class TJsonQuery : public TViewerPipeClient {
437437
}
438438

439439
TStringStream stream;
440+
constexpr ui32 doubleNDigits = std::numeric_limits<double>::max_digits10;
441+
constexpr ui32 floatNDigits = std::numeric_limits<float>::max_digits10;
442+
constexpr EFloatToStringMode floatMode = EFloatToStringMode::PREC_NDIGITS;
440443
NJson::WriteJson(&stream, &jsonResponse, {
444+
.DoubleNDigits = doubleNDigits,
445+
.FloatNDigits = floatNDigits,
446+
.FloatToStringMode = floatMode,
441447
.ValidateUtf8 = false,
442448
.WriteNanAsString = true,
443449
});

ydb/core/viewer/viewer_ut.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,56 @@ Y_UNIT_TEST_SUITE(Viewer) {
15891589
size_t AuthorizeTicketFails = 0;
15901590
};
15911591

1592+
Y_UNIT_TEST(FloatPointJsonQuery) {
1593+
TPortManager tp;
1594+
ui16 port = tp.GetPort(2134);
1595+
ui16 grpcPort = tp.GetPort(2135);
1596+
ui16 monPort = tp.GetPort(8765);
1597+
auto settings = TServerSettings(port);
1598+
settings.InitKikimrRunConfig()
1599+
.SetNodeCount(1)
1600+
.SetUseRealThreads(true)
1601+
.SetDomainName("Root")
1602+
.SetMonitoringPortOffset(monPort, true);
1603+
1604+
TServer server(settings);
1605+
server.EnableGRpc(grpcPort);
1606+
TClient client(settings);
1607+
1608+
TTestActorRuntime& runtime = *server.GetRuntime();
1609+
runtime.SetLogPriority(NKikimrServices::GRPC_SERVER, NLog::PRI_TRACE);
1610+
runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE);
1611+
1612+
TKeepAliveHttpClient httpClient("localhost", monPort);
1613+
TStringStream responseStream;
1614+
TKeepAliveHttpClient::THeaders headers;
1615+
headers["Content-Type"] = "application/json";
1616+
headers["Authorization"] = "test_ydb_token";
1617+
TString requestBody = R"json({
1618+
"query": "SELECT cast('311111111113.222222223' as Double);",
1619+
"database": "/Root",
1620+
"action": "execute-script",
1621+
"syntax": "yql_v1",
1622+
"stats": "profile"
1623+
})json";
1624+
const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/query?timeout=600000&base64=false&schema=modern", requestBody, &responseStream, headers);
1625+
const TString response = responseStream.ReadAll();
1626+
UNIT_ASSERT_EQUAL_C(statusCode, HTTP_OK, statusCode << ": " << response);
1627+
{
1628+
NJson::TJsonReaderConfig jsonCfg;
1629+
1630+
NJson::TJsonValue json;
1631+
NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true);
1632+
1633+
auto resultSets = json["result"].GetArray();
1634+
UNIT_ASSERT_EQUAL_C(1, resultSets.size(), response);
1635+
1636+
double parsed = resultSets.begin()->GetArray().begin()->GetDouble();
1637+
double expected = 311111111113.22222;
1638+
UNIT_ASSERT_DOUBLES_EQUAL(parsed, expected, 0.00001);
1639+
}
1640+
}
1641+
15921642
Y_UNIT_TEST(AuthorizeYdbTokenWithDatabaseAttributes) {
15931643
TPortManager tp;
15941644
ui16 port = tp.GetPort(2134);

0 commit comments

Comments
 (0)