Skip to content

Commit b19a245

Browse files
committed
Merge branch 'xwei/formatted-double' of github.com:anlowee/clp into xwei/formatted-double
2 parents c56275e + 30c9b08 commit b19a245

File tree

18 files changed

+309
-84
lines changed

18 files changed

+309
-84
lines changed

components/webui/client/public/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ClpStorageEngine": "clp",
3-
"ClpQueryEngine": "native",
3+
"ClpQueryEngine": "clp",
44
"MongoDbSearchResultsMetadataCollectionName": "results-metadata",
55
"SqlDbClpArchivesTableName": "clp_archives",
66
"SqlDbClpDatasetsTableName": "clp_datasets",

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,28 @@ const submitQuery = async (
2828
return axios.post<PrestoQueryJobSchema>("/api/presto-search/query", payload);
2929
};
3030

31+
32+
/**
33+
* Sends post request to server to cancel presto query.
34+
*
35+
* @param payload
36+
* @return
37+
*/
38+
const cancelQuery = async (
39+
payload: PrestoQueryJobSchema
40+
): Promise<AxiosResponse<null>> => {
41+
console.log("Cancelling query:", JSON.stringify(payload));
42+
43+
return axios.post("/api/presto-search/cancel", payload);
44+
};
45+
46+
3147
export type {
3248
PrestoQueryJobCreationSchema,
3349
PrestoQueryJobSchema,
3450
};
3551

36-
export {submitQuery};
52+
export {
53+
cancelQuery,
54+
submitQuery,
55+
};

components/webui/client/src/config/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {CLP_QUERY_ENGINES} from "../../../common/index.js";
12
import {settings} from "../settings";
23

34

@@ -9,14 +10,6 @@ enum CLP_STORAGE_ENGINES {
910
CLP_S = "clp-s",
1011
}
1112

12-
/**
13-
* Query engine options.
14-
*/
15-
enum CLP_QUERY_ENGINES {
16-
NATIVE = "native",
17-
PRESTO = "presto",
18-
}
19-
2013
const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;
2114
const SETTINGS_QUERY_ENGINE = settings.ClpQueryEngine as CLP_QUERY_ENGINES;
2215

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.cancelButton {
2+
width: 100%;
3+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {useCallback} from "react";
2+
3+
import {CloseOutlined} from "@ant-design/icons";
4+
import {
5+
Button,
6+
Tooltip,
7+
} from "antd";
8+
9+
import useSearchStore from "../../../../SearchState/index";
10+
import {handlePrestoQueryCancel} from "../../presto-search-requests";
11+
import styles from "./index.module.css";
12+
13+
14+
/**
15+
* Renders a button to cancel the SQL query.
16+
*
17+
* @return
18+
*/
19+
const CancelButton = () => {
20+
const searchJobId = useSearchStore((state) => state.searchJobId);
21+
22+
const handleClick = useCallback(() => {
23+
if (null === searchJobId) {
24+
console.error("Cannot cancel query: searchJobId is not set.");
25+
26+
return;
27+
}
28+
handlePrestoQueryCancel({searchJobId});
29+
}, [searchJobId]);
30+
31+
return (
32+
<Tooltip title={"Cancel query"}>
33+
<Button
34+
className={styles["cancelButton"] || ""}
35+
color={"red"}
36+
icon={<CloseOutlined/>}
37+
size={"large"}
38+
variant={"solid"}
39+
onClick={handleClick}
40+
>
41+
Cancel
42+
</Button>
43+
</Tooltip>
44+
);
45+
};
46+
47+
export default CancelButton;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.runButton {
2+
width: 100%;
3+
}

components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx renamed to components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlSearchButton/RunButton/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import {
66
Tooltip,
77
} from "antd";
88

9-
import useSearchStore from "../../../SearchState/index";
10-
import {handlePrestoQuerySubmit} from "../presto-search-requests";
9+
import useSearchStore from "../../../../SearchState/index";
10+
import {SEARCH_UI_STATE} from "../../../../SearchState/typings";
11+
import {handlePrestoQuerySubmit} from "../../presto-search-requests";
12+
import styles from "./index.module.css";
1113

1214

1315
/**
@@ -16,6 +18,7 @@ import {handlePrestoQuerySubmit} from "../presto-search-requests";
1618
* @return
1719
*/
1820
const RunButton = () => {
21+
const searchUiState = useSearchStore((state) => state.searchUiState);
1922
const queryString = useSearchStore((state) => state.queryString);
2023

2124
const isQueryStringEmpty = "" === queryString;
@@ -30,11 +33,13 @@ const RunButton = () => {
3033
return (
3134
<Tooltip title={tooltipTitle}>
3235
<Button
36+
className={styles["runButton"] || ""}
3337
color={"green"}
34-
disabled={isQueryStringEmpty}
3538
icon={<CaretRightOutlined/>}
3639
size={"large"}
3740
variant={"solid"}
41+
disabled={isQueryStringEmpty ||
42+
searchUiState === SEARCH_UI_STATE.QUERY_ID_PENDING}
3843
onClick={handleClick}
3944
>
4045
Run
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.runButtonContainer {
2+
width: 130px;
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import useSearchStore from "../../../SearchState/index";
2+
import {SEARCH_UI_STATE} from "../../../SearchState/typings";
3+
import CancelButton from "./CancelButton";
4+
import styles from "./index.module.css";
5+
import RunButton from "./RunButton";
6+
7+
8+
/**
9+
* Renders a button to submit or cancel the SQL query.
10+
*
11+
* @return
12+
*/
13+
const SqlSearchButton = () => {
14+
const searchUiState = useSearchStore((state) => state.searchUiState);
15+
16+
return (
17+
<div className={styles["runButtonContainer"] || ""}>
18+
{ (searchUiState === SEARCH_UI_STATE.QUERYING) ?
19+
<CancelButton/> :
20+
<RunButton/>}
21+
</div>
22+
);
23+
};
24+
25+
export default SqlSearchButton;

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import {
2+
cancelQuery,
23
type PrestoQueryJobCreationSchema,
4+
type PrestoQueryJobSchema,
35
submitQuery,
46
} from "../../../../api/presto-search";
7+
import useSearchStore from "../../SearchState";
8+
import {SEARCH_UI_STATE} from "../../SearchState/typings";
59

610

711
/**
@@ -10,9 +14,30 @@ import {
1014
* @param payload
1115
*/
1216
const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => {
17+
const {updateSearchJobId, updateSearchUiState, searchUiState} = useSearchStore.getState();
18+
19+
// User should NOT be able to submit a new query while an existing query is in progress.
20+
if (
21+
searchUiState !== SEARCH_UI_STATE.DEFAULT &&
22+
searchUiState !== SEARCH_UI_STATE.DONE
23+
) {
24+
console.error("Cannot submit query while existing query is in progress.");
25+
26+
return;
27+
}
28+
29+
updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);
30+
1331
submitQuery(payload)
1432
.then((result) => {
1533
const {searchJobId} = result.data;
34+
35+
updateSearchJobId(searchJobId);
36+
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+
1641
console.debug(
1742
"Presto search job created - ",
1843
"Search job ID:",
@@ -24,4 +49,29 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => {
2449
});
2550
};
2651

27-
export {handlePrestoQuerySubmit};
52+
/**
53+
* Cancels an ongoing Presto search query on server.
54+
*
55+
* @param payload
56+
*/
57+
const handlePrestoQueryCancel = (payload: PrestoQueryJobSchema) => {
58+
const {searchUiState, updateSearchUiState} = useSearchStore.getState();
59+
if (searchUiState !== SEARCH_UI_STATE.QUERYING) {
60+
console.error("Cannot cancel query if there is no ongoing query.");
61+
62+
return;
63+
}
64+
65+
updateSearchUiState(SEARCH_UI_STATE.DONE);
66+
cancelQuery(payload)
67+
.then(() => {
68+
console.debug("Query cancelled successfully");
69+
})
70+
.catch((err: unknown) => {
71+
console.error("Failed to cancel query:", err);
72+
});
73+
};
74+
75+
export {
76+
handlePrestoQueryCancel, handlePrestoQuerySubmit,
77+
};

0 commit comments

Comments
 (0)