@@ -39,6 +39,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
3939 TString Stats;
4040 TString Syntax;
4141 TString QueryId;
42+ TString TransactionMode;
4243 bool Direct = false ;
4344 bool IsBase64Encode = true ;
4445
@@ -82,6 +83,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
8283 Schema = StringToSchemaType (schemaStr);
8384 Syntax = params.Get (" syntax" );
8485 QueryId = params.Get (" query_id" );
86+ TransactionMode = params.Get (" transaction_mode" );
8587 Direct = FromStringWithDefault<bool >(params.Get (" direct" ), Direct);
8688 IsBase64Encode = FromStringWithDefault<bool >(params.Get (" base64" ), true );
8789 }
@@ -97,6 +99,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
9799 Action = Action.empty () ? requestData[" action" ].GetStringSafe ({}) : Action;
98100 Syntax = Syntax.empty () ? requestData[" syntax" ].GetStringSafe ({}) : Syntax;
99101 QueryId = QueryId.empty () ? requestData[" query_id" ].GetStringSafe ({}) : QueryId;
102+ TransactionMode = TransactionMode.empty () ? requestData[" transaction_mode" ].GetStringSafe ({}) : TransactionMode;
100103 }
101104 return success;
102105 }
@@ -198,6 +201,23 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
198201 Send (NKqp::MakeKqpProxyID (SelfId ().NodeId ()), event.release ());
199202 }
200203
204+ bool SetTransactionMode (NKikimrKqp::TQueryRequest& request) {
205+ if (TransactionMode == " serializable-read-write" ) {
206+ request.mutable_txcontrol ()->mutable_begin_tx ()->mutable_serializable_read_write ();
207+ } else if (TransactionMode == " online-read-only" ) {
208+ request.mutable_txcontrol ()->mutable_begin_tx ()->mutable_online_read_only ();
209+ } else if (TransactionMode == " stale-read-only" ) {
210+ request.mutable_txcontrol ()->mutable_begin_tx ()->mutable_stale_read_only ();
211+ } else if (TransactionMode == " snapshot-read-only" ) {
212+ request.mutable_txcontrol ()->mutable_begin_tx ()->mutable_snapshot_read_only ();
213+ } else {
214+ return false ;
215+ }
216+ request.mutable_txcontrol ()->set_commit_tx (true );
217+ return true ;
218+
219+ }
220+
201221 void HandleReply (NKqp::TEvKqp::TEvCreateSessionResponse::TPtr& ev) {
202222 if (ev->Get ()->Record .GetYdbStatus () != Ydb::StatusIds::SUCCESS) {
203223 return ReplyAndPassAway (
@@ -232,6 +252,7 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
232252 request.SetAction (NKikimrKqp::QUERY_ACTION_EXECUTE);
233253 request.SetType (NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
234254 request.SetKeepSession (false );
255+ SetTransactionMode (request);
235256 } else if (Action == " explain-query" ) {
236257 request.SetAction (NKikimrKqp::QUERY_ACTION_EXPLAIN);
237258 request.SetType (NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
@@ -243,9 +264,11 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
243264 } else if (Action == " execute-data" ) {
244265 request.SetAction (NKikimrKqp::QUERY_ACTION_EXECUTE);
245266 request.SetType (NKikimrKqp::QUERY_TYPE_SQL_DML);
246- request.mutable_txcontrol ()->mutable_begin_tx ()->mutable_serializable_read_write ();
247- request.mutable_txcontrol ()->set_commit_tx (true );
248267 request.SetKeepSession (false );
268+ if (!SetTransactionMode (request)) {
269+ request.mutable_txcontrol ()->mutable_begin_tx ()->mutable_serializable_read_write ();
270+ request.mutable_txcontrol ()->set_commit_tx (true );
271+ }
249272 } else if (Action == " explain" || Action == " explain-ast" || Action == " explain-data" ) {
250273 request.SetAction (NKikimrKqp::QUERY_ACTION_EXPLAIN);
251274 request.SetType (NKikimrKqp::QUERY_TYPE_SQL_DML);
@@ -662,6 +685,17 @@ YAML::Node TJsonRequestSwagger<TJsonQuery>::GetSwagger() {
662685 type: string
663686 enum: [profile, full]
664687 required: false
688+ - name: transaction_mode
689+ in: query
690+ description: >
691+ transaction mode:
692+ * `serializable-read-write`
693+ * `online-read-only`
694+ * `stale-read-only`
695+ * `snapshot-read-only`
696+ type: string
697+ enum: [serializable-read-write, online-read-only, stale-read-only, snapshot-read-only]
698+ required: false
665699 - name: direct
666700 in: query
667701 description: force processing query on current node
0 commit comments