Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
clearQueryResults,
submitQuery,
} from "../../../../api/presto-search";
import useSearchStore from "../../SearchState";
import useSearchStore, {SEARCH_STATE_DEFAULT} from "../../SearchState";
import {SEARCH_UI_STATE} from "../../SearchState/typings";


Expand Down Expand Up @@ -43,7 +43,13 @@ const handlePrestoClearResults = () => {
* @param payload
*/
const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreation) => {
const {updateSearchJobId, updateSearchUiState, searchUiState} = useSearchStore.getState();
const {
updateNumSearchResultsTable,
updateNumSearchResultsMetadata,
updateSearchJobId,
updateSearchUiState,
searchUiState,
} = useSearchStore.getState();

// User should NOT be able to submit a new query while an existing query is in progress.
if (
Expand All @@ -58,6 +64,8 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreation) => {

handlePrestoClearResults();

updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);
updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);

submitQuery(payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const handleQuerySubmit = (payload: QueryJobCreation) => {

store.updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
store.updateNumSearchResultsTimeline(SEARCH_STATE_DEFAULT.numSearchResultsTimeline);
store.updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);
store.updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);

submitQuery(payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const useUpdateStateWithMetadata = () => {

switch (resultsMetadata.lastSignal) {
case SEARCH_SIGNAL.RESP_DONE:
case PRESTO_SEARCH_SIGNAL.FINISHED:
case PRESTO_SEARCH_SIGNAL.DONE:
updateSearchUiState(SEARCH_UI_STATE.DONE);
break;
case PRESTO_SEARCH_SIGNAL.FAILED:
Expand Down
12 changes: 2 additions & 10 deletions components/webui/common/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ enum SEARCH_SIGNAL {
* Presto search-related signals.
*/
enum PRESTO_SEARCH_SIGNAL {
WAITING_FOR_PREREQUISITES = "WAITING_FOR_PREREQUISITES",
QUEUED = "QUEUED",
WAITING_FOR_RESOURCES = "WAITING_FOR_RESOURCES",
DISPATCHING = "DISPATCHING",
PLANNING = "PLANNING",
STARTING = "STARTING",
RUNNING = "RUNNING",
FINISHING = "FINISHING",
FINISHED = "FINISHED",
CANCELED = "CANCELED",
QUERYING = "QUERYING",
DONE = "DONE",
FAILED = "FAILED",
}

Expand Down
26 changes: 15 additions & 11 deletions components/webui/server/src/routes/api/presto-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
},
query: queryString,
state: (_, queryId, stats) => {
// Type cast `presto-client` string literal type to our enum type.
const newState = stats.state as PRESTO_SEARCH_SIGNAL;
request.log.info({
searchJobId: queryId,
state: stats.state,
Expand All @@ -163,24 +161,30 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
_id: queryId,
errorMsg: null,
errorName: null,
lastSignal: newState,
lastSignal: PRESTO_SEARCH_SIGNAL.QUERYING,
queryEngine: CLP_QUERY_ENGINES.PRESTO,
}).catch((err: unknown) => {
request.log.error(err, "Failed to insert Presto metadata");
});
isResolved = true;
resolve(queryId);
} else {
// Update metadata on subsequent calls
searchResultsMetadataCollection.updateOne(
{_id: queryId},
{$set: {lastSignal: newState}}
).catch((err: unknown) => {
request.log.error(err, "Failed to update Presto metadata");
});
}
},
success: () => {
if (false === isResolved) {
request.log.error(
"Presto query finished before searchJobId was resolved; "
);

return;
}
searchResultsMetadataCollection.updateOne(
{_id: searchJobId},
{$set: {lastSignal: PRESTO_SEARCH_SIGNAL.DONE}}
).catch((err: unknown) => {
request.log.error(err, "Failed to update Presto metadata");
});

request.log.info("Presto search succeeded");
},
timeout: null,
Expand Down
Loading