Optimize/auto complete (#178)
* feat: optimize hive function name auto complete * feat: optimize flink rules that c3 prefer to * feat: optimize flink autoComplete * test: flink auto complete unit tests
This commit is contained in:
@ -1,11 +1,25 @@
|
||||
INSERT INTO cat.db.tb
|
||||
|
||||
SELECT * FROM cat.db
|
||||
|
||||
DROP CATALOG cat;
|
||||
;
|
||||
SELECT * FROM cat. ;
|
||||
;
|
||||
CREATE TABLE cat.db ;
|
||||
;
|
||||
SHOW TABLES FROM cat;
|
||||
;
|
||||
ALTER DATABASE cat.;
|
||||
;
|
||||
DROP VIEW v;
|
||||
;
|
||||
SELECT * FROM ;
|
||||
;
|
||||
CREATE VIEW cv;
|
||||
;
|
||||
SELECT name, calculate_age(birthdate) AS age FROM students;
|
||||
;
|
||||
CREATE FUNCTION fnc;
|
||||
;
|
||||
SHOW COLUMNS FROM vie;
|
||||
;
|
||||
SHOW CREATE TABLE tb1;
|
||||
|
||||
SHOW TABLES FROM cat
|
||||
|
||||
ALTER DATABASE cat.
|
||||
|
||||
USE DATABASE cat.
|
||||
SHOW CREATE VIEW v1;
|
@ -15,30 +15,43 @@ describe('Flink SQL Syntax Suggestion', () => {
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
})
|
||||
|
||||
test('Insert table ', () => {
|
||||
test("Multiple SQL use database", () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 22
|
||||
lineNumber: 19,
|
||||
column: 10,
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.', 'db', '.', 'tb' ])
|
||||
.toEqual([ 'cat1', '.' ]);
|
||||
})
|
||||
|
||||
test('Drop catalog', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 17
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.CATALOG);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat' ]);
|
||||
});
|
||||
|
||||
test('Select table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 21
|
||||
column: 19
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
|
||||
console.log(syntaxes);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.', 'db' ])
|
||||
.toEqual([ 'cat', '.' ])
|
||||
})
|
||||
|
||||
test('Create table', () => {
|
||||
@ -60,7 +73,7 @@ describe('Flink SQL Syntax Suggestion', () => {
|
||||
column: 21
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
@ -80,30 +93,107 @@ describe('Flink SQL Syntax Suggestion', () => {
|
||||
.toEqual([ 'cat', '.' ])
|
||||
})
|
||||
|
||||
test('Use database', () => {
|
||||
test('Drop view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 9,
|
||||
lineNumber: 11,
|
||||
column: 12
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'v' ]);
|
||||
});
|
||||
|
||||
test('Select view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 13,
|
||||
column: 15
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([]);
|
||||
});
|
||||
|
||||
test('Create view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 15,
|
||||
column: 15
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['cv']);
|
||||
});
|
||||
|
||||
test('Function call', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 17,
|
||||
column: 27
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['calculate_age']);
|
||||
});
|
||||
|
||||
test('Create Function', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 20
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.' ]);
|
||||
})
|
||||
.toEqual(['fnc']);
|
||||
});
|
||||
|
||||
test("Multiple SQL use database", () => {
|
||||
test('Show columns from view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 10,
|
||||
lineNumber: 21,
|
||||
column: 22
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat1', '.' ]);
|
||||
})
|
||||
.toEqual(['vie']);
|
||||
});
|
||||
|
||||
test('Show create table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 23,
|
||||
column: 22
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['tb1']);
|
||||
});
|
||||
|
||||
test('Show create view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 25,
|
||||
column: 20
|
||||
}
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['v1']);
|
||||
});
|
||||
})
|
Reference in New Issue
Block a user