Skip to content

Commit ddaba31

Browse files
authored
Merge branch 'main' into datat
2 parents 9cdcebb + c778aef commit ddaba31

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

components/webui/client/src/api/presto-search/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,25 @@ const cancelQuery = async (
4444
};
4545

4646

47+
/**
48+
* Sends delete request to server to clear presto query results.
49+
*
50+
* @param payload
51+
* @return
52+
*/
53+
const clearQueryResults = (payload: PrestoQueryJobSchema): Promise<AxiosResponse<null>> => {
54+
console.log("Clearing query:", JSON.stringify(payload));
55+
56+
return axios.delete("/api/presto-search/results", {data: payload});
57+
};
58+
4759
export type {
4860
PrestoQueryJobCreationSchema,
4961
PrestoQueryJobSchema,
5062
};
5163

5264
export {
5365
cancelQuery,
66+
clearQueryResults,
5467
submitQuery,
5568
};

components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
cancelQuery,
3+
clearQueryResults,
34
type PrestoQueryJobCreationSchema,
45
type PrestoQueryJobSchema,
56
submitQuery,
@@ -8,6 +9,31 @@ import useSearchStore from "../../SearchState";
89
import {SEARCH_UI_STATE} from "../../SearchState/typings";
910

1011

12+
/**
13+
* Clears current presto query results on server.
14+
*/
15+
const handlePrestoClearResults = () => {
16+
const {searchUiState, searchJobId} = useSearchStore.getState();
17+
18+
// In the starting state, there are no results to clear.
19+
if (searchUiState === SEARCH_UI_STATE.DEFAULT) {
20+
return;
21+
}
22+
23+
if (null === searchJobId) {
24+
console.error("Cannot clear results: searchJobId is not set.");
25+
26+
return;
27+
}
28+
29+
clearQueryResults(
30+
{searchJobId}
31+
).catch((err: unknown) => {
32+
console.error("Failed to clear query results:", err);
33+
});
34+
};
35+
36+
1137
/**
1238
* Submits a new Presto query to server.
1339
*
@@ -26,18 +52,15 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => {
2652
return;
2753
}
2854

55+
handlePrestoClearResults();
56+
2957
updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);
3058

3159
submitQuery(payload)
3260
.then((result) => {
3361
const {searchJobId} = result.data;
34-
3562
updateSearchJobId(searchJobId);
3663
updateSearchUiState(SEARCH_UI_STATE.QUERYING);
37-
38-
// eslint-disable-next-line no-warning-comments
39-
// TODO: Delete previous query results when the backend is ready
40-
4164
console.debug(
4265
"Presto search job created - ",
4366
"Search job ID:",
@@ -73,5 +96,6 @@ const handlePrestoQueryCancel = (payload: PrestoQueryJobSchema) => {
7396
};
7497

7598
export {
76-
handlePrestoQueryCancel, handlePrestoQuerySubmit,
99+
handlePrestoQueryCancel,
100+
handlePrestoQuerySubmit,
77101
};

components/webui/server/src/routes/api/presto-search/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,33 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
182182
return null;
183183
}
184184
);
185+
186+
fastify.delete(
187+
"/results",
188+
{
189+
schema: {
190+
body: PrestoQueryJobSchema,
191+
response: {
192+
[StatusCodes.NO_CONTENT]: Type.Null(),
193+
[StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema,
194+
},
195+
tags: ["Presto Search"],
196+
},
197+
},
198+
async (request, reply) => {
199+
const {searchJobId} = request.body;
200+
201+
request.log.info({
202+
searchJobId,
203+
}, "api/presto-search/results args");
204+
205+
await mongoDb.collection(searchJobId).drop();
206+
207+
reply.code(StatusCodes.NO_CONTENT);
208+
209+
return null;
210+
}
211+
);
185212
};
186213

187214
export default plugin;

0 commit comments

Comments
 (0)