Skip to content

Commit

Permalink
updating datasource in request
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Li <[email protected]>
  • Loading branch information
sejli committed Jun 7, 2024
1 parent 06a3264 commit 471a4ea
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export class SQLAsyncQlSearchInterceptor extends SearchInterceptor {
const { id, ...searchRequest } = request;
const path = trimEnd('/api/sqlasyncql/jobs');

const fetchDataFrame = (queryString: string | undefined, df = null) => {
const fetchDataFrame = (queryString: string | undefined, dataSource: string, df = null) => {
const body = stringify({
query: { qs: queryString, format: 'jdbc' },
dataSource,
df,
});
return from(
Expand All @@ -53,14 +54,15 @@ export class SQLAsyncQlSearchInterceptor extends SearchInterceptor {
};

const rawDataFrame = getRawDataFrame(searchRequest);
const dataFrame = fetchDataFrame(getRawQueryString(searchRequest), rawDataFrame);
const dataFrame = fetchDataFrame(
getRawQueryString(searchRequest),
searchRequest.params.index,
rawDataFrame
);

// subscribe to dataFrame to see if an error is returned, display a toast message if so
dataFrame.subscribe((df) => {
// TODO: MQL Async: clean later
// if (!df.body.error) {
// console.log('SEARCH INTERCEPTOR:', df);
// }
if (!df.body.error) return;
const jsError = new Error(df.body.error.response);
this.deps.toasts.addError(jsError, {
Expand Down
1 change: 1 addition & 0 deletions plugins-extra/query_enhancements/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function defineRoutes(
format: schema.string(),
}),
df: schema.any(),
dataSource: schema.string(),
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SQLAsyncFacet {
const params = {
body: {
query: request.body.query.qs,
datasource: df?.name,
datasource: request.body.dataSource,
lang: 'sql',
sessionId: df?.meta?.sessionId,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export async function getExternalSearchParamsFromRequest(
const dataFrame =
getDataFrame() ??
(dataSource?.name ? getDataFrameBySource(dataSource.name) : null) ??
(await setDataFrame(createDataFrame({ name: dataSource?.name ?? '', fields: [] })));
(await setDataFrame(createDataFrame({ name: dataSource?.name ?? indexTitle, fields: [] })));
return {
index: indexTitle,
index: dataSource ? dataSource.name : indexTitle,
body: {
...searchRequest.body,
df: dataFrame,
Expand Down

0 comments on commit 471a4ea

Please sign in to comment.