@@ -1590,6 +1590,91 @@ Y_UNIT_TEST_SUITE(Viewer) {
15901590 size_t AuthorizeTicketFails = 0 ;
15911591 };
15921592
1593+ TString PostQuery (TKeepAliveHttpClient& httpClient, TString query, TString action = " " , TString transactionMode = " " ) {
1594+ TStringStream requestBody;
1595+ requestBody
1596+ << " { \" query\" : \" " << query << " \" ,"
1597+ << " \" database\" : \" /Root\" ,"
1598+ << " \" action\" : \" " << action << " \" ,"
1599+ << " \" syntax\" : \" yql_v1\" ,"
1600+ << " \" transaction_mode\" : \" " << transactionMode << " \" ,"
1601+ << " \" stats\" : \" none\" }" ;
1602+ TStringStream responseStream;
1603+ TKeepAliveHttpClient::THeaders headers;
1604+ headers[" Content-Type" ] = " application/json" ;
1605+ headers[" Authorization" ] = " test_ydb_token" ;
1606+ const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost (" /viewer/query?timeout=600000&base64=false&schema=modern" , requestBody.Str (), &responseStream, headers);
1607+ const TString response = responseStream.ReadAll ();
1608+ UNIT_ASSERT_EQUAL_C (statusCode, HTTP_OK, statusCode << " : " << response);
1609+ return response;
1610+ }
1611+
1612+ Y_UNIT_TEST (ExecuteQueryDoesntExecuteSchemeOperationsInsideTransation) {
1613+ TPortManager tp;
1614+ ui16 port = tp.GetPort (2134 );
1615+ ui16 grpcPort = tp.GetPort (2135 );
1616+ ui16 monPort = tp.GetPort (8765 );
1617+ auto settings = TServerSettings (port);
1618+ settings.InitKikimrRunConfig ()
1619+ .SetNodeCount (1 )
1620+ .SetUseRealThreads (true )
1621+ .SetDomainName (" Root" )
1622+ .SetMonitoringPortOffset (monPort, true );
1623+
1624+ TServer server (settings);
1625+ server.EnableGRpc (grpcPort);
1626+ TClient client (settings);
1627+ client.InitRootScheme ();
1628+
1629+ TTestActorRuntime& runtime = *server.GetRuntime ();
1630+ runtime.SetLogPriority (NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE);
1631+
1632+ TKeepAliveHttpClient httpClient (" localhost" , monPort);
1633+
1634+ // Scheme operations cannot be executed inside transaction
1635+ TString response = PostQuery (httpClient, " CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));" , " execute-query" , " serializable-read-write" );
1636+ {
1637+ NJson::TJsonReaderConfig jsonCfg;
1638+ NJson::TJsonValue json;
1639+ NJson::ReadJsonTree (response, &jsonCfg, &json, /* throwOnError = */ true );
1640+ UNIT_ASSERT_EQUAL_C (json[" status" ].GetString (), " PRECONDITION_FAILED" , response);
1641+ }
1642+ }
1643+
1644+ Y_UNIT_TEST (UseTransactionWhenExecuteDataActionQuery) {
1645+ TPortManager tp;
1646+ ui16 port = tp.GetPort (2134 );
1647+ ui16 grpcPort = tp.GetPort (2135 );
1648+ ui16 monPort = tp.GetPort (8765 );
1649+ auto settings = TServerSettings (port);
1650+ settings.InitKikimrRunConfig ()
1651+ .SetNodeCount (1 )
1652+ .SetUseRealThreads (true )
1653+ .SetDomainName (" Root" )
1654+ .SetMonitoringPortOffset (monPort, true );
1655+
1656+ TServer server (settings);
1657+ server.EnableGRpc (grpcPort);
1658+ TClient client (settings);
1659+ client.InitRootScheme ();
1660+
1661+ TTestActorRuntime& runtime = *server.GetRuntime ();
1662+ runtime.SetLogPriority (NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE);
1663+
1664+ TKeepAliveHttpClient httpClient (" localhost" , monPort);
1665+
1666+ PostQuery (httpClient, " CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));" , " execute-query" );
1667+ PostQuery (httpClient, " INSERT INTO `/Root/Test` (Key, Value) VALUES (1, 'testvalue');" , " execute-query" );
1668+ TString response = PostQuery (httpClient, " SELECT * FROM `/Root/Test`;" , " execute-data" );
1669+ {
1670+ NJson::TJsonReaderConfig jsonCfg;
1671+ NJson::TJsonValue json;
1672+ NJson::ReadJsonTree (response, &jsonCfg, &json, /* throwOnError = */ true );
1673+ auto resultSets = json[" result" ].GetArray ();
1674+ UNIT_ASSERT_EQUAL_C (1 , resultSets.size (), response);
1675+ }
1676+ }
1677+
15931678 Y_UNIT_TEST (FloatPointJsonQuery) {
15941679 TPortManager tp;
15951680 ui16 port = tp.GetPort (2134 );
@@ -1620,7 +1705,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
16201705 "database": "/Root",
16211706 "action": "execute-script",
16221707 "syntax": "yql_v1",
1623- "stats": "profile "
1708+ "stats": "none "
16241709 })json" ;
16251710 const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost (" /viewer/query?timeout=600000&base64=false&schema=modern" , requestBody, &responseStream, headers);
16261711 const TString response = responseStream.ReadAll ();
0 commit comments