2023-11-28 21:11:07 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-03-27 10:33:25 +08:00
|
|
|
import { ImpalaSQL } from 'src/parser/impala';
|
|
|
|
import { CaretPosition } from 'src/parser/common/types';
|
2024-01-19 21:10:00 +08:00
|
|
|
import { commentOtherLine } from 'test/helper';
|
2023-11-28 21:11:07 +08:00
|
|
|
|
|
|
|
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
|
|
|
|
|
|
|
describe('Impala SQL Token Suggestion', () => {
|
2024-03-27 10:33:25 +08:00
|
|
|
const impala = new ImpalaSQL();
|
2023-11-28 21:11:07 +08:00
|
|
|
|
|
|
|
test('After ALTER', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 7,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const suggestion = impala.getSuggestionAtCaretPosition(
|
2023-12-13 11:33:47 +08:00
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-11-28 21:11:07 +08:00
|
|
|
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['TABLE', 'VIEW', 'DATABASE']);
|
2023-11-28 21:11:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('After CREATE', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 3,
|
|
|
|
column: 8,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const suggestion = impala.getSuggestionAtCaretPosition(
|
2023-11-28 21:11:07 +08:00
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-11-28 21:11:07 +08:00
|
|
|
'TABLE',
|
|
|
|
'EXTERNAL',
|
|
|
|
'VIEW',
|
|
|
|
'FUNCTION',
|
|
|
|
'AGGREGATE',
|
|
|
|
'ROLE',
|
|
|
|
'DATABASE',
|
|
|
|
'SCHEMA',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After DROP', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 5,
|
|
|
|
column: 6,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const suggestion = impala.getSuggestionAtCaretPosition(
|
2023-11-28 21:11:07 +08:00
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-11-28 21:11:07 +08:00
|
|
|
'DATABASE',
|
|
|
|
'SCHEMA',
|
|
|
|
'TABLE',
|
|
|
|
'VIEW',
|
|
|
|
'STATS',
|
|
|
|
'INCREMENTAL',
|
|
|
|
'FUNCTION',
|
|
|
|
'AGGREGATE',
|
|
|
|
'ROLE',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After INSERT', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 7,
|
|
|
|
column: 8,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const suggestion = impala.getSuggestionAtCaretPosition(
|
2023-11-28 21:11:07 +08:00
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['INTO', 'OVERWRITE']);
|
2023-11-28 21:11:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('After SHOW', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 9,
|
|
|
|
column: 6,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const suggestion = impala.getSuggestionAtCaretPosition(
|
2023-11-28 21:11:07 +08:00
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-11-28 21:11:07 +08:00
|
|
|
'DATABASES',
|
|
|
|
'SCHEMAS',
|
|
|
|
'TABLES',
|
|
|
|
'FUNCTIONS',
|
|
|
|
'ANALYTIC',
|
|
|
|
'AGGREGATE',
|
|
|
|
'CREATE',
|
|
|
|
'TABLE',
|
|
|
|
'COLUMN',
|
|
|
|
'PARTITIONS',
|
|
|
|
'RANGE',
|
|
|
|
'FILES',
|
|
|
|
'GRANT',
|
|
|
|
'ROLE',
|
|
|
|
'ROLES',
|
|
|
|
'CURRENT',
|
|
|
|
]);
|
|
|
|
});
|
2024-04-21 12:10:36 +08:00
|
|
|
|
|
|
|
test('Create table with column dataType', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 11,
|
|
|
|
column: 21,
|
|
|
|
};
|
|
|
|
const suggestion = impala.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
|
|
|
const dataTypes = [
|
|
|
|
'INT',
|
|
|
|
'BINARY',
|
|
|
|
'BIGINT',
|
|
|
|
'BOOLEAN',
|
|
|
|
'CHAR',
|
|
|
|
'DATE',
|
|
|
|
'DECIMAL',
|
|
|
|
'DOUBLE',
|
|
|
|
'INT',
|
|
|
|
'MAP',
|
|
|
|
'REAL',
|
|
|
|
'SMALLINT',
|
|
|
|
'FLOAT',
|
|
|
|
'STRING',
|
|
|
|
'STRUCT',
|
|
|
|
'TIMESTAMP',
|
|
|
|
'TINYINT',
|
|
|
|
'VARCHAR',
|
|
|
|
'COMPLEX',
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(dataTypes.every((dataType) => suggestion.includes(dataType))).toBe(true);
|
|
|
|
});
|
2023-11-28 21:11:07 +08:00
|
|
|
});
|