-
Notifications
You must be signed in to change notification settings - Fork 82
feat(webui): Add support for cancelling Presto SQL queries. #1175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
28dd131
feat(webui): Add support for cancelling Presto SQL queries.
hoophalab d125a51
address coderabbit comments
hoophalab 3d2f89e
address coderabbit comments
hoophalab 5cbdce7
address comments
hoophalab aa419fa
Merge branch 'main' into cancel
hoophalab 3096ecf
remove redundant css
hoophalab 410bd5b
address comments
hoophalab 4171efa
no content
hoophalab acafd2e
rename
hoophalab b7a4a01
Merge branch 'main' into cancel
hoophalab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
.../src/pages/SearchPage/SearchControls/Presto/SqlSearchButton/CancelButton/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cancelButton { | ||
width: 100%; | ||
} |
47 changes: 47 additions & 0 deletions
47
.../client/src/pages/SearchPage/SearchControls/Presto/SqlSearchButton/CancelButton/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {useCallback} from "react"; | ||
|
||
import {CloseOutlined} from "@ant-design/icons"; | ||
import { | ||
Button, | ||
Tooltip, | ||
} from "antd"; | ||
|
||
import useSearchStore from "../../../../SearchState/index"; | ||
import {handlePrestoQueryCancel} from "../../presto-search-requests"; | ||
import styles from "./index.module.css"; | ||
|
||
|
||
/** | ||
* Renders a button to cancel the SQL query. | ||
* | ||
* @return | ||
*/ | ||
const CancelButton = () => { | ||
const searchJobId = useSearchStore((state) => state.searchJobId); | ||
|
||
const handleClick = useCallback(() => { | ||
if (null === searchJobId) { | ||
console.error("Cannot cancel query: searchJobId is not set."); | ||
|
||
return; | ||
} | ||
handlePrestoQueryCancel({searchJobId}); | ||
}, [searchJobId]); | ||
|
||
return ( | ||
<Tooltip title={"Cancel query"}> | ||
<Button | ||
className={styles["cancelButton"] || ""} | ||
color={"red"} | ||
icon={<CloseOutlined/>} | ||
size={"large"} | ||
variant={"solid"} | ||
onClick={handleClick} | ||
> | ||
Cancel | ||
</Button> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default CancelButton; |
3 changes: 3 additions & 0 deletions
3
...ent/src/pages/SearchPage/SearchControls/Presto/SqlSearchButton/RunButton/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.runButton { | ||
width: 100%; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
.../webui/client/src/pages/SearchPage/SearchControls/Presto/SqlSearchButton/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.runButtonContainer { | ||
width: 130px; | ||
} |
25 changes: 25 additions & 0 deletions
25
components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlSearchButton/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import useSearchStore from "../../../SearchState/index"; | ||
import {SEARCH_UI_STATE} from "../../../SearchState/typings"; | ||
import CancelButton from "./CancelButton"; | ||
import styles from "./index.module.css"; | ||
import RunButton from "./RunButton"; | ||
|
||
|
||
/** | ||
* Renders a button to submit or cancel the SQL query. | ||
* | ||
* @return | ||
*/ | ||
const SqlSearchButton = () => { | ||
const searchUiState = useSearchStore((state) => state.searchUiState); | ||
|
||
return ( | ||
<div className={styles["runButtonContainer"] || ""}> | ||
{ (searchUiState === SEARCH_UI_STATE.QUERYING) ? | ||
<CancelButton/> : | ||
<RunButton/>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SqlSearchButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { | ||
cancelQuery, | ||
type PrestoQueryJobCreationSchema, | ||
type PrestoQueryJobSchema, | ||
submitQuery, | ||
} from "../../../../api/presto-search"; | ||
import useSearchStore from "../../SearchState"; | ||
import {SEARCH_UI_STATE} from "../../SearchState/typings"; | ||
|
||
|
||
/** | ||
|
@@ -10,9 +14,30 @@ import { | |
* @param payload | ||
*/ | ||
const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => { | ||
const {updateSearchJobId, updateSearchUiState, searchUiState} = useSearchStore.getState(); | ||
|
||
// User should NOT be able to submit a new query while an existing query is in progress. | ||
if ( | ||
searchUiState !== SEARCH_UI_STATE.DEFAULT && | ||
searchUiState !== SEARCH_UI_STATE.DONE | ||
) { | ||
console.error("Cannot submit query while existing query is in progress."); | ||
|
||
return; | ||
} | ||
|
||
updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING); | ||
|
||
submitQuery(payload) | ||
.then((result) => { | ||
const {searchJobId} = result.data; | ||
|
||
updateSearchJobId(searchJobId); | ||
updateSearchUiState(SEARCH_UI_STATE.QUERYING); | ||
|
||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO: Delete previous query results when the backend is ready | ||
|
||
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Keep the TODO; consider clearing stale results on cancel success too. When the backend supports it, clear prior results on both new submissions and successful cancellations to avoid showing outdated data. 🤖 Prompt for AI Agents
|
||
console.debug( | ||
"Presto search job created - ", | ||
"Search job ID:", | ||
|
@@ -24,4 +49,29 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => { | |
}); | ||
}; | ||
|
||
export {handlePrestoQuerySubmit}; | ||
/** | ||
* Cancels an ongoing Presto search query on server. | ||
* | ||
* @param payload | ||
*/ | ||
const handlePrestoQueryCancel = (payload: PrestoQueryJobSchema) => { | ||
const {searchUiState, updateSearchUiState} = useSearchStore.getState(); | ||
if (searchUiState !== SEARCH_UI_STATE.QUERYING) { | ||
console.error("Cannot cancel query if there is no ongoing query."); | ||
|
||
return; | ||
} | ||
|
||
updateSearchUiState(SEARCH_UI_STATE.DONE); | ||
cancelQuery(payload) | ||
.then(() => { | ||
console.debug("Query cancelled successfully"); | ||
}) | ||
.catch((err: unknown) => { | ||
console.error("Failed to cancel query:", err); | ||
}); | ||
}; | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export { | ||
handlePrestoQueryCancel, handlePrestoQuerySubmit, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.