@@ -4,7 +4,10 @@ import {isEqual} from 'lodash';
4
4
import { v4 as uuidv4 } from 'uuid' ;
5
5
6
6
import SplitPane from '../../../../components/SplitPane' ;
7
- import { useTracingLevelOptionAvailable } from '../../../../store/reducers/capabilities/hooks' ;
7
+ import {
8
+ useStreamingAvailable ,
9
+ useTracingLevelOptionAvailable ,
10
+ } from '../../../../store/reducers/capabilities/hooks' ;
8
11
import {
9
12
queryApi ,
10
13
saveQueryToHistory ,
@@ -86,8 +89,12 @@ export default function QueryEditor(props: QueryEditorProps) {
86
89
LAST_USED_QUERY_ACTION_KEY ,
87
90
) ;
88
91
const [ lastExecutedQueryText , setLastExecutedQueryText ] = React . useState < string > ( '' ) ;
92
+ const isStreamingSupported = useStreamingAvailable ( ) ;
89
93
90
94
const [ sendQuery ] = queryApi . useUseSendQueryMutation ( ) ;
95
+ const [ streamQuery ] = queryApi . useUseStreamQueryMutation ( ) ;
96
+
97
+ const runningQueryRef = React . useRef < { abort : VoidFunction } | null > ( null ) ;
91
98
92
99
React . useEffect ( ( ) => {
93
100
if ( savedPath !== tenantName ) {
@@ -121,14 +128,25 @@ export default function QueryEditor(props: QueryEditorProps) {
121
128
}
122
129
const queryId = uuidv4 ( ) ;
123
130
124
- sendQuery ( {
125
- actionType : 'execute' ,
126
- query : text ,
127
- database : tenantName ,
128
- querySettings,
129
- enableTracingLevel,
130
- queryId,
131
- } ) ;
131
+ if ( isStreamingSupported ) {
132
+ runningQueryRef . current = streamQuery ( {
133
+ actionType : 'execute' ,
134
+ query : text ,
135
+ database : tenantName ,
136
+ querySettings,
137
+ enableTracingLevel,
138
+ queryId,
139
+ } ) ;
140
+ } else {
141
+ runningQueryRef . current = sendQuery ( {
142
+ actionType : 'execute' ,
143
+ query : text ,
144
+ database : tenantName ,
145
+ querySettings,
146
+ enableTracingLevel,
147
+ queryId,
148
+ } ) ;
149
+ }
132
150
133
151
dispatch ( setShowPreview ( false ) ) ;
134
152
@@ -155,7 +173,7 @@ export default function QueryEditor(props: QueryEditorProps) {
155
173
156
174
const queryId = uuidv4 ( ) ;
157
175
158
- sendQuery ( {
176
+ runningQueryRef . current = sendQuery ( {
159
177
actionType : 'explain' ,
160
178
query : text ,
161
179
database : tenantName ,
@@ -169,6 +187,12 @@ export default function QueryEditor(props: QueryEditorProps) {
169
187
dispatchResultVisibilityState ( PaneVisibilityActionTypes . triggerExpand ) ;
170
188
} ) ;
171
189
190
+ const handleCancelRunningQuery = React . useCallback ( ( ) => {
191
+ if ( runningQueryRef . current ) {
192
+ runningQueryRef . current . abort ( ) ;
193
+ }
194
+ } , [ ] ) ;
195
+
172
196
const onCollapseResultHandler = ( ) => {
173
197
dispatchResultVisibilityState ( PaneVisibilityActionTypes . triggerCollapse ) ;
174
198
} ;
@@ -233,6 +257,7 @@ export default function QueryEditor(props: QueryEditorProps) {
233
257
path = { path }
234
258
showPreview = { showPreview }
235
259
queryText = { lastExecutedQueryText }
260
+ onCancelRunningQuery = { handleCancelRunningQuery }
236
261
/>
237
262
</ div >
238
263
</ SplitPane >
@@ -252,6 +277,7 @@ interface ResultProps {
252
277
path : string ;
253
278
showPreview ?: boolean ;
254
279
queryText : string ;
280
+ onCancelRunningQuery : VoidFunction ;
255
281
}
256
282
function Result ( {
257
283
resultVisibilityState,
@@ -264,6 +290,7 @@ function Result({
264
290
path,
265
291
showPreview,
266
292
queryText,
293
+ onCancelRunningQuery,
267
294
} : ResultProps ) {
268
295
if ( showPreview ) {
269
296
return < Preview database = { tenantName } path = { path } type = { type } /> ;
@@ -280,6 +307,7 @@ function Result({
280
307
onExpandResults = { onExpandResultHandler }
281
308
onCollapseResults = { onCollapseResultHandler }
282
309
queryText = { queryText }
310
+ onCancelRunningQuery = { onCancelRunningQuery }
283
311
/>
284
312
) ;
285
313
}
0 commit comments