Skip to content
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

[Bug] Fix SQL/PPL crash with incorrect query #2284

Merged
merged 2 commits into from
Dec 9, 2024
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
64 changes: 51 additions & 13 deletions .cypress/integration/notebooks_test/notebooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
PPL_QUERY_TEXT,
NOTEBOOK_TEXT,
OPENSEARCH_URL,
PPL_INCORRECT_QUERY_TEXT,
SQL_INCORRECT_QUERY_TEXT,
} from '../../utils/constants';

import { v4 as uuid4 } from 'uuid';
Expand Down Expand Up @@ -74,7 +76,9 @@
cy.get('h3[data-test-subj="notebookTableTitle"]').contains('Notebooks (0)').should('exist');
cy.get('div[data-test-subj="notebookEmptyTableText"]').contains('No notebooks');
cy.get('a[data-test-subj="notebookEmptyTableCreateBtn"]').contains('Create notebook');
cy.get('button[data-test-subj="notebookEmptyTableAddSamplesBtn"]').contains('Add sample notebooks');
cy.get('button[data-test-subj="notebookEmptyTableAddSamplesBtn"]').contains(
'Add sample notebooks'
);
});

it('Displays error toast for invalid notebook name', () => {
Expand All @@ -96,13 +100,9 @@
cy.get('input.euiFieldSearch').focus().type('this notebook should not exist');
cy.get('.euiTableCellContent__text').contains('No items found').should('exist');
cy.get('.euiFormControlLayoutClearButton').click();
cy.get('input.euiFieldSearch')
.focus()
.type(TEST_NOTEBOOK);
cy.get('input.euiFieldSearch').focus().type(TEST_NOTEBOOK);

cy.get('a.euiLink')
.contains(TEST_NOTEBOOK)
.should('exist');
cy.get('a.euiLink').contains(TEST_NOTEBOOK).should('exist');
});

it('Notebooks table columns headers and pagination', () => {
Expand Down Expand Up @@ -187,7 +187,7 @@

it('Renders input only mode', () => {
cy.get('input[data-test-subj="input_only"]').should('exist');
cy.get('input[data-test-subj="input_only"]').click({ force: true });

Check warning on line 190 in .cypress/integration/notebooks_test/notebooks.spec.js

View workflow job for this annotation

GitHub Actions / Lint

Do not use force on click and type calls

cy.get('div.markdown-body').should('not.exist');
cy.get('button[data-test-subj="viewBothLink"]').should('exist');
Expand All @@ -199,7 +199,7 @@

it('Renders output only mode', () => {
cy.get('input[data-test-subj="output_only"]').should('exist');
cy.get('input[data-test-subj="output_only"]').click({ force: true });

Check warning on line 202 in .cypress/integration/notebooks_test/notebooks.spec.js

View workflow job for this annotation

GitHub Actions / Lint

Do not use force on click and type calls
cy.get('button[aria-label="Open paragraph menu"]').should('not.exist');
cy.get('button[data-test-subj="paragraphToggleInputBtn"]').should('not.exist');
cy.get('code').contains('POST').should('exist');
Expand Down Expand Up @@ -295,6 +295,24 @@
});
});

it('Adds an incorrect SQL query paragraph', () => {
cy.get('button[data-test-subj="AddParagraphButton"]').click();
cy.get('button[data-test-subj="AddCodeBlockBtn"]').click();

cy.get('textarea[data-test-subj="editorArea-6"]').clear();
cy.get('textarea[data-test-subj="editorArea-6"]').focus();
cy.get('textarea[data-test-subj="editorArea-6"]').type(SQL_INCORRECT_QUERY_TEXT);
cy.get('button[data-test-subj="runRefreshBtn-6"]').click();

cy.get('textarea[data-test-subj="editorArea-6"]').should('exist');
cy.get('div[id$="-error-0"]')
.should('exist')
.and('have.class', 'euiFormErrorText')
.and('contain.text', 'Invalid SQL query');

cy.get('.euiDataGrid__overflow').should('exist');
});

it('Adds an observability visualization paragraph', () => {
cy.get('h3[data-test-subj="notebookTitle"]').contains(TEST_NOTEBOOK).should('exist');
cy.get('button[data-test-subj="notebook-paragraph-actions-button"]').click();
Expand All @@ -309,7 +327,9 @@
cy.get('input[data-test-subj="comboBoxSearchInput"]')
.focus()
.type('[Logs] Count total requests by t');
cy.get('.euiComboBoxOption__content').contains('[Logs] Count total requests by tags').click({ force: true });
cy.get('.euiComboBoxOption__content')

Check warning on line 330 in .cypress/integration/notebooks_test/notebooks.spec.js

View workflow job for this annotation

GitHub Actions / Lint

Do not use force on click and type calls
.contains('[Logs] Count total requests by tags')
.click({ force: true });
cy.get('button[data-test-subj="runRefreshBtn-0"]').click();
cy.get('h5').contains('[Logs] Count total requests by tags').should('exist');
});
Expand All @@ -318,19 +338,37 @@
cy.get('button[data-test-subj="AddParagraphButton"]').click();
cy.get('button[data-test-subj="AddCodeBlockBtn"]').click();

cy.get('textarea[data-test-subj="editorArea-7"]').clear();
cy.get('textarea[data-test-subj="editorArea-7"]').focus();
cy.get('textarea[data-test-subj="editorArea-7"]').type(PPL_QUERY_TEXT);
cy.get('button[data-test-subj="runRefreshBtn-7"]').click();
cy.get('textarea[data-test-subj="editorArea-8"]').clear();
cy.get('textarea[data-test-subj="editorArea-8"]').focus();
cy.get('textarea[data-test-subj="editorArea-8"]').type(PPL_QUERY_TEXT);
cy.get('button[data-test-subj="runRefreshBtn-8"]').click();

cy.get('textarea[data-test-subj="editorArea-7"]').should('not.exist');
cy.get('textarea[data-test-subj="editorArea-8"]').should('not.exist');
cy.get('div[data-test-subj="queryOutputText"]')
.contains('source=opensearch_dashboards_sample_data_flights')
.should('exist');

cy.get('.euiDataGrid__overflow').should('exist');
});

it('Adds an incorrect PPL query paragraph', () => {
cy.get('button[data-test-subj="AddParagraphButton"]').click();
cy.get('button[data-test-subj="AddCodeBlockBtn"]').click();

cy.get('textarea[data-test-subj="editorArea-9"]').clear();
cy.get('textarea[data-test-subj="editorArea-9"]').focus();
cy.get('textarea[data-test-subj="editorArea-9"]').type(PPL_INCORRECT_QUERY_TEXT);
cy.get('button[data-test-subj="runRefreshBtn-9"]').click();

cy.get('textarea[data-test-subj="editorArea-9"]').should('exist');
cy.get('div[id$="-error-0"]')
.should('exist')
.and('have.class', 'euiFormErrorText')
.and('contain.text', 'Error occurred in OpenSearch engine: no such index');

cy.get('.euiDataGrid__overflow').should('exist');
});

it('Clears outputs', () => {
cy.get('h3[data-test-subj="notebookTitle"]').contains(TEST_NOTEBOOK).should('exist');
cy.get('.euiButton__text').contains('Clear all outputs').click();
Expand Down
1 change: 0 additions & 1 deletion .cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ export const ADMIN_AUTH = {
username: 'admin',
password: 'admin',
};

11 changes: 10 additions & 1 deletion .cypress/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@
cy.get('.euiQuickSelect__applyButton').click();
cy.get('.euiSuperDatePicker__prettyFormatLink').click();
cy.get('.euiTab__content').contains('Absolute').click();
cy.get('input[data-test-subj="superDatePickerAbsoluteDateInput"]')

Check warning on line 73 in .cypress/utils/constants.js

View workflow job for this annotation

GitHub Actions / Lint

Do not use force on click and type calls
.focus()
.type('{selectall}' + startTime, { force: true });
if (setEndTime) {
cy.get('button.euiDatePopoverButton--end[data-test-subj="superDatePickerendDatePopoverButton"]').click();
cy.get(
'button.euiDatePopoverButton--end[data-test-subj="superDatePickerendDatePopoverButton"]'
).click();
cy.get('.euiTab__content').contains('Absolute').click();
cy.get('input[data-test-subj="superDatePickerAbsoluteDateInput"]')

Check warning on line 81 in .cypress/utils/constants.js

View workflow job for this annotation

GitHub Actions / Lint

Do not use force on click and type calls
.focus()
.type('{selectall}' + endTime, { force: true });
}
Expand Down Expand Up @@ -128,10 +130,17 @@
select * from opensearch_dashboards_sample_data_flights limit 20 {enter}
`;

export const SQL_INCORRECT_QUERY_TEXT = `%sql
selectaaaaa * from opensearch_dashboards_sample_data_flights limit 20 {enter}
`;

export const PPL_QUERY_TEXT = `%ppl
source=opensearch_dashboards_sample_data_flights {enter}
`;

export const PPL_INCORRECT_QUERY_TEXT = `%ppl
source=opensearch_dashboards_sample_data_flights__ {enter}
`;

export const suppressResizeObserverIssue = () => {
// exception is thrown on loading EuiDataGrid in cypress only, ignore for now
Expand Down
2 changes: 1 addition & 1 deletion server/services/queryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import { Logger } from '../../../../src/core/server';

export class QueryService {
private client: any;

Check warning on line 12 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
constructor(client: any, private readonly logger: Logger) {

Check warning on line 13 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
this.client = client;
}

describeQueryInternal = async (
request: any,

Check warning on line 18 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
format: string,
responseFormat: string,
context: any

Check warning on line 21 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
) => {
try {
const queryRequest = {
Expand Down Expand Up @@ -51,14 +51,14 @@
return {
data: {
ok: false,
resp: err.message,
resp: err.response,
body: err.body,
},
};
}
};

describeSQLQuery = async (context: any, request: any) => {

Check warning on line 61 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return this.describeQueryInternal(request, 'ppl.sqlQuery', 'json', context);
};

Expand Down
Loading