@@ -3590,6 +3590,116 @@ class ShowFullCheckpointHandler final : public HttpRequestHandler {
3590
3590
}
3591
3591
};
3592
3592
3593
+
3594
+ class ShowQueryHandler final : public HttpRequestHandler {
3595
+ public:
3596
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3597
+ auto infinity = Infinity::RemoteConnect ();
3598
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3599
+
3600
+ nlohmann::json json_response;
3601
+ nlohmann::json json_table;
3602
+ HTTPStatus http_status;
3603
+ String query_id = request->getPathVariable (" query_id" );
3604
+ QueryResult result = infinity->Query (fmt::format (" show query {}" , query_id));
3605
+
3606
+ if (result.IsOk ()) {
3607
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (0 ).get ();
3608
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3609
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3610
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3611
+ Value value = data_block->GetValue (col, 0 );
3612
+ const String &column_value = value.ToString ();
3613
+ json_table[column_name] = column_value;
3614
+ }
3615
+ json_response[" query" ] = json_table;
3616
+ json_response[" error_code" ] = 0 ;
3617
+ http_status = HTTPStatus::CODE_200;
3618
+ } else {
3619
+ json_response[" error_code" ] = result.ErrorCode ();
3620
+ json_response[" error_message" ] = result.ErrorMsg ();
3621
+ http_status = HTTPStatus::CODE_500;
3622
+ }
3623
+
3624
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3625
+ }
3626
+ };
3627
+
3628
+ class ShowTransactionsHandler final : public HttpRequestHandler {
3629
+ public:
3630
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3631
+ auto infinity = Infinity::RemoteConnect ();
3632
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3633
+
3634
+ nlohmann::json json_response;
3635
+ HTTPStatus http_status;
3636
+ QueryResult result = infinity->Query (" show transactions" );
3637
+
3638
+ if (result.IsOk ()) {
3639
+ SizeT block_rows = result.result_table_ ->DataBlockCount ();
3640
+ for (SizeT block_id = 0 ; block_id < block_rows; ++block_id) {
3641
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (block_id).get ();
3642
+ auto row_count = data_block->row_count ();
3643
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3644
+ for (int row = 0 ; row < row_count; ++row) {
3645
+ nlohmann::json json_table;
3646
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3647
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3648
+ Value value = data_block->GetValue (col, row);
3649
+ const String &column_value = value.ToString ();
3650
+ json_table[column_name] = column_value;
3651
+ }
3652
+ json_response[" transactions" ].push_back (json_table);
3653
+ }
3654
+ }
3655
+ json_response[" error_code" ] = 0 ;
3656
+ http_status = HTTPStatus::CODE_200;
3657
+ } else {
3658
+ json_response[" error_code" ] = result.ErrorCode ();
3659
+ json_response[" error_message" ] = result.ErrorMsg ();
3660
+ http_status = HTTPStatus::CODE_500;
3661
+ }
3662
+
3663
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3664
+ }
3665
+ };
3666
+
3667
+ class ShowTransactionHandler final : public HttpRequestHandler {
3668
+ public:
3669
+ SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
3670
+ auto infinity = Infinity::RemoteConnect ();
3671
+ DeferFn defer_fn ([&]() { infinity->RemoteDisconnect (); });
3672
+
3673
+ nlohmann::json json_response;
3674
+ nlohmann::json json_table;
3675
+ HTTPStatus http_status;
3676
+ String transaction_id = request->getPathVariable (" transaction_id" );
3677
+ QueryResult result = infinity->Query (fmt::format (" show transaction {}" , transaction_id));
3678
+
3679
+ if (result.IsOk ()) {
3680
+ DataBlock *data_block = result.result_table_ ->GetDataBlockById (0 ).get ();
3681
+ auto column_cnt = result.result_table_ ->ColumnCount ();
3682
+ for (SizeT col = 0 ; col < column_cnt; ++col) {
3683
+ const String &column_name = result.result_table_ ->GetColumnNameById (col);
3684
+ Value value = data_block->GetValue (col, 0 );
3685
+ const String &column_value = value.ToString ();
3686
+ json_table[column_name] = column_value;
3687
+ }
3688
+ json_response[" error_code" ] = 0 ;
3689
+ json_response[" transaction" ]= json_table;
3690
+ http_status = HTTPStatus::CODE_200;
3691
+ } else {
3692
+ json_response[" error_code" ] = result.ErrorCode ();
3693
+ json_response[" error_message" ] = result.ErrorMsg ();
3694
+ http_status = HTTPStatus::CODE_500;
3695
+ }
3696
+
3697
+ return ResponseFactory::createResponse (http_status, json_response.dump ());
3698
+ }
3699
+ };
3700
+
3701
+
3702
+
3593
3703
class AdminShowCurrentNodeHandler final : public HttpRequestHandler {
3594
3704
public:
3595
3705
SharedPtr<OutgoingResponse> handle (const SharedPtr<IncomingRequest> &request) final {
@@ -3926,6 +4036,9 @@ void HTTPServer::Start(const String &ip_address, u16 port) {
3926
4036
router->route (" GET" , " /instance/logs" , MakeShared<ShowLogsHandler>());
3927
4037
router->route (" GET" , " /instance/delta_checkpoint" , MakeShared<ShowDeltaCheckpointHandler>());
3928
4038
router->route (" GET" , " /instance/global_checkpoint" , MakeShared<ShowFullCheckpointHandler>());
4039
+ router->route (" GET" , " /instance/queries/{query_id}" , MakeShared<ShowQueryHandler>());
4040
+ router->route (" GET" , " /instance/transactions" , MakeShared<ShowTransactionsHandler>());
4041
+ router->route (" GET" , " /instance/transactions/{transaction_id}" , MakeShared<ShowTransactionHandler>());
3929
4042
3930
4043
// variable
3931
4044
router->route (" GET" , " /variables/global" , MakeShared<ShowGlobalVariablesHandler>());
0 commit comments