@@ -72,6 +72,10 @@ using namespace std;
72
72
73
73
extern XrdSsiProvider* XrdSsiProviderClient;
74
74
75
+ // This macro is used to convert empty strings into "0" in order to avoid
76
+ // problems with calling std::atoi() when the string is empty.
77
+ #define ZERO_IF_EMPTY_STR (x ) ((x.empty()) ? " 0" : (x))
78
+
75
79
namespace {
76
80
77
81
string const createAsyncResultTmpl (
@@ -548,7 +552,12 @@ void Czar::removeOldResultTables() {
548
552
SubmitResult Czar::getQueryInfo (QueryId queryId) const {
549
553
string const context = " Czar::" + string (__func__) + " " ;
550
554
auto sqlConn = sql::SqlConnectionFactory::make (_czarConfig->getMySqlQmetaConfig ());
551
- string sql = " SELECT status,messageTable,resultQuery FROM QInfo WHERE queryId=" + to_string (queryId);
555
+ string sql =
556
+ " SELECT "
557
+ " status,UNIX_TIMESTAMP(submitted),UNIX_TIMESTAMP(completed),chunkCount,messageTable,resultQuery "
558
+ " FROM QInfo WHERE "
559
+ " queryId=" +
560
+ to_string (queryId);
552
561
sql::SqlResults results;
553
562
sql::SqlErrorObject err;
554
563
if (!sqlConn->runQuery (sql, results, err)) {
@@ -558,9 +567,13 @@ SubmitResult Czar::getQueryInfo(QueryId queryId) const {
558
567
throw runtime_error (msg);
559
568
}
560
569
vector<string> colStatus;
570
+ vector<string> colSubmitted;
571
+ vector<string> colCompleted;
572
+ vector<string> colChunkCount;
561
573
vector<string> colMessageTable;
562
574
vector<string> colResultQuery;
563
- if (!results.extractFirst3Columns (colStatus, colMessageTable, colResultQuery, err)) {
575
+ if (!results.extractFirst6Columns (colStatus, colSubmitted, colCompleted, colChunkCount, colMessageTable,
576
+ colResultQuery, err)) {
564
577
string const msg = context + " Failed to extract info for the user query, err=" + err.printErrMsg () +
565
578
" , sql=" + sql;
566
579
throw runtime_error (msg);
@@ -606,14 +619,18 @@ SubmitResult Czar::getQueryInfo(QueryId queryId) const {
606
619
}
607
620
switch (colTotalChunks.size ()) {
608
621
case 0 :
609
- // No stats means the query is over
622
+ // No stats means the query is over. Pull the final stats from the main table.
623
+ result.totalChunks = stoi (ZERO_IF_EMPTY_STR (colChunkCount[0 ]));
624
+ result.completedChunks = result.totalChunks ;
625
+ result.queryBeginEpoch = stoi (ZERO_IF_EMPTY_STR (colSubmitted[0 ]));
626
+ result.lastUpdateEpoch = stoi (ZERO_IF_EMPTY_STR (colCompleted[0 ]));
610
627
break ;
611
628
case 1 :
612
629
// The query might be still in progress
613
- result.totalChunks = stoi (colTotalChunks[0 ]);
614
- result.completedChunks = stoi (colCompletedChunks[0 ]);
615
- result.queryBeginEpoch = stoi (colQueryBeginEpoch[0 ]);
616
- result.lastUpdateEpoch = stoi (colLastUpdateEpoch[0 ]);
630
+ result.totalChunks = stoi (ZERO_IF_EMPTY_STR ( colTotalChunks[0 ]) );
631
+ result.completedChunks = stoi (ZERO_IF_EMPTY_STR ( colCompletedChunks[0 ]) );
632
+ result.queryBeginEpoch = stoi (ZERO_IF_EMPTY_STR ( colQueryBeginEpoch[0 ]) );
633
+ result.lastUpdateEpoch = stoi (ZERO_IF_EMPTY_STR ( colLastUpdateEpoch[0 ]) );
617
634
break ;
618
635
default :
619
636
// Should never be here.
0 commit comments