Skip to content

Commit

Permalink
Add backticks and remove ckpt for manual refresh in acceleration flyo…
Browse files Browse the repository at this point in the history
…ut (opensearch-project#183)

* add backticks to columns for acceleration flyout

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

* fix redundant checkpoint issue

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

---------

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 authored Oct 25, 2023
1 parent 16e2e1c commit ca0df0c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
indexOptionsMock3,
indexOptionsMock4,
indexOptionsMock5,
indexOptionsMock6,
indexOptionsMockResult1,
indexOptionsMockResult2,
indexOptionsMockResult3,
indexOptionsMockResult4,
indexOptionsMockResult5,
indexOptionsMockResult6,
materializedViewBuilderMock1,
materializedViewBuilderMock2,
materializedViewBuilderMockResult1,
Expand Down Expand Up @@ -60,6 +62,11 @@ describe('buildIndexOptions', () => {
expect(indexOptions).toEqual(indexOptionsMockResult5);
});

it('should build index options with manual refresh and checkpoint', () => {
const indexOptions = buildIndexOptions(indexOptionsMock6);
expect(indexOptions).toEqual(indexOptionsMockResult6);
});

describe('skippingIndexQueryBuilder', () => {
it('should build skipping index query as expected with interval refresh', () => {
const result = skippingIndexQueryBuilder(skippingIndexBuilderMock1);
Expand Down
36 changes: 20 additions & 16 deletions public/components/acceleration/visual_editors/query_builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const buildIndexOptions = (accelerationformData: CreateAccelerationForm)
);
}

if (checkpointLocation) {
if (refreshType !== 'manual' && checkpointLocation) {
// Add checkpoint location option
indexOptions.push(`checkpoint_location = '${checkpointLocation}'`);
}
Expand All @@ -58,7 +58,7 @@ export const buildIndexOptions = (accelerationformData: CreateAccelerationForm)
/* Add skipping index columns to query */
const buildSkippingIndexColumns = (skippingIndexQueryData: SkippingIndexRowType[]) => {
return skippingIndexQueryData
.map((n) => ` ${n.fieldName} ${n.accelerationMethod}`)
.map((n) => ` \`${n.fieldName}\` ${n.accelerationMethod}`)
.join(', \n');
};

Expand All @@ -68,9 +68,9 @@ const buildSkippingIndexColumns = (skippingIndexQueryData: SkippingIndexRowType[
*
* CREATE SKIPPING INDEX
* ON datasource.database.table (
* field1 VALUE_SET,
* field2 PARTITION,
* field3 MIN_MAX,
* `field1` VALUE_SET,
* `field2` PARTITION,
* `field3` MIN_MAX,
* ) WITH (
* auto_refresh = true,
* refresh_interval = '1 minute',
Expand All @@ -91,7 +91,7 @@ ${buildSkippingIndexColumns(skippingIndexQueryData)}

/* Add covering index columns to query */
const buildCoveringIndexColumns = (coveringIndexQueryData: string[]) => {
return coveringIndexQueryData.map((field) => ` ${field}`).join(', \n');
return coveringIndexQueryData.map((field) => ` \`${field}\``).join(', \n');
};

/*
Expand All @@ -100,9 +100,9 @@ const buildCoveringIndexColumns = (coveringIndexQueryData: string[]) => {
*
* CREATE INDEX index_name
* ON datasource.database.table (
* field1,
* field2,
* field3,
* `field1`,
* `field2`,
* `field3`,
* ) WITH (
* auto_refresh = true,
* refresh_interval = '1 minute',
Expand All @@ -127,12 +127,16 @@ ${buildCoveringIndexColumns(coveringIndexQueryData)}
return codeQuery;
};

const buildMaterializedViewColumnName = (columnName: string) => {
return columnName === '*' ? columnName : `\`${columnName}\``;
};

const buildMaterializedViewColumns = (columnsValues: MaterializedViewColumn[]) => {
return columnsValues
.map(
(column) =>
` ${column.functionName}(${column.functionParam})${
column.fieldAlias ? ` AS ${column.fieldAlias}` : ``
` ${column.functionName}(${buildMaterializedViewColumnName(column.functionParam)})${
column.fieldAlias ? ` AS \`${column.fieldAlias}\`` : ``
}`
)
.join(', \n');
Expand All @@ -141,7 +145,7 @@ const buildMaterializedViewColumns = (columnsValues: MaterializedViewColumn[]) =
/* Build group by tumble values */
const buildTumbleValue = (GroupByTumbleValue: GroupByTumbleType) => {
const { timeField, tumbleWindow, tumbleInterval } = GroupByTumbleValue;
return `(${timeField}, '${tumbleWindow} ${tumbleInterval}${pluralizeTime(tumbleWindow)}')`;
return `(\`${timeField}\`, '${tumbleWindow} ${tumbleInterval}${pluralizeTime(tumbleWindow)}')`;
};

/*
Expand All @@ -150,10 +154,10 @@ const buildTumbleValue = (GroupByTumbleValue: GroupByTumbleType) => {
*
* CREATE MATERIALIZED VIEW datasource.database.index_name
* AS SELECT
* count(field) as counter,
* count(*) as counter1,
* sum(field2),
* avg(field3) as average
* count(`field`) as `counter`,
* count(*) as `counter1`,
* sum(`field2`),
* avg(`field3`) as `average`
* WITH (
* auto_refresh = true,
* refresh_interval = '1 minute',
Expand Down
43 changes: 28 additions & 15 deletions test/mocks/accelerationMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,24 @@ export const skippingIndexBuilderMock1: CreateAccelerationForm = {
checkpointLocation: 's3://test/',
};

export const indexOptionsMock6: CreateAccelerationForm = {
...createAccelerationEmptyDataMock,
primaryShardsCount: 1,
replicaShardsCount: 1,
refreshType: 'manual',
checkpointLocation: 's3://dsfsad/dasda',
};

export const indexOptionsMockResult6 = `WITH (
index_settings = '{"number_of_shards":1,"number_of_replicas":1}',
auto_refresh = false
)`;

export const skippingIndexBuilderMockResult1 = `CREATE SKIPPING INDEX
ON datasource.database.table (
field1 PARTITION,
field2 VALUE_SET,
field3 MIN_MAX
\`field1\` PARTITION,
\`field2\` VALUE_SET,
\`field3\` MIN_MAX
) WITH (
index_settings = '{"number_of_shards":9,"number_of_replicas":2}',
auto_refresh = true,
Expand Down Expand Up @@ -269,7 +282,7 @@ export const skippingIndexBuilderMock2: CreateAccelerationForm = {

export const skippingIndexBuilderMockResult2 = `CREATE SKIPPING INDEX
ON datasource.database.table (
field1 PARTITION
\`field1\` PARTITION
) WITH (
index_settings = '{"number_of_shards":5,"number_of_replicas":3}',
auto_refresh = true,
Expand All @@ -295,9 +308,9 @@ export const coveringIndexBuilderMock1: CreateAccelerationForm = {

export const coveringIndexBuilderMockResult1 = `CREATE INDEX index_name
ON datasource.database.table (
field1,
field2,
field3
\`field1\`,
\`field2\`,
\`field3\`
) WITH (
index_settings = '{"number_of_shards":9,"number_of_replicas":2}',
auto_refresh = true,
Expand All @@ -320,7 +333,7 @@ export const coveringIndexBuilderMock2: CreateAccelerationForm = {

export const coveringIndexBuilderMockResult2 = `CREATE INDEX index_name
ON datasource.database.table (
field1
\`field1\`
) WITH (
index_settings = '{"number_of_shards":5,"number_of_replicas":3}',
auto_refresh = true,
Expand Down Expand Up @@ -363,12 +376,12 @@ export const materializedViewBuilderMock1: CreateAccelerationForm = {

export const materializedViewBuilderMockResult1 = `CREATE MATERIALIZED VIEW datasource.database.index_name
AS SELECT
count(field) AS counter,
count(*) AS counter1,
sum(field2),
avg(field3) AS average
count(\`field\`) AS \`counter\`,
count(*) AS \`counter1\`,
sum(\`field2\`),
avg(\`field3\`) AS \`average\`
FROM datasource.database.table
GROUP BY TUMBLE (timestamp, '1 minute')
GROUP BY TUMBLE (\`timestamp\`, '1 minute')
WITH (
index_settings = '{"number_of_shards":9,"number_of_replicas":2}',
auto_refresh = true,
Expand Down Expand Up @@ -404,9 +417,9 @@ export const materializedViewBuilderMock2: CreateAccelerationForm = {

export const materializedViewBuilderMockResult2 = `CREATE MATERIALIZED VIEW datasource.database.index_name
AS SELECT
count(field)
count(\`field\`)
FROM datasource.database.table
GROUP BY TUMBLE (timestamp, '2 hours')
GROUP BY TUMBLE (\`timestamp\`, '2 hours')
WITH (
index_settings = '{"number_of_shards":5,"number_of_replicas":3}',
auto_refresh = true,
Expand Down

0 comments on commit ca0df0c

Please sign in to comment.