lava-oushudb-dt-sql-parser/test/parser/impala/suggestion/tokenSuggestion.test.ts
霜序 e203f1a48a
feat: support impala (#184)
* feat(impala): add impala sqlLexer

* feat(impala): add impala grammar

* feat(impala): add alter table sql

* feat(impala): update alter table sql

* feat(impala): add alter db sql

* feat(impala): add alter view sql

* feat(impala): add compute stats/comment statement and update partition_desc for alter table

* feat(impala): add drop statement sql

* feat(impala): add revoke and grant sql

* feat(impala): add create db/function/role/view sql

* feat(impala): add describe/explain/invalidata_metadata/load_data sql

* feat(impala): add refresh/set/shutdown sql

* feat(impala): add truncate_table/use/values sql

* fix(impala): update shutdown and invaliddate_metadata

* feat(impala): add show/update/upsert sql

* feat(impala): add create/insert sql

* feat(impala): add select and delete sql

* feat(impala): add impala tokens and fix todo

* feat(impala): update impalaparser and some test unit

* feat(impala): add syntax suggestion

* feat(impala): add syntax suggestion

* feat(impala): update test unit

* feat(impala): remove reference

* fix(impala): add statement for sqlname and collect tableName

* fix(impala): fix syntax suggestion unit test

* fix(impala): update syntax suggestion and collect column

* feat(impala): add collect column create
2023-11-28 21:11:07 +08:00

110 lines
2.8 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import { CaretPosition } from '../../../../src/parser/common/basic-parser-types';
import impalaSQL from '../../../../src/parser/impala';
import { commentOtherLine } from '../../../helper';
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
describe('Impala SQL Token Suggestion', () => {
const parser = new impalaSQL();
test('After ALTER', () => {
const pos: CaretPosition = {
lineNumber: 1,
column: 7,
};
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
expect(suggestion).toEqual(['TABLE', 'VIEW', 'DATABASE']);
});
test('After CREATE', () => {
const pos: CaretPosition = {
lineNumber: 3,
column: 8,
};
const suggestion = parser.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toEqual([
'TABLE',
'EXTERNAL',
'VIEW',
'FUNCTION',
'AGGREGATE',
'ROLE',
'DATABASE',
'SCHEMA',
]);
});
test('After DROP', () => {
const pos: CaretPosition = {
lineNumber: 5,
column: 6,
};
const suggestion = parser.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toEqual([
'DATABASE',
'SCHEMA',
'TABLE',
'VIEW',
'STATS',
'INCREMENTAL',
'FUNCTION',
'AGGREGATE',
'ROLE',
]);
});
test('After INSERT', () => {
const pos: CaretPosition = {
lineNumber: 7,
column: 8,
};
const suggestion = parser.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toEqual(['INTO', 'OVERWRITE']);
});
test('After SHOW', () => {
const pos: CaretPosition = {
lineNumber: 9,
column: 6,
};
const suggestion = parser.getSuggestionAtCaretPosition(
commentOtherLine(tokenSql, pos.lineNumber),
pos
)?.keywords;
expect(suggestion).toEqual([
'DATABASES',
'SCHEMAS',
'TABLES',
'FUNCTIONS',
'ANALYTIC',
'AGGREGATE',
'CREATE',
'TABLE',
'COLUMN',
'PARTITIONS',
'RANGE',
'FILES',
'GRANT',
'ROLE',
'ROLES',
'CURRENT',
]);
});
});