Skip to content

Commit

Permalink
fix(YQL): suggest entity settings as YQLEntity (#192)
Browse files Browse the repository at this point in the history
* fix(YQL): suggest entity settings as YQLEntity

* fix(YQL): add replication and topicConsumer

---------

Co-authored-by: Elena Makarova <[email protected]>
  • Loading branch information
Raubzeug and Elena Makarova authored Jun 4, 2024
1 parent b007053 commit fb478ce
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 13 deletions.
5 changes: 3 additions & 2 deletions 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 All @@ -70,7 +71,7 @@ export interface YqlAutocompleteResult extends AutocompleteResultBase {
suggestTableFunctions?: boolean;
suggestPragmas?: boolean;
suggestTableHints?: string;
suggestTableSettings?: string;
suggestEntitySettings?: YQLEntity;
}

export interface ParserSyntaxError extends TokenPosition {
Expand Down
41 changes: 33 additions & 8 deletions src/autocomplete/databases/yql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,41 @@ function getTableHintsSuggestions({
return allRulesInList([YQLParser.RULE_an_id_hint, YQLParser.RULE_table_hint]);
}

function getTableSettingsSuggestions({
function getEntitySettingsSuggestions({
allRulesInList,
anyRuleInList,
}: GetParticularSuggestionProps): boolean | undefined {
if (anyRuleInList(YQLParser.RULE_table_setting_value)) {
}: GetParticularSuggestionProps): YQLEntity | undefined {
if (
anyRuleInList([
YQLParser.RULE_table_setting_value,
YQLParser.RULE_topic_setting_value,
YQLParser.RULE_topic_consumer_setting_value,
])
) {
return;
}
return allRulesInList([YQLParser.RULE_with_table_settings, YQLParser.RULE_an_id]);
if (allRulesInList([YQLParser.RULE_with_table_settings, YQLParser.RULE_an_id])) {
if (anyRuleInList(YQLParser.RULE_create_external_data_source_stmt)) {
return 'externalDataSource';
}
if (anyRuleInList(YQLParser.RULE_create_view_stmt)) {
return 'view';
}
if (anyRuleInList(YQLParser.RULE_create_table_stmt)) {
return 'table';
}
return;
}
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;
}

const ruleNames = YQLParser.ruleNames;
Expand Down Expand Up @@ -425,7 +452,7 @@ export function getGranularSuggestions(
const suggestFunctions = getFunctionsSuggestions(props);
const suggestAggregateFunctions = getAggregateFunctionsSuggestions(props);
const shouldSuggestTableHints = getTableHintsSuggestions(props);
const shouldSuggestTableSettings = getTableSettingsSuggestions(props);
const suggestEntitySettings = getEntitySettingsSuggestions(props);

return {
suggestWindowFunctions,
Expand All @@ -439,9 +466,7 @@ export function getGranularSuggestions(
suggestFunctions,
suggestAggregateFunctions,
suggestTableHints: shouldSuggestTableHints ? getParticularStatement(ruleList) : undefined,
suggestTableSettings: shouldSuggestTableSettings
? getParticularStatement(ruleList)
: undefined,
suggestEntitySettings,
suggestObject,
suggestTableStore,
suggestTable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ test('should suggest properly after source name', () => {
const keywordsSuggestion: KeywordSuggestion[] = [{value: 'WITH'}];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
});
test('should suggest properly after WITH', () => {
const autocompleteResult = parseYqlQueryWithCursor('CREATE EXTERNAL DATA SOURCE test WITH (|');

const keywordsSuggestion: KeywordSuggestion[] = [];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestEntitySettings).toEqual('externalDataSource');
});
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 @@ -93,14 +93,14 @@ test('should suggest properly table hints', () => {
const keywordsSuggestion: KeywordSuggestion[] = [{value: 'COLUMNS'}, {value: 'SCHEMA'}];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestTableHints).toEqual('create_table_stmt');
expect(autocompleteResult.suggestTableSettings).toBeFalsy();
expect(autocompleteResult.suggestEntitySettings).toBeFalsy();
});
test('should suggest properly table settings', () => {
const autocompleteResult = parseYqlQueryWithCursor(
'CREATE TABLE test_table (col1 String) WITH (set1 = 1, |',
);
const keywordsSuggestion: KeywordSuggestion[] = [];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestTableSettings).toEqual('create_table_stmt');
expect(autocompleteResult.suggestEntitySettings).toEqual('table');
expect(autocompleteResult.suggestTableHints).toBeFalsy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,28 @@ 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 (|',
);

const keywordsSuggestion: KeywordSuggestion[] = [];
expect(autocompleteResult.suggestKeywords).toEqual(keywordsSuggestion);
expect(autocompleteResult.suggestEntitySettings).toEqual('topic');
});
2 changes: 1 addition & 1 deletion src/autocomplete/databases/yql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type YqlAutocompleteResultPartial = Pick<
| 'suggestTableFunctions'
| 'suggestPragmas'
| 'suggestTableHints'
| 'suggestTableSettings'
| 'suggestEntitySettings'
>;

export interface InternalSuggestions
Expand Down

0 comments on commit fb478ce

Please sign in to comment.