Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions components/webui/client/src/api/presto-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,25 @@ const cancelQuery = async (
};


/**
* Sends delete request to server to clear presto query results.
*
* @param payload
* @return
*/
const clearQueryResults = (payload: PrestoQueryJobSchema): Promise<AxiosResponse<null>> => {
console.log("Clearing query:", JSON.stringify(payload));

return axios.delete("/api/presto-search/results", {data: payload});
};

export type {
PrestoQueryJobCreationSchema,
PrestoQueryJobSchema,
};

export {
cancelQuery,
clearQueryResults,
submitQuery,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
cancelQuery,
clearQueryResults,
type PrestoQueryJobCreationSchema,
type PrestoQueryJobSchema,
submitQuery,
Expand All @@ -8,6 +9,31 @@ import useSearchStore from "../../SearchState";
import {SEARCH_UI_STATE} from "../../SearchState/typings";


/**
* Clears current presto query results on server.
*/
const handlePrestoClearResults = () => {
const {searchUiState, searchJobId} = useSearchStore.getState();

// In the starting state, there are no results to clear.
if (searchUiState === SEARCH_UI_STATE.DEFAULT) {
return;
}

if (null === searchJobId) {
console.error("Cannot clear results: searchJobId is not set.");

return;
}

clearQueryResults(
{searchJobId}
).catch((err: unknown) => {
console.error("Failed to clear query results:", err);
});
};


/**
* Submits a new Presto query to server.
*
Expand All @@ -26,18 +52,15 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => {
return;
}

handlePrestoClearResults();

updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);

submitQuery(payload)
.then((result) => {
const {searchJobId} = result.data;

updateSearchJobId(searchJobId);
updateSearchUiState(SEARCH_UI_STATE.QUERYING);

// eslint-disable-next-line no-warning-comments
// TODO: Delete previous query results when the backend is ready

console.debug(
"Presto search job created - ",
"Search job ID:",
Expand Down Expand Up @@ -73,5 +96,6 @@ const handlePrestoQueryCancel = (payload: PrestoQueryJobSchema) => {
};

export {
handlePrestoQueryCancel, handlePrestoQuerySubmit,
handlePrestoQueryCancel,
handlePrestoQuerySubmit,
};
27 changes: 27 additions & 0 deletions components/webui/server/src/routes/api/presto-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
return null;
}
);

fastify.delete(
"/results",
{
schema: {
body: PrestoQueryJobSchema,
response: {
[StatusCodes.NO_CONTENT]: Type.Null(),
[StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema,
},
tags: ["Presto Search"],
},
},
async (request, reply) => {
const {searchJobId} = request.body;

request.log.info({
searchJobId,
}, "api/presto-search/results args");

await mongoDb.collection(searchJobId).drop();

reply.code(StatusCodes.NO_CONTENT);

return null;
}
);
};

export default plugin;