Skip to content

Commit

Permalink
Fix create acceleration bugs (#1599)
Browse files Browse the repository at this point in the history
* fix acceleration flyout minor bugs

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

* update snapshots

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

* update index name regex

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

---------

Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
(cherry picked from commit 76d206c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Mar 21, 2024
1 parent 1fe1926 commit 85af6c0
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 28 deletions.
4 changes: 2 additions & 2 deletions common/constants/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ACCELERATION_TIME_INTERVAL = [
];

export const ACCELERATION_ADD_FIELDS_TEXT = '(add fields here)';
export const ACCELERATION_INDEX_NAME_REGEX = /^[a-z][a-z_]*$/;
export const ACCELERATION_INDEX_NAME_REGEX = /^[a-z0-9_]+$/;
export const ACCELERATION_S3_URL_REGEX = /^(s3|s3a):\/\/[a-zA-Z0-9.\-]+/;
export const SPARK_HIVE_TABLE_REGEX = /Provider:\s*hive/;
export const TIMESTAMP_DATATYPE = 'timestamp';
Expand All @@ -60,7 +60,7 @@ export const ACCELERATION_INDEX_NAME_INFO = `All OpenSearch acceleration indices
- 'Materialized View' indices also enable users to define their index name, but they do not have a suffix.
- An example of a 'Materialized View' index name might look like: \`flint_mydatasource_mydb_mytable_myindexname\`.
##### Note:
- All user given index names must be in lowercase letters. Index name cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \, |, ?, #, >, or < are not allowed.
- All user given index names must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \, |, ?, #, >, or < are not allowed.
`;

export const SKIPPING_INDEX_ACCELERATION_METHODS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Array [
class="euiFormLabel euiFormRow__label"
for="random_html_id"
>
Index type
Acceleration type
</label>
<div
Expand Down Expand Up @@ -538,7 +538,7 @@ Array [
class="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Select the type of index you want to create. Each index type has benefits and costs.
Select the type of acceleration according to your use case.
</div>
</div>
</div>
Expand Down Expand Up @@ -1031,7 +1031,7 @@ Array [
class="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
</div>
</div>
</div>
Expand Down Expand Up @@ -1834,7 +1834,7 @@ Array [
className="euiFormLabel euiFormRow__label"
htmlFor="random_html_id"
>
Index type
Acceleration type
</label>
<div
Expand Down Expand Up @@ -1950,7 +1950,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Select the type of index you want to create. Each index type has benefits and costs.
Select the type of acceleration according to your use case.
</div>
</div>
</div>,
Expand Down Expand Up @@ -2528,7 +2528,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
</div>
</div>
</div>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('validateRefreshInterval', () => {

describe('validateIndexName', () => {
it('should return an array with an error message when the index name is invalid', () => {
expect(validateIndexName('_invalid')).toEqual(['Enter a valid index name']);
expect(validateIndexName('Iinvalid')).toEqual(['Enter a valid index name']);
expect(validateIndexName('-invalid')).toEqual(['Enter a valid index name']);
expect(validateIndexName('InVal1d')).toEqual(['Enter a valid index name']);
expect(validateIndexName('invalid_with spaces')).toEqual(['Enter a valid index name']);
Expand All @@ -147,9 +147,13 @@ describe('validateIndexName', () => {

it('should use the ACCELERATION_INDEX_NAME_REGEX pattern to validate the index name', () => {
expect(ACCELERATION_INDEX_NAME_REGEX.test('valid_name')).toBe(true);
expect(ACCELERATION_INDEX_NAME_REGEX.test('_valid_name')).toBe(true);
expect(ACCELERATION_INDEX_NAME_REGEX.test('23valid_name')).toBe(true);
expect(ACCELERATION_INDEX_NAME_REGEX.test('___1__')).toBe(true);
expect(ACCELERATION_INDEX_NAME_REGEX.test('23')).toBe(true);
expect(ACCELERATION_INDEX_NAME_REGEX.test('invalid name')).toBe(false);
expect(ACCELERATION_INDEX_NAME_REGEX.test('-invalid')).toBe(false);
expect(ACCELERATION_INDEX_NAME_REGEX.test('_invalid')).toBe(false);
expect(ACCELERATION_INDEX_NAME_REGEX.test('_invalid')).toBe(true);
expect(ACCELERATION_INDEX_NAME_REGEX.test('invalid.')).toBe(false);
expect(ACCELERATION_INDEX_NAME_REGEX.test('invalid<')).toBe(false);
expect(ACCELERATION_INDEX_NAME_REGEX.test('invalid*')).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export const CreateAcceleration = ({
<PreviewSQLDefinition
accelerationFormData={accelerationFormData}
setAccelerationFormData={setAccelerationFormData}
resetFlyout={resetFlyout}
/>
</EuiForm>
</EuiFlyoutBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const validateWatermarkDelay = (
};

export const validateIndexName = (value: string) => {
// Check if the value does not begin with underscores or hyphens and all characters are lower case
// Check if the value contains lower case letters, numbers and underscore
return !ACCELERATION_INDEX_NAME_REGEX.test(value) ? ['Enter a valid index name'] : [];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
</div>
</div>
</div>,
Expand Down Expand Up @@ -200,7 +200,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
</div>
</div>
</div>,
Expand Down Expand Up @@ -298,7 +298,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
</div>
</div>
</div>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ exports[`Advanced Index settings acceleration components renders acceleration in
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \\, |, ?, #, &gt;, or &lt; are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.
</div>
</div>
</div>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Array [
className="euiFormLabel euiFormRow__label"
htmlFor="random_html_id"
>
Index type
Acceleration type
</label>
<div
Expand Down Expand Up @@ -140,7 +140,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Select the type of index you want to create. Each index type has benefits and costs.
Select the type of acceleration according to your use case.
</div>
</div>
</div>,
Expand Down Expand Up @@ -171,7 +171,7 @@ Array [
className="euiFormLabel euiFormRow__label"
htmlFor="random_html_id"
>
Index type
Acceleration type
</label>
<div
Expand Down Expand Up @@ -287,7 +287,7 @@ Array [
className="euiFormHelpText euiFormRow__text"
id="random_html_id-help-0"
>
Select the type of index you want to create. Each index type has benefits and costs.
Select the type of acceleration according to your use case.
</div>
</div>
</div>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const DefineIndexOptions = ({
<>
<EuiFormRow
label="Index name"
helpText='Must be in lowercase letters. Cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \, |, ?, #, >, or < are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.'
helpText='Must be in lowercase letters, numbers and underscore. Spaces, commas, and characters -, :, ", *, +, /, \, |, ?, #, >, or < are not allowed. Prefix and suffix are added to the name of generated OpenSearch index.'
isInvalid={hasError(accelerationFormData.formErrors, 'indexNameError')}
error={accelerationFormData.formErrors.indexNameError}
labelAppend={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ export const IndexSettingOptions = ({
const [checkpoint, setCheckpoint] = useState('');

const onChangeRefreshType = (optionId: AccelerationRefreshType) => {
setAccelerationFormData({
...accelerationFormData,
refreshType: optionId,
});
setAccelerationFormData(
producer((accData) => {
accData.refreshType = optionId;
accData.formErrors.checkpointLocationError = [];
accData.formErrors.refreshIntervalError = [];

Check warning on line 108 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/index_setting_options.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/index_setting_options.tsx#L104-L108

Added lines #L104 - L108 were not covered by tests
})
);
setRefreshTypeSelected(optionId);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export const IndexTypeSelector = ({
</EuiText>
<EuiSpacer size="s" />
<EuiFormRow
label="Index type"
helpText="Select the type of index you want to create. Each index type has benefits and costs."
label="Acceleration type"
helpText="Select the type of acceleration according to your use case."
labelAppend={
<EuiText size="xs">
<EuiLink href={ACC_INDEX_TYPE_DOCUMENTATION_URL} target="_blank">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import { accelerationQueryBuilder } from '../visual_editors/query_builder';
interface PreviewSQLDefinitionProps {
accelerationFormData: CreateAccelerationForm;
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
resetFlyout: () => void;
}

export const PreviewSQLDefinition = ({
accelerationFormData,
setAccelerationFormData,
resetFlyout,
}: PreviewSQLDefinitionProps) => {
const { setToast } = useToast();
const [isPreviewStale, setIsPreviewStale] = useState(false);
Expand Down Expand Up @@ -96,12 +98,13 @@ export const PreviewSQLDefinition = ({
queryToRun: accelerationQueryBuilder(accelerationFormData),
},
});
resetFlyout();

Check warning on line 101 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/preview_sql_defintion.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/preview_sql_defintion.tsx#L101

Added line #L101 was not covered by tests
}
};

const queryWorkbenchButton = sqlWorkbenchPLuginExists ? (
<EuiButton iconType="popout" iconSide="right" onClick={openInWorkbench}>
Open in Query Workbench
<EuiButton iconSide="right" onClick={openInWorkbench}>
Continue in Query Workbench
</EuiButton>
) : (
<></>
Expand Down

0 comments on commit 85af6c0

Please sign in to comment.