@@ -7,13 +7,14 @@ import { SharedGlobalConfig, Logger, ILegacyClusterClient } from 'opensearch-das
7
7
import { Observable } from 'rxjs' ;
8
8
import { ISearchStrategy , SearchUsage } from '../../../../src/plugins/data/server' ;
9
9
import {
10
+ DATA_FRAME_TYPES ,
11
+ IDataFrameError ,
10
12
IDataFrameResponse ,
11
13
IOpenSearchDashboardsSearchRequest ,
12
14
PartialDataFrame ,
13
15
createDataFrame ,
14
16
} from '../../../../src/plugins/data/common' ;
15
- import { Facet } from '../utils' ;
16
- import { JobsFacet } from '../utils' ;
17
+ import { Facet , JobsFacet } from '../utils' ;
17
18
18
19
export const sqlAsyncSearchStrategyProvider = (
19
20
config$ : Observable < SharedGlobalConfig > ,
@@ -35,15 +36,15 @@ export const sqlAsyncSearchStrategyProvider = (
35
36
datasource : df ?. meta ?. queryConfig ?. dataSource ,
36
37
lang : 'sql' ,
37
38
sessionId : df ?. meta ?. sessionId ,
38
- }
39
+ } ;
39
40
const rawResponse = await sqlAsyncFacet . describeQuery ( context , request ) ;
40
41
// handles failure
41
42
if ( ! rawResponse . success ) {
42
43
return {
43
- type : 'data_frame_polling' ,
44
+ type : DATA_FRAME_TYPES . POLLING ,
44
45
body : { error : rawResponse . data } ,
45
46
took : rawResponse . took ,
46
- } ;
47
+ } as IDataFrameError ;
47
48
}
48
49
const queryId = rawResponse . data ?. queryId ;
49
50
const sessionId = rawResponse . data ?. sessionId ;
@@ -60,13 +61,13 @@ export const sqlAsyncSearchStrategyProvider = (
60
61
} ;
61
62
dataFrame . name = request . body ?. datasource ;
62
63
return {
63
- type : 'data_frame_polling' ,
64
+ type : DATA_FRAME_TYPES . POLLING ,
64
65
body : dataFrame ,
65
66
took : rawResponse . took ,
66
67
} ;
67
68
} else {
68
69
const queryId = request . params . queryId ;
69
- request . params = { queryId }
70
+ request . params = { queryId } ;
70
71
const asyncResponse = await sqlAsyncJobsFacet . describeQuery ( request ) ;
71
72
const status = asyncResponse . data . status ;
72
73
const partial : PartialDataFrame = {
@@ -77,21 +78,21 @@ export const sqlAsyncSearchStrategyProvider = (
77
78
dataFrame . fields . forEach ( ( field , index ) => {
78
79
field . values = asyncResponse ?. data . datarows . map ( ( row : any ) => row [ index ] ) ;
79
80
} ) ;
80
-
81
+
81
82
dataFrame . size = asyncResponse ?. data ?. datarows ?. length || 0 ;
82
-
83
+
83
84
dataFrame . meta = {
84
85
status,
85
86
queryId,
86
- error : status === 'FAILED' && asyncResponse . data ?. error
87
+ error : status === 'FAILED' && asyncResponse . data ?. error ,
87
88
} ;
88
89
dataFrame . name = request . body ?. datasource ;
89
-
90
+
90
91
// TODO: MQL should this be the time for polling or the time for job creation?
91
92
if ( usage ) usage . trackSuccess ( asyncResponse . took ) ;
92
-
93
+
93
94
return {
94
- type : 'data_frame_polling' ,
95
+ type : DATA_FRAME_TYPES . POLLING ,
95
96
body : dataFrame ,
96
97
took : asyncResponse . took ,
97
98
} ;
@@ -103,4 +104,4 @@ export const sqlAsyncSearchStrategyProvider = (
103
104
}
104
105
} ,
105
106
} ;
106
- } ;
107
+ } ;
0 commit comments