Skip to content

Commit

Permalink
fix(YQL): add replication and topicConsumer
Browse files Browse the repository at this point in the history
  • Loading branch information
Elena Makarova committed Jun 4, 2024
1 parent d0805f3 commit a2ebf02
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/autocomplete/autocomplete-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export type YQLEntity =
| 'topic'
| 'group'
| 'user'
| 'tableIndex';
| 'tableIndex'
| 'topicConsumer';

export interface YqlAutocompleteResult extends AutocompleteResultBase {
suggestTableIndexes?: TableIndexSuggestion;
Expand Down
14 changes: 13 additions & 1 deletion src/autocomplete/databases/yql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,13 @@ function getEntitySettingsSuggestions({
allRulesInList,
anyRuleInList,
}: GetParticularSuggestionProps): YQLEntity | undefined {
if (anyRuleInList([YQLParser.RULE_table_setting_value, YQLParser.RULE_topic_setting_value])) {
if (
anyRuleInList([
YQLParser.RULE_table_setting_value,
YQLParser.RULE_topic_setting_value,
YQLParser.RULE_topic_consumer_setting_value,
])
) {
return;
}
if (allRulesInList([YQLParser.RULE_with_table_settings, YQLParser.RULE_an_id])) {
Expand All @@ -379,6 +385,12 @@ function getEntitySettingsSuggestions({
if (allRulesInList([YQLParser.RULE_with_topic_settings, YQLParser.RULE_an_id])) {
return 'topic';
}
if (allRulesInList([YQLParser.RULE_topic_consumer_with_settings, YQLParser.RULE_an_id])) {
return 'topicConsumer';
}
if (allRulesInList([YQLParser.RULE_replication_settings, YQLParser.RULE_an_id])) {
return 'replication';
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ test('should suggest properly after FOR', () => {
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestEntity).toEqual(['table']);
});
test('should suggest properly after FOR', () => {
const autocompleteResult = parseYqlQueryWithCursor(
'CREATE ASYNC REPLICATION test FOR target AS target |',
);

const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
});
test('should suggest properly after WITH', () => {
const autocompleteResult = parseYqlQueryWithCursor(
'CREATE ASYNC REPLICATION test FOR target AS target WITH (|',
);

const keywordsSuggestion: KeywordSuggestion[] = [];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestEntitySettings).toEqual('replication');
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ test('should suggest properly after consumer name', () => {
const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
});
test('should suggest properly after consumer WITH', () => {
const autocompleteResult = parseYqlQueryWithCursor(
'CREATE TOPIC test (CONSUMER test_consumer WITH (|',
);

const keywordsSuggestion: KeywordSuggestion[] = [];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestEntitySettings).toEqual('topicConsumer');
});
test('should suggest properly after consumer statement', () => {
const autocompleteResult = parseYqlQueryWithCursor(
'CREATE TOPIC test (CONSUMER test_consumer) |',
);
const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
});
test('should suggest properly after WITH', () => {
const autocompleteResult = parseYqlQueryWithCursor(
'CREATE TOPIC test (CONSUMER test_consumer) WITH (|',
Expand Down

0 comments on commit a2ebf02

Please sign in to comment.