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

added changes for cancel query not being able to cancel, added back ticks #256

Merged
merged 7 commits into from
Feb 6, 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
2 changes: 1 addition & 1 deletion common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const TREE_ITEM_TABLE_NAME_DEFAULT_NAME = `table`;
export const TREE_ITEM_LOAD_MATERIALIZED_BADGE_NAME = `Load Materialized View`;
export const TREE_ITEM_BADGE_NAME = `badge`;
export const LOAD_OPENSEARCH_INDICES_QUERY = `SHOW tables LIKE '%';`;
export const SKIPPING_INDEX_QUERY = `CREATE SKIPPING INDEX ON datasource.database.table
export const SKIPPING_INDEX_QUERY = `CREATE SKIPPING INDEX ON \`datasource\`.\`database\`.\`table\`
(status VALUE_SET)
WITH (
auto_refresh = true,
Expand Down
17 changes: 12 additions & 5 deletions common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface RefreshIntervalType {
refreshInterval: string;
}

export interface watermarkDelayType {
export interface WatermarkDelayType {
delayWindow: number;
delayInterval: string;
}
Expand All @@ -45,7 +45,7 @@ export interface GroupByTumbleType {
tumbleInterval: string;
}

export interface materializedViewQueryType {
export interface MaterializedViewQueryType {
columnsValues: MaterializedViewColumn[];
groupByTumbleValue: GroupByTumbleType;
}
Expand Down Expand Up @@ -75,18 +75,25 @@ export interface CreateAccelerationForm {
accelerationIndexType: AccelerationIndexType;
skippingIndexQueryData: SkippingIndexRowType[];
coveringIndexQueryData: string[];
materializedViewQueryData: materializedViewQueryType;
materializedViewQueryData: MaterializedViewQueryType;
accelerationIndexName: string;
primaryShardsCount: number;
replicaShardsCount: number;
refreshType: AccelerationRefreshType;
checkpointLocation: string | undefined;
watermarkDelay: watermarkDelayType;
watermarkDelay: WatermarkDelayType;
refreshIntervalOptions: RefreshIntervalType;
formErrors: FormErrorsType;
}

export type AsyncQueryLoadingStatus = 'SUCCESS' | 'FAILED' | 'RUNNING' | 'SCHEDULED' | 'CANCELLED';
export enum AsyncQueryLoadingStatus {
Success = 'success',
Failed = 'failed',
Running = 'running',
Scheduled = 'scheduled',
Cancelled = 'cancelled',
}

export type TreeItemType =
| 'covering_index'
| 'skipping_index'
Expand Down
14 changes: 7 additions & 7 deletions public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

interface ResponseData {
ok: boolean;
resp: any;

Check warning on line 51 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
body: any;

Check warning on line 52 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface ResponseDetail<T> {
Expand All @@ -59,11 +59,11 @@
}

export interface TranslateResult {
[key: string]: any;

Check warning on line 62 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface QueryMessage {
text: any;

Check warning on line 66 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
className: string;
}

Expand All @@ -83,13 +83,13 @@
[key: string]: {
nodes: Tree;
expandedRow?: {};
selectedNodes?: { [key: string]: any };

Check warning on line 86 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
};
}

export interface DataRow {
rowId: number;
data: { [key: string]: any };

Check warning on line 92 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

interface MainProps {
Expand Down Expand Up @@ -128,7 +128,7 @@

const SUCCESS_MESSAGE = 'Success';

const errorQueryResponse = (queryResultResponseDetail: any) => {

Check warning on line 131 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const errorMessage =
queryResultResponseDetail.errorMessage +
', this query is not runnable. \n \n' +
Expand Down Expand Up @@ -156,7 +156,7 @@
const dataRows: DataRow[] = [];

const schema: object[] = _.get(responseObj, 'schema');
const datarows: any[][] = _.get(responseObj, 'datarows');

Check warning on line 159 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
let queryType = 'default';

for (const column of schema.values()) {
Expand All @@ -181,7 +181,7 @@
}

for (const [id, field] of datarows.entries()) {
const row: { [key: string]: any } = {};

Check warning on line 184 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
row.TABLE_NAME = field[index];
const dataRow: DataRow = {
rowId: id,
Expand All @@ -194,7 +194,7 @@
case 'describe':
case 'default':
for (const [id, field] of schema.entries()) {
let alias: any = null;

Check warning on line 197 in public/components/Main/main.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
try {
alias = _.get(field, 'alias');
} catch (e) {
Expand Down Expand Up @@ -259,7 +259,7 @@
isResultFullScreen: false,
selectedDatasource: [{ label: 'OpenSearch' }],
asyncLoading: false,
asyncLoadingStatus: 'SUCCESS',
asyncLoadingStatus: AsyncQueryLoadingStatus.Success,
asyncQueryError: '',
asyncJobId: '',
refreshTree: false,
Expand Down Expand Up @@ -424,7 +424,7 @@
queryResultsTEXT: [],
searchQuery: '',
asyncLoading: false,
asyncLoadingStatus: 'SUCCESS',
asyncLoadingStatus: AsyncQueryLoadingStatus.Success,
isCallOutVisible: false,
},
() => console.log('Successfully updated the states')
Expand Down Expand Up @@ -497,7 +497,7 @@
selectedTabName: MESSAGE_TAB_LABEL,
itemIdToExpandedRowMap: {},
asyncLoading: true,
asyncLoadingStatus: 'SCHEDULED',
asyncLoadingStatus: AsyncQueryLoadingStatus.Scheduled,
asyncJobId: queryId,
isCallOutVisible: false,
});
Expand Down Expand Up @@ -533,8 +533,8 @@
const result: ResponseDetail<string> = this.processQueryResponse(
response as IHttpResponse<ResponseData>
);
const status = result.data.status;
if (_.isEqual(status, 'SUCCESS')) {
const status = result.data.status.toLowerCase();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason for converting to lower case? Can't we compare directly?

Copy link
Collaborator Author

@sumukhswamy sumukhswamy Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to keep it uniform if there are other changes, initially the status from the back end were in caps

if (_.isEqual(status, 'success')) {
const resultTable: Array<ResponseDetail<QueryResult>> = getQueryResultsForTable(
[result],
false
Expand All @@ -555,7 +555,7 @@
asyncLoadingStatus: status,
isCallOutVisible: !(result.data.schema.length > 0),
});
} else if (_.isEqual(status, 'FAILED') || _.isEqual(status, 'CANCELLED')) {
} else if (_.isEqual(status, 'failed') || _.isEqual(status, 'cancelled')) {
this.setState({
asyncLoading: false,
asyncLoadingStatus: status,
Expand Down Expand Up @@ -792,7 +792,7 @@
selectedTabName: MESSAGE_TAB_LABEL,
itemIdToExpandedRowMap: {},
asyncLoading: false,
asyncLoadingStatus: 'SUCCESS',
asyncLoadingStatus: AsyncQueryLoadingStatus.Success,
isCallOutVisible: false,
});
};
Expand Down
10 changes: 6 additions & 4 deletions public/components/QueryResults/QueryResults.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import '@testing-library/jest-dom/extend-expect';
import { configure, fireEvent, render } from '@testing-library/react';
import { AsyncQueryLoadingStatus } from "../../../common/types/index";

Check failure on line 8 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `"../../../common/types/index"` with `'../../../common/types/index'`

import 'mutationobserver-shim';
import React from 'react';
import 'regenerator-runtime';
Expand All @@ -16,8 +18,8 @@
configure({ testIdAttribute: 'data-test-subj' });

function renderSQLQueryResults(
mockQueryResults: ResponseDetail<QueryResult>[],

Check failure on line 21 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'mockQueryResults' is already declared in the upper scope

Check failure on line 21 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead
mockQueries: string[] = [],

Check failure on line 22 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'mockQueries' is already declared in the upper scope
mockSearchQuery: string = '',
onSelectedTabIdChange: (tab: Tab) => void,
onQueryChange: () => {},
Expand Down Expand Up @@ -53,7 +55,7 @@
getText={getText}
isResultFullScreen={false}
setIsResultFullScreen={setIsResultFullScreen}
asyncLoadingStatus="SUCCESS"
asyncLoadingStatus={AsyncQueryLoadingStatus.Success}
asyncQueryError=""
selectedDatasource={[{ label: 'OpenSearch' }]}
cancelAsyncQuery={() => {}}
Expand Down Expand Up @@ -86,7 +88,7 @@
getAllByRole,
getByText,
getAllByText,
getAllByTestId,

Check failure on line 91 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'getAllByTestId' is assigned a value but never used. Allowed unused vars must match /^_/u
getAllByLabelText,
} = renderSQLQueryResults(
mockQueryResults,
Expand All @@ -108,7 +110,7 @@
expect(getAllByRole('tab')[0].getAttribute('aria-selected')).toEqual('false');
expect(getAllByRole('tab')[1].getAttribute('aria-selected')).toEqual('true');

//It tests that there is one tab for each QueryResult

Check failure on line 113 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
expect(getAllByRole('tab')).toHaveLength(11);

// It tests Tab button
Expand All @@ -121,10 +123,10 @@
// It tests pagination
await fireEvent.click(getAllByLabelText('Page 2 of 2')[0]);
await fireEvent.click(getAllByText('Rows per page', { exact: false })[0]);
expect(getByText('10 rows'));

Check failure on line 126 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expect must have a corresponding matcher call
expect(getByText('20 rows'));

Check failure on line 127 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expect must have a corresponding matcher call
expect(getByText('50 rows'));

Check failure on line 128 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expect must have a corresponding matcher call
expect(getByText('100 rows'));

Check failure on line 129 in public/components/QueryResults/QueryResults.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expect must have a corresponding matcher call
await fireEvent.click(getByText('20 rows'));
});

Expand Down Expand Up @@ -215,7 +217,7 @@
getText={getText}
isResultFullScreen={false}
setIsResultFullScreen={setIsResultFullScreen}
asyncLoadingStatus="SUCCESS"
asyncLoadingStatus={AsyncQueryLoadingStatus.Success}
asyncQueryError=""
selectedDatasource={[{ label: 'OpenSearch' }]}
cancelAsyncQuery={() => {}}
Expand Down Expand Up @@ -341,7 +343,7 @@
getText={() => {}}
isResultFullScreen={false}
setIsResultFullScreen={() => {}}
asyncLoadingStatus="RUNNING"
asyncLoadingStatus={AsyncQueryLoadingStatus.Running}
asyncQueryError=""
selectedDatasource={[{ label: 'mys3' }]}
cancelAsyncQuery={() => {}}
Expand Down Expand Up @@ -378,7 +380,7 @@
getText={() => {}}
isResultFullScreen={false}
setIsResultFullScreen={() => {}}
asyncLoadingStatus="FAILED"
asyncLoadingStatus={AsyncQueryLoadingStatus.Failed}
asyncQueryError="custom error"
selectedDatasource={[{ label: 'mys3' }]}
cancelAsyncQuery={() => {}}
Expand Down
4 changes: 2 additions & 2 deletions public/components/QueryResults/QueryResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ class QueryResults extends React.Component<QueryResultsProps, QueryResultsState>
</EuiFlexItem>
</EuiFlexGroup>
</div>
{this.props.asyncLoadingStatus === 'SUCCESS' ||
this.props.asyncLoadingStatus === 'CANCELLED' ? (
{this.props.asyncLoadingStatus === 'success' ||
this.props.asyncLoadingStatus === 'cancelled' ? (
<>
{this.props.queryResults.length === 0 ? (
// show no results message instead of the results table when there are no results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ exports[`<AsyncQueryResults /> spec renders async query loading component 1`] =
class="euiText euiText--medium"
>
Status:
RUNNING
running
</div>
<button
class="euiButton euiButton--primary"
Expand Down
10 changes: 5 additions & 5 deletions public/components/QueryResults/async_query_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
*/

import {
EuiFlexGroup,
EuiText,
EuiLoadingSpinner,
EuiButton,
EuiFlexGroup,
EuiIcon,
EuiLoadingSpinner,
EuiModal,
EuiModalBody,
EuiModalFooter,
EuiModalHeader,
EuiModalHeaderTitle,
EuiText,
} from '@elastic/eui';
import { AsyncQueryLoadingStatus } from '../../../common/types';
import React, { useState } from 'react';
import { AsyncQueryLoadingStatus } from '../../../common/types';

interface AsyncQueryBodyProps {
asyncLoadingStatus: AsyncQueryLoadingStatus;
Expand Down Expand Up @@ -51,7 +51,7 @@ export function AsyncQueryBody(props: AsyncQueryBodyProps) {

return (
<EuiFlexGroup direction="column" alignItems="center">
{asyncLoadingStatus == 'FAILED' ? (
{asyncLoadingStatus == AsyncQueryLoadingStatus.Failed ? (
<>
<EuiIcon size="l" type="alert" color="danger" />
<EuiText>
Expand Down
12 changes: 6 additions & 6 deletions public/components/SQLPage/table_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const TableView = ({ http, selectedItems, updateSQLQueries, refreshTree }
setTableNames([]);
const query = {
lang: 'sql',
query: `SHOW SCHEMAS IN ${selectedItems[0].label}`,
query: `SHOW SCHEMAS IN \`${selectedItems[0]['label']}\``,
datasource: selectedItems[0].label,
};
getJobId(selectedItems[0].label, query, http, (id) => {
Expand Down Expand Up @@ -202,7 +202,7 @@ export const TableView = ({ http, selectedItems, updateSQLQueries, refreshTree }
setSelectedDatabase(databaseName);
const query = {
lang: 'sql',
query: `SHOW TABLES IN ${selectedItems[0].label}.${databaseName}`,
query: `SHOW TABLES IN \`${selectedItems[0]['label']}\`.\`${databaseName}\``,
datasource: selectedItems[0].label,
};
getJobId(selectedItems[0].label, query, http, (id) => {
Expand Down Expand Up @@ -270,7 +270,7 @@ export const TableView = ({ http, selectedItems, updateSQLQueries, refreshTree }
const loadCoveringIndex = (tableName: string, databaseName: string) => {
const coverQuery = {
lang: 'sql',
query: `SHOW INDEX ON ${selectedItems[0].label}.${databaseName}.${tableName}`,
query: `SHOW INDEX ON \`${selectedItems[0]['label']}\`.\`${databaseName}\`.\`${tableName}\``,
datasource: selectedItems[0].label,
};
getJobId(selectedItems[0].label, coverQuery, http, (id) => {
Expand Down Expand Up @@ -354,7 +354,7 @@ export const TableView = ({ http, selectedItems, updateSQLQueries, refreshTree }
setLoadingForTableElements(databaseName, tableName);
const materializedViewQuery = {
lang: 'sql',
query: `SHOW MATERIALIZED VIEW IN ${selectedItems[0].label}.${databaseName}`,
query: `SHOW MATERIALIZED VIEW IN \`${selectedItems[0]['label']}\`.\`${databaseName}\``,
datasource: selectedItems[0].label,
};
getJobId(selectedItems[0].label, materializedViewQuery, http, (id) => {
Expand Down Expand Up @@ -418,7 +418,7 @@ export const TableView = ({ http, selectedItems, updateSQLQueries, refreshTree }
setLoadingForTableElements(databaseName, tableName);
const skipQuery = {
lang: 'sql',
query: `DESC SKIPPING INDEX ON ${selectedItems[0].label}.${databaseName}.${tableName}`,
query: `DESC SKIPPING INDEX ON \`${selectedItems[0]['label']}\`.\`${databaseName}\`.\`${tableName}\``,
datasource: selectedItems[0].label,
};
getJobId(selectedItems[0].label, skipQuery, http, (id) => {
Expand Down Expand Up @@ -472,7 +472,7 @@ export const TableView = ({ http, selectedItems, updateSQLQueries, refreshTree }
};
const handleQuery = (e: MouseEvent, parentName: string, tableName: string) => {
e.stopPropagation();
updateSQLQueries(`select * from ${selectedItems[0].label}.${parentName}.${tableName} limit 10`);
updateSQLQueries(`select * from \`${selectedItems[0].label}\`.\`${parentName}\`.\`${tableName}\` limit 10`);
};

const iconCreation = (node: TreeItem) => {
Expand Down
4 changes: 2 additions & 2 deletions public/components/acceleration/create/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
AccelerationRefreshType,
CreateAccelerationForm,
FormErrorsType,
MaterializedViewQueryType,
SkippingIndexRowType,
materializedViewQueryType,
} from '../../../../common/types';

export const pluralizeTime = (timeWindow: number) => {
Expand Down Expand Up @@ -103,7 +103,7 @@ export const validateCoveringIndexData = (

export const validateMaterializedViewData = (
accelerationIndexType: AccelerationIndexType,
materializedViewQueryData: materializedViewQueryType
materializedViewQueryData: MaterializedViewQueryType
) => {
if (accelerationIndexType !== 'materialized') return [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const IndexTypeSelector = ({
const idPrefix = htmlIdGenerator()();
const query = {
lang: 'sql',
query: `DESC ${accelerationFormData.dataSource}.${accelerationFormData.database}.${accelerationFormData.dataTable}`,
query: `DESC \`${accelerationFormData.dataSource}\`.\`${accelerationFormData.database}\`.\`${accelerationFormData.dataTable}\``,
datasource: accelerationFormData.dataSource,
};
const errorMessage = 'ERROR: failed to load table columns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const AccelerationDataSourceSelector = ({
setLoadingComboBoxes({ ...loadingComboBoxes, database: true });
const query = {
lang: 'sql',
query: `SHOW SCHEMAS IN ${accelerationFormData.dataSource}`,
query: `SHOW SCHEMAS IN \`${accelerationFormData.dataSource}\``,
datasource: accelerationFormData.dataSource,
};
const errorMessage = `ERROR: failed to load databases`;
Expand Down Expand Up @@ -96,7 +96,7 @@ export const AccelerationDataSourceSelector = ({
setLoadingComboBoxes({ ...loadingComboBoxes, dataTable: true });
const query = {
lang: 'sql',
query: `SHOW TABLES IN ${accelerationFormData.dataSource}.${accelerationFormData.database}`,
query: `SHOW TABLES IN \`${accelerationFormData.dataSource}.\`${accelerationFormData.database}\``,
datasource: accelerationFormData.dataSource,
};
const errorMessage = `ERROR: failed to load tables`;
Expand Down
16 changes: 8 additions & 8 deletions test/mocks/accelerationMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

import {
ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME,
ACCELERATION_TIME_INTERVAL,
ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME,
ACCELERATION_TIME_INTERVAL,
} from '../../common/constants';
import {
CreateAccelerationForm,
SkippingIndexRowType,
materializedViewQueryType,
CreateAccelerationForm,
MaterializedViewQueryType,
SkippingIndexRowType,
} from '../../common/types';

export const skippingIndexDataMock: SkippingIndexRowType[] = [
Expand Down Expand Up @@ -39,7 +39,7 @@ export const materializedViewEmptyDataMock = {
},
};

export const materializedViewEmptyTumbleDataMock: materializedViewQueryType = {
export const materializedViewEmptyTumbleDataMock: MaterializedViewQueryType = {
columnsValues: [
{
id: '1',
Expand All @@ -54,7 +54,7 @@ export const materializedViewEmptyTumbleDataMock: materializedViewQueryType = {
},
};

export const materializedViewStaleDataMock: materializedViewQueryType = {
export const materializedViewStaleDataMock: MaterializedViewQueryType = {
columnsValues: [],
groupByTumbleValue: {
timeField: 'timestamp',
Expand All @@ -63,7 +63,7 @@ export const materializedViewStaleDataMock: materializedViewQueryType = {
},
};

export const materializedViewValidDataMock: materializedViewQueryType = {
export const materializedViewValidDataMock: MaterializedViewQueryType = {
columnsValues: [
{
id: '1',
Expand Down
Loading