@@ -3473,6 +3473,113 @@ class ShowQueriesHandler final : public HttpRequestHandler {
3473
3473
}
3474
3474
};
3475
3475
3476
+ class ShowQueryHandler final : public HttpRequestHandler {
3477
+ public:
3478
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3479
+ auto infinity = Infinity::RemoteConnect ();
3480
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3481
+
3482
+ nlohmann::json json_response;
3483
+ nlohmann::json json_table;
3484
+ HTTPStatus http_status;
3485
+ String query_id = request->getPathVariable (" query_id" );
3486
+ QueryResult result = infinity->Query (fmt::format (" show query {}" , query_id));
3487
+
3488
+ if (result.IsOk ()) {
3489
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (0 ).get ();
3490
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3491
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3492
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3493
+ Value value = data_block->GetValue (col, 0 );
3494
+ const String &column_value = value.ToString ();
3495
+ json_table[column_name] = column_value;
3496
+ }
3497
+ json_response[" query" ] = json_table;
3498
+ json_response[" error_code" ] = 0 ;
3499
+ http_status = HTTPStatus::CODE_200;
3500
+ } else {
3501
+ json_response[" error_code" ] = result.ErrorCode ();
3502
+ json_response[" error_message" ] = result.ErrorMsg ();
3503
+ http_status = HTTPStatus::CODE_500;
3504
+ }
3505
+
3506
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3507
+ }
3508
+ };
3509
+
3510
+ class ShowTransactionsHandler final : public HttpRequestHandler {
3511
+ public:
3512
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3513
+ auto infinity = Infinity::RemoteConnect ();
3514
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3515
+
3516
+ nlohmann::json json_response;
3517
+ HTTPStatus http_status;
3518
+ QueryResult result = infinity->Query (" show transactions" );
3519
+
3520
+ if (result.IsOk ()) {
3521
+ SizeT block_rows = result.result_table_ ->DataBlockCount ();
3522
+ for (SizeT block_id = 0 ; block_id < block_rows; ++block_id) {
3523
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (block_id).get ();
3524
+ auto row_count = data_block->row_count ();
3525
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3526
+ for (int row = 0 ; row < row_count; ++row) {
3527
+ nlohmann::json json_table;
3528
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3529
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3530
+ Value value = data_block->GetValue (col, row);
3531
+ const String &column_value = value.ToString ();
3532
+ json_table[column_name] = column_value;
3533
+ }
3534
+ json_response[" transactions" ].push_back (json_table);
3535
+ }
3536
+ }
3537
+ json_response[" error_code" ] = 0 ;
3538
+ http_status = HTTPStatus::CODE_200;
3539
+ } else {
3540
+ json_response[" error_code" ] = result.ErrorCode ();
3541
+ json_response[" error_message" ] = result.ErrorMsg ();
3542
+ http_status = HTTPStatus::CODE_500;
3543
+ }
3544
+
3545
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3546
+ }
3547
+ };
3548
+
3549
+ class ShowTransactionHandler final : public HttpRequestHandler {
3550
+ public:
3551
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3552
+ auto infinity = Infinity::RemoteConnect ();
3553
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3554
+
3555
+ nlohmann::json json_response;
3556
+ nlohmann::json json_table;
3557
+ HTTPStatus http_status;
3558
+ String transaction_id = request->getPathVariable (" transaction_id" );
3559
+ QueryResult result = infinity->Query (fmt::format (" show transaction {}" , transaction_id));
3560
+
3561
+ if (result.IsOk ()) {
3562
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (0 ).get ();
3563
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3564
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3565
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3566
+ Value value = data_block->GetValue (col, 0 );
3567
+ const String &column_value = value.ToString ();
3568
+ json_table[column_name] = column_value;
3569
+ }
3570
+ json_response[" error_code" ] = 0 ;
3571
+ json_response[" transaction" ]= json_table;
3572
+ http_status = HTTPStatus::CODE_200;
3573
+ } else {
3574
+ json_response[" error_code" ] = result.ErrorCode ();
3575
+ json_response[" error_message" ] = result.ErrorMsg ();
3576
+ http_status = HTTPStatus::CODE_500;
3577
+ }
3578
+
3579
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3580
+ }
3581
+ };
3582
+
3476
3583
class ShowCurrentNodeHandler final : public HttpRequestHandler {
3477
3584
public:
3478
3585
SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
@@ -3792,6 +3899,9 @@ void HTTPServer::Start(const String &ip_address, u16 port) {
3792
3899
router->route (" GET" , " /instance/profiles" , MakeShared<ShowProfilesHandler>());
3793
3900
router->route (" GET" , " /instance/memindex" , MakeShared<ShowMemIndexHandler>());
3794
3901
router->route (" GET" , " /instance/queries" , MakeShared<ShowQueriesHandler>());
3902
+ router->route (" GET" , " /instance/queries/{query_id}" , MakeShared<ShowQueryHandler>());
3903
+ router->route (" GET" , " /instance/transactions" , MakeShared<ShowTransactionsHandler>());
3904
+ router->route (" GET" , " /instance/transactions/{transaction_id}" , MakeShared<ShowTransactionHandler>());
3795
3905
3796
3906
// variable
3797
3907
router->route (" GET" , " /variables/global" , MakeShared<ShowGlobalVariablesHandler>());
0 commit comments