Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add Error Message for Explain and Run #872

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions workbench/public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { CoreStart } from 'kibana/public';
interface ResponseData {
ok: boolean;
resp: any;
body: any;
}

export interface ResponseDetail<T> {
Expand Down Expand Up @@ -94,6 +95,12 @@ interface MainState {

const SUCCESS_MESSAGE = 'Success';

const errorQueryResponse = (queryResultResponseDetail: any) => {
let errorMessage = queryResultResponseDetail.errorMessage + ', this query is not runnable. \n \n' +
queryResultResponseDetail.data;
return errorMessage;
}

// It gets column names and row values to display in a Table from the json API response
export function getQueryResultsForTable(
queryResults: ResponseDetail<string>[]
Expand All @@ -103,7 +110,7 @@ export function getQueryResultsForTable(
if (!queryResultResponseDetail.fulfilled) {
return {
fulfilled: queryResultResponseDetail.fulfilled,
errorMessage: queryResultResponseDetail.errorMessage,
errorMessage: errorQueryResponse(queryResultResponseDetail),
};
} else {
let databaseRecords: { [key: string]: any }[] = [];
Expand Down Expand Up @@ -242,6 +249,15 @@ export class Main extends React.Component<MainProps, MainState> {
};
}

formatQueryErrorBody(data: any) {
let prettyErrorMessage = "";
prettyErrorMessage += 'reason: ' + data.errorReason + '\n';
prettyErrorMessage += 'details: ' + data.errorDetails + '\n';
prettyErrorMessage += 'type: ' + data.errorType + '\n';
prettyErrorMessage += 'status: ' + data.status;
return prettyErrorMessage;
}

processQueryResponse(response: IHttpResponse<ResponseData>): ResponseDetail<string> {
if (!response) {
return {
Expand All @@ -254,7 +270,7 @@ export class Main extends React.Component<MainProps, MainState> {
return {
fulfilled: false,
errorMessage: response.data.resp,
data: '',
data: this.formatQueryErrorBody(response.data),
};
}

Expand Down Expand Up @@ -332,7 +348,6 @@ export class Main extends React.Component<MainProps, MainState> {
this.processQueryResponse(response as IHttpResponse<ResponseData>)
);
const resultTable: ResponseDetail<QueryResult>[] = getQueryResultsForTable(results);

this.setState(
{
queries: queries,
Expand Down
19 changes: 18 additions & 1 deletion workbench/public/components/PPLPage/PPLPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ export class PPLPage extends React.Component<PPLPageProps, PPLPageState> {
const closeModal = () => this.setIsModalVisible(false);
const showModal = () => this.setIsModalVisible(true);

const pplTranslationsNotEmpty = () => {
if (this.props.pplTranslations.length > 0) {
return this.props.pplTranslations[0].fulfilled;
}
return false;
}

const showExplainErrorMessage = () => {
return this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify(
queryTranslation.errorMessage + ": This query is not explainable.", null, 2
));
}

const explainContent = pplTranslationsNotEmpty()
? this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n")
: showExplainErrorMessage();

let modal;

if (this.state.isModalVisible) {
Expand All @@ -85,7 +102,7 @@ export class PPLPage extends React.Component<PPLPageProps, PPLPageState> {
fontSize="m"
isCopyable
>
{this.props.pplTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n")}
{explainContent}
</EuiCodeBlock>
</EuiModalBody>

Expand Down
24 changes: 22 additions & 2 deletions workbench/public/components/SQLPage/SQLPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
const closeModal = () => this.setIsModalVisible(false);
const showModal = () => this.setIsModalVisible(true);

const sqlTranslationsNotEmpty = () => {
if (this.props.sqlTranslations.length > 0) {
return this.props.sqlTranslations[0].fulfilled;
}
return false;
}

const showExplainErrorMessage = () => {
return this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify(
queryTranslation.errorMessage + ": This query is not explainable.", null, 2
));
}

const explainContent = sqlTranslationsNotEmpty()
? this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n")
: showExplainErrorMessage();

let modal;

if (this.state.isModalVisible) {
Expand All @@ -88,7 +105,7 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
fontSize="m"
isCopyable
>
{this.props.sqlTranslations.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2)).join("\n")}
{explainContent}
</EuiCodeBlock>
</EuiModalBody>

Expand Down Expand Up @@ -148,7 +165,10 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
this.props.onTranslate(this.props.sqlQuery)
}
>
<EuiButton className="sql-editor-button" onClick={showModal}>
<EuiButton
className="sql-editor-button"
onClick={showModal}
>
Explain
</EuiButton>
{modal}
Expand Down
5 changes: 5 additions & 0 deletions workbench/server/services/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ export default class QueryService {
};
} catch (err) {
console.log(err);
const errorObj = JSON.parse(err.body);
return {
data: {
ok: false,
resp: err.message,
errorReason: errorObj.error.reason,
errorDetails: errorObj.error.details,
errorType: errorObj.error.type,
status: errorObj.status
},
};
}
Expand Down