Skip to content

Commit

Permalink
Acceleration related changes and minor fixes (#135)
Browse files Browse the repository at this point in the history
* add acc index flyout

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* remove [if not exists] from acc creation

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* merge tableview from main

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* adding acc index flyout

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* add hash router

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* hide materialized view index type

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* update snapshots

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* loading combo boxes for acc flyout

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* adding acceleration backend integ

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* update jest tests for acc flyout

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* add redirection support for home page

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* fix primary shards count and replica validation

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* remove the caution callout for acc flyout

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

* support acc flyout redirection from data sources

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>

---------

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 authored Oct 4, 2023
1 parent e1c28e9 commit 621b82e
Show file tree
Hide file tree
Showing 30 changed files with 470 additions and 400 deletions.
2 changes: 1 addition & 1 deletion common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ON_LOAD_QUERY = `SHOW tables LIKE '%';`;
export const ACCELERATION_INDEX_TYPES = [
{ label: 'Skipping Index', value: 'skipping' },
{ label: 'Covering Index', value: 'covering' },
{ label: 'Materialized View', value: 'materialized' },
// { label: 'Materialized View', value: 'materialized' }, Hidden Option -> Until opensearch-spark feature is ready
];

export const ACCELERATION_AGGREGRATION_FUNCTIONS = [
Expand Down
26 changes: 21 additions & 5 deletions public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiPageSideBar,
EuiPanel,
EuiSpacer,
EuiText
EuiText,
} from '@elastic/eui';
import { IHttpResponse } from 'angular';
import _ from 'lodash';
Expand Down Expand Up @@ -83,6 +83,8 @@ export type DataRow = {
interface MainProps {
httpClient: CoreStart['http'];
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
isAccelerationFlyoutOpen: boolean;
urlDataSource: string;
}

interface MainState {
Expand Down Expand Up @@ -417,7 +419,11 @@ export class Main extends React.Component<MainProps, MainState> {
queries.map((query: string) =>
this.httpClient
.post(endpoint, {
body: JSON.stringify({ lang: language, query: query, datasource: this.state.selectedDatasource[0].label}), // TODO: dynamically datasource when accurate
body: JSON.stringify({
lang: language,
query: query,
datasource: this.state.selectedDatasource[0].label,
}), // TODO: dynamically datasource when accurate
})
.catch((error: any) => {
this.setState({
Expand Down Expand Up @@ -796,8 +802,11 @@ export class Main extends React.Component<MainProps, MainState> {
if (this.state.language == 'SQL') {
page = (
<SQLPage
http={this.httpClient}
onRun={
_.isEqual(this.state.selectedDatasource[0].label, 'OpenSearch') ? this.onRun : this.onRunAsync
_.isEqual(this.state.selectedDatasource[0].label, 'OpenSearch')
? this.onRun
: this.onRunAsync
}
onTranslate={this.onTranslate}
onClear={this.onClear}
Expand All @@ -814,7 +823,9 @@ export class Main extends React.Component<MainProps, MainState> {
page = (
<PPLPage
onRun={
_.isEqual(this.state.selectedDatasource[0].label, 'OpenSearch') ? this.onRun : this.onRunAsync
_.isEqual(this.state.selectedDatasource[0].label, 'OpenSearch')
? this.onRun
: this.onRunAsync
}
onTranslate={this.onTranslate}
onClear={this.onClear}
Expand Down Expand Up @@ -876,7 +887,11 @@ export class Main extends React.Component<MainProps, MainState> {
<EuiFlexGroup direction="row" alignItems="center">
<EuiFlexItem>
<EuiText>Data Sources</EuiText>
<DataSelect http={this.httpClient} onSelect={this.handleDataSelect} />
<DataSelect
http={this.httpClient}
onSelect={this.handleDataSelect}
urlDataSource={this.props.urlDataSource}
/>
<EuiSpacer />
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand All @@ -903,6 +918,7 @@ export class Main extends React.Component<MainProps, MainState> {
<TableView
http={this.httpClient}
selectedItems={this.state.selectedDatasource}
updateSQLQueries={this.updateSQLQueries}
/>
<EuiSpacer />
</EuiFlexItem>
Expand Down
23 changes: 18 additions & 5 deletions public/components/SQLPage/DataSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import { CoreStart } from '../../../../../src/core/public';
interface CustomView {
http: CoreStart['http'];
onSelect: (selectedItems: []) => void;
urlDataSource: string;
}

export const DataSelect = ({ http, onSelect }: CustomView) => {
const [selectedOptions, setSelectedOptions] = useState<EuiComboBoxOptionOption[]>([{ label: 'OpenSearch' }]);
export const DataSelect = ({ http, onSelect, urlDataSource }: CustomView) => {
const [selectedOptions, setSelectedOptions] = useState<EuiComboBoxOptionOption[]>([
{ label: 'OpenSearch' },
]);
const [options, setOptions] = useState<any[]>([]);

const datasources = () => {
let dataOptions: EuiComboBoxOptionOption[] = [];
let urlSourceFound = false;
http
.get(`/api/get_datasources`)
.then((res) => {
Expand All @@ -34,21 +39,29 @@ export const DataSelect = ({ http, onSelect }: CustomView) => {
}

connectorGroups[connector].push(name);
if (name === urlDataSource) {
urlSourceFound = true;
}
}
});
options.push({ label: 'OpenSearch' });
dataOptions.push({ label: 'OpenSearch' });

for (const connector in connectorGroups) {
if (connectorGroups.hasOwnProperty(connector)) {
const connectorNames = connectorGroups[connector];

options.push({
dataOptions.push({
label: connector,
options: connectorNames.map((name) => ({ label: name })),
});
}
}

setOptions(options);
setOptions(dataOptions);
if (urlSourceFound) {
setSelectedOptions([{ label: urlDataSource }]);
onSelect([{ label: urlDataSource }]);
}
})
.catch((err) => {
console.error(err);
Expand Down
31 changes: 18 additions & 13 deletions public/components/SQLPage/SQLPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EuiButton,
EuiCodeBlock,
EuiCodeEditor,
EuiComboBoxOptionOption,
EuiFlexGroup,
EuiFlexItem,
EuiModal,
Expand All @@ -21,18 +22,20 @@ import {
import 'brace/ext/language_tools';
import 'brace/mode/sql';
import React from 'react';
import { CoreStart } from '../../../../../src/core/public';
import '../../ace-themes/sql_console';
import { ResponseDetail, TranslateResult } from '../Main/main';
import { CreateAcceleration } from '../acceleration/create/create_acceleration';

interface SQLPageProps {
http: CoreStart['http'];
onRun: (query: string) => void;
onTranslate: (query: string) => void;
onClear: () => void;
updateSQLQueries: (query: string) => void;
sqlQuery: string;
sqlTranslations: ResponseDetail<TranslateResult>[];
selectedDatasource: string;
selectedDatasource: EuiComboBoxOptionOption[];
asyncLoading: boolean;
}

Expand Down Expand Up @@ -68,7 +71,8 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
this.setState({
flyoutComponent: (
<CreateAcceleration
dataSource="ds"
http={this.props.http}
selectedDatasource={this.props.selectedDatasource}
resetFlyout={this.resetFlyout}
updateQueries={this.props.updateSQLQueries}
/>
Expand Down Expand Up @@ -170,17 +174,18 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
{this.props.selectedDatasource === 'S3' && (
<EuiFlexItem grow={false}>
<EuiButton
fill={true}
className="sql-accelerate-button"
onClick={this.setAccelerationFlyout}
>
Accelerate Table
</EuiButton>
</EuiFlexItem>
)}
{this.props.selectedDatasource &&
this.props.selectedDatasource[0].label !== 'OpenSearch' && (
<EuiFlexItem grow={false}>
<EuiButton
fill={true}
className="sql-accelerate-button"
onClick={this.setAccelerationFlyout}
>
Accelerate Table
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiPanel>
{modal}
Expand Down
49 changes: 41 additions & 8 deletions public/components/SQLPage/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,51 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiEmptyPrompt, EuiIcon, EuiTreeView } from '@elastic/eui';
import { EuiComboBoxOptionOption, EuiEmptyPrompt, EuiIcon, EuiTreeView } from '@elastic/eui';
import _ from 'lodash';
import React, { useEffect, useState } from 'react';
import { CoreStart } from '../../../../../src/core/public';
import { ON_LOAD_QUERY } from '../../../common/constants';
import { AccelerationIndexFlyout } from './acceleration_index_flyout';
import { getJobId, pollQueryStatus } from './utils';

interface CustomView {
http: CoreStart['http'];
selectedItems: any[];
selectedItems: EuiComboBoxOptionOption[];
updateSQLQueries: (query: string) => void;
}

export const TableView = ({ http, selectedItems }: CustomView) => {
export const TableView = ({ http, selectedItems, updateSQLQueries }: CustomView) => {
const [tablenames, setTablenames] = useState<string[]>([]);
const [selectedNode, setSelectedNode] = useState<string | null>(null);
const [childData, setChildData] = useState<string[]>([]);
const [selectedChildNode, setSelectedChildNode] = useState<string | null>(null);
const [indexData, setIndexedData] = useState<string[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [indiciesData, setIndiciesData] = useState<string []>([]);
const [indiciesData, setIndiciesData] = useState<string[]>([]);
const [indexFlyout, setIndexFlyout] = useState(<></>);

const resetFlyout = () => {
setIndexFlyout(<></>);
};

const handleAccelerationIndexClick = (
dataSource: string,
database: string,
dataTable: string,
indexName: string
) => {
setIndexFlyout(
<AccelerationIndexFlyout
dataSource={dataSource}
database={database}
dataTable={dataTable}
indexName={indexName}
resetFlyout={resetFlyout}
updateSQLQueries={updateSQLQueries}
/>
);
};

const get_async_query_results = (id, http, callback) => {
pollQueryStatus(id, http, callback);
Expand Down Expand Up @@ -64,7 +89,7 @@ export const TableView = ({ http, selectedItems }: CustomView) => {

useEffect(() => {
getSidebarContent();
}, [selectedItems[0]['label']]);
}, [selectedItems]);

const handleNodeClick = (nodeLabel: string) => {
setSelectedNode(nodeLabel);
Expand All @@ -89,8 +114,8 @@ export const TableView = ({ http, selectedItems }: CustomView) => {
};
getJobId(coverQuery, http, (id) => {
get_async_query_results(id, http, (data) => {
data = [].concat(...data)
indiciesData.push(data)
data = [].concat(...data);
indiciesData.push(data);
setIndexedData(indiciesData);
});
});
Expand All @@ -105,7 +130,7 @@ export const TableView = ({ http, selectedItems }: CustomView) => {
getJobId(skipQuery, http, (id) => {
get_async_query_results(id, http, (data) => {
if (data.length > 0) {
indiciesData.push('skip_index');
indiciesData.push('skip_index');
callCoverQuery(nodeLabel1);
}
});
Expand Down Expand Up @@ -141,6 +166,13 @@ export const TableView = ({ http, selectedItems }: CustomView) => {
label: indexChild,
id: `${table}_${indexChild}`,
icon: <EuiIcon type="bolt" size="s" />,
callback: () =>
handleAccelerationIndexClick(
selectedItems[0].label,
database,
table,
indexChild
),
}))
: undefined,
}))
Expand All @@ -158,6 +190,7 @@ export const TableView = ({ http, selectedItems }: CustomView) => {
title={<h2>Error loading Datasources</h2>}
/>
)}
{indexFlyout}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ exports[`<SQLPage /> spec renders the component 1`] = `
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 621b82e

Please sign in to comment.