Skip to content

Commit

Permalink
fixed MV load bug, added mv create button, handled error case when po…
Browse files Browse the repository at this point in the history
…st query async fails

Signed-off-by: sumukhswamy <sumukhhs@amazon.com>
  • Loading branch information
sumukhswamy committed Oct 25, 2023
1 parent 015cab8 commit 6b77e6b
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 105 deletions.
18 changes: 16 additions & 2 deletions common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const LOAD_OPENSEARCH_INDICES_QUERY = `SHOW tables LIKE '%';`;
export const SKIPPING_INDEX_QUERY = `CREATE SKIPPING INDEX ON myS3.logs_db.http_logs
(status VALUE_SET)
WITH (
auto_refresh = true
auto_refresh = true,
checkpoint_location = 's3://test/'
)`;
export const COVERING_INDEX_QUERY = `CREATE INDEX covering_idx ON myS3.logs_db.http_logs
(status)
WITH (
auto_refresh = true
auto_refresh = true,
checkpoint_location = 's3://test/'
)`;
export const CREATE_DATABASE_QUERY = `CREATE DATABASE myS3.logs_db`;
export const CREATE_TABLE_QUERY = `CREATE EXTERNAL TABLE myS3.logs_db.logs (
Expand All @@ -42,6 +44,18 @@ OPTIONS (
compression 'gzip'
);`;

export const CREATE_MATERIALIZED_VIEW = `CREATE MATERIALIZED VIEW datasource.database.index_name
AS SELECT
count(field)
FROM datasource.database.table
GROUP BY TUMBLE (timestamp, '2 hours')
WITH (
index_settings = '{"number_of_shards":5,"number_of_replicas":3}',
auto_refresh = true,
watermark_delay = '2 minutes',
checkpoint_location = 's3://test/'
)`;

export const ACCELERATION_INDEX_TYPES = [
{ label: 'Skipping Index', value: 'skipping' },
{ label: 'Covering Index', value: 'covering' },
Expand Down
3 changes: 3 additions & 0 deletions common/utils/async_query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const getJobId = (query: {}, http: CoreStart['http'], callback) => {
.then((res) => {
const id = res.data.resp.queryId;
setAsyncSessionId(_.get(res.data.resp, 'sessionId', null));
if (id === undefined) {
console.error(JSON.parse(res.data.body));
}
callback(id);
})
.catch((err) => {
Expand Down
19 changes: 18 additions & 1 deletion public/components/SQLPage/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import React, { useState } from 'react';
import {
COVERING_INDEX_QUERY,
CREATE_DATABASE_QUERY,
CREATE_MATERIALIZED_VIEW,
CREATE_TABLE_QUERY,
SKIPPING_INDEX_QUERY,
SKIPPING_INDEX_QUERY
} from '../../../common/constants';

interface CreateButtonProps {
Expand Down Expand Up @@ -57,6 +58,13 @@ export const CreateButton = ({ updateSQLQueries, selectedDatasource }: CreateBut
},
];

const materializedViewItems = [
{
name: 'Materialized View',
onClick: () => handleSubMenuClick(CREATE_MATERIALIZED_VIEW),
},
];

const button = (
<EuiButton iconType="arrowDown" iconSide="right" onClick={() => togglePopover(null)}>
Create
Expand Down Expand Up @@ -88,6 +96,10 @@ export const CreateButton = ({ updateSQLQueries, selectedDatasource }: CreateBut
name: 'Acceleration Index',
panel: 2,
},
{
name: 'Materialized View',
panel: 3,
}
],
},
{
Expand All @@ -100,6 +112,11 @@ export const CreateButton = ({ updateSQLQueries, selectedDatasource }: CreateBut
title: 'Acceleration Index Options',
items: acceleratedIndexItems,
},
{
id: 3,
title: 'Create Materialized View',
items: materializedViewItems,
},
]}
/>
</EuiPopover>
Expand Down
Loading

0 comments on commit 6b77e6b

Please sign in to comment.