Skip to content

Commit

Permalink
Revert "Add backticks and remove ckpt for manual refresh in accelerat…
Browse files Browse the repository at this point in the history
…ion flyout (opensearch-project#183) (opensearch-project#185)"

This reverts commit f96c5d9.

Signed-off-by: Eric <[email protected]>
  • Loading branch information
mengweieric committed Nov 8, 2023
1 parent 40091f0 commit 4a58411
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import {
indexOptionsMock3,
indexOptionsMock4,
indexOptionsMock5,
indexOptionsMock6,
indexOptionsMockResult1,
indexOptionsMockResult2,
indexOptionsMockResult3,
indexOptionsMockResult4,
indexOptionsMockResult5,
indexOptionsMockResult6,
materializedViewBuilderMock1,
materializedViewBuilderMock2,
materializedViewBuilderMockResult1,
Expand Down Expand Up @@ -62,11 +60,6 @@ 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: 16 additions & 20 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 (refreshType !== 'manual' && checkpointLocation) {
if (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,16 +127,12 @@ ${buildCoveringIndexColumns(coveringIndexQueryData)}
return codeQuery;
};

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

const buildMaterializedViewColumns = (columnsValues: MaterializedViewColumn[]) => {
return columnsValues
.map(
(column) =>
` ${column.functionName}(${buildMaterializedViewColumnName(column.functionParam)})${
column.fieldAlias ? ` AS \`${column.fieldAlias}\`` : ``
` ${column.functionName}(${column.functionParam})${
column.fieldAlias ? ` AS ${column.fieldAlias}` : ``
}`
)
.join(', \n');
Expand All @@ -145,7 +141,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 @@ -154,10 +150,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: 15 additions & 28 deletions test/mocks/accelerationMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,11 @@ 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 @@ -282,7 +269,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 @@ -308,9 +295,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 @@ -333,7 +320,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 @@ -376,12 +363,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 @@ -417,9 +404,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 4a58411

Please sign in to comment.