@@ -31,6 +31,8 @@ class TJsonQuery : public TViewerPipeClient {
3131 TString TransactionMode;
3232 bool Direct = false ;
3333 bool IsBase64Encode = true ;
34+ int LimitRows = 10000 ;
35+ int TotalRows = 0 ;
3436
3537 enum ESchemaType {
3638 Classic,
@@ -89,6 +91,9 @@ class TJsonQuery : public TViewerPipeClient {
8991 if (params.Has (" base64" )) {
9092 IsBase64Encode = FromStringWithDefault<bool >(params.Get (" base64" ), true );
9193 }
94+ if (params.Has (" limit_rows" )) {
95+ LimitRows = std::clamp<int >(FromStringWithDefault<int >(params.Get (" limit_rows" ), 10000 ), 1 , 100000 );
96+ }
9297 Direct = FromStringWithDefault<bool >(params.Get (" direct" ), Direct);
9398 }
9499
@@ -124,6 +129,9 @@ class TJsonQuery : public TViewerPipeClient {
124129 if (requestData.Has (" base64" )) {
125130 IsBase64Encode = requestData[" base64" ].GetBooleanRobust ();
126131 }
132+ if (requestData.Has (" limit_rows" )) {
133+ LimitRows = std::clamp<int >(requestData[" limit_rows" ].GetIntegerRobust (), 1 , 100000 );
134+ }
127135 }
128136 return success;
129137 }
@@ -307,7 +315,13 @@ class TJsonQuery : public TViewerPipeClient {
307315 request.SetAction (NKikimrKqp::QUERY_ACTION_EXPLAIN);
308316 request.SetType (NKikimrKqp::QUERY_TYPE_SQL_SCRIPT);
309317 }
310- if (Stats == " profile" ) {
318+ if (Stats == " none" ) {
319+ request.SetStatsMode (NYql::NDqProto::DQ_STATS_MODE_NONE);
320+ request.SetCollectStats (Ydb::Table::QueryStatsCollection::STATS_COLLECTION_NONE);
321+ } else if (Stats == " basic" ) {
322+ request.SetStatsMode (NYql::NDqProto::DQ_STATS_MODE_BASIC);
323+ request.SetCollectStats (Ydb::Table::QueryStatsCollection::STATS_COLLECTION_BASIC);
324+ } else if (Stats == " profile" ) {
311325 request.SetStatsMode (NYql::NDqProto::DQ_STATS_MODE_PROFILE);
312326 request.SetCollectStats (Ydb::Table::QueryStatsCollection::STATS_COLLECTION_PROFILE);
313327 } else if (Stats == " full" ) {
@@ -479,13 +493,23 @@ class TJsonQuery : public TViewerPipeClient {
479493 }
480494
481495 void HandleReply (NKqp::TEvKqpExecuter::TEvStreamData::TPtr& ev) {
482- const NKikimrKqp::TEvExecuterStreamData& data (ev->Get ()->Record );
496+ NKikimrKqp::TEvExecuterStreamData& data (ev->Get ()->Record );
483497
484- ResultSets.emplace_back ();
485- ResultSets.back () = std::move (data.GetResultSet ());
498+ if (TotalRows < LimitRows) {
499+ int rowsAvailable = LimitRows - TotalRows;
500+ if (data.GetResultSet ().rows_size () > rowsAvailable) {
501+ data.MutableResultSet ()->mutable_rows ()->Truncate (rowsAvailable);
502+ data.MutableResultSet ()->set_truncated (true );
503+ }
504+ TotalRows += data.GetResultSet ().rows_size ();
505+ ResultSets.emplace_back () = std::move (*data.MutableResultSet ());
506+ }
486507
487508 THolder<NKqp::TEvKqpExecuter::TEvStreamDataAck> ack = MakeHolder<NKqp::TEvKqpExecuter::TEvStreamDataAck>();
488509 ack->Record .SetSeqNo (ev->Get ()->Record .GetSeqNo ());
510+ if (TotalRows >= LimitRows) {
511+ ack->Record .SetEnough (true );
512+ }
489513 Send (ev->Sender , ack.Release ());
490514 }
491515
@@ -618,6 +642,9 @@ class TJsonQuery : public TViewerPipeClient {
618642 jsonColumn = ColumnValueToJsonValue (rsParser.ColumnParser (columnNum));
619643 }
620644 }
645+ if (resultSet.Truncated ()) {
646+ jsonResult[" truncated" ] = true ;
647+ }
621648 }
622649 }
623650
0 commit comments