2023-10-12 17:08:21 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2023-12-19 19:22:27 +08:00
|
|
|
import { SparkSQL, CaretPosition } from '../../../filters';
|
2023-12-13 11:33:47 +08:00
|
|
|
import { commentOtherLine } from '../../../helper';
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
|
|
|
|
2023-10-18 10:53:43 +08:00
|
|
|
describe('Spark SQL Token Suggestion', () => {
|
2023-10-12 17:08:21 +08:00
|
|
|
const parser = new SparkSQL();
|
|
|
|
|
|
|
|
test('After ALTER', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 7,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(suggestion).toEqual(['TABLE', 'INDEX', 'VIEW', 'DATABASE', 'NAMESPACE', 'SCHEMA']);
|
2023-10-12 17:08:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('After CREATE', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 3,
|
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'TEMPORARY',
|
|
|
|
'INDEX',
|
|
|
|
'ROLE',
|
|
|
|
'FUNCTION',
|
|
|
|
'OR',
|
|
|
|
'GLOBAL',
|
|
|
|
'VIEW',
|
|
|
|
'TABLE',
|
|
|
|
'EXTERNAL',
|
|
|
|
'DATABASE',
|
|
|
|
'NAMESPACE',
|
|
|
|
'SCHEMA',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After DELETE', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 5,
|
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual(['FROM']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After DESCRIBE', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 7,
|
|
|
|
column: 10,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'WITH',
|
|
|
|
'SELECT',
|
|
|
|
'MAP',
|
|
|
|
'REDUCE',
|
|
|
|
'FROM',
|
|
|
|
'TABLE',
|
|
|
|
'VALUES',
|
|
|
|
'QUERY',
|
|
|
|
'EXTENDED',
|
|
|
|
'FORMATTED',
|
|
|
|
'DATABASE',
|
|
|
|
'FUNCTION',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After DROP', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 9,
|
|
|
|
column: 6,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'TEMPORARY',
|
|
|
|
'INDEX',
|
|
|
|
'ROLE',
|
|
|
|
'FUNCTION',
|
|
|
|
'VIEW',
|
|
|
|
'TABLE',
|
|
|
|
'DATABASE',
|
|
|
|
'NAMESPACE',
|
|
|
|
'SCHEMA',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After INSERT', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 11,
|
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(suggestion).toEqual(['OVERWRITE', 'INTO']);
|
2023-10-12 17:08:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('After LOAD', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 13,
|
|
|
|
column: 6,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(suggestion).toEqual(['DATA']);
|
2023-10-12 17:08:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('After SHOW', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 15,
|
|
|
|
column: 6,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual([
|
|
|
|
'LOCKS',
|
|
|
|
'INDEXES',
|
|
|
|
'TRANSACTIONS',
|
|
|
|
'CREATE',
|
|
|
|
'COMPACTIONS',
|
|
|
|
'CURRENT',
|
|
|
|
'ROLES',
|
|
|
|
'PRINCIPALS',
|
|
|
|
'ROLE',
|
|
|
|
'GRANT',
|
|
|
|
'CATALOGS',
|
|
|
|
'FUNCTIONS',
|
|
|
|
'ALL',
|
|
|
|
'SYSTEM',
|
|
|
|
'USER',
|
|
|
|
'PARTITIONS',
|
|
|
|
'VIEWS',
|
|
|
|
'COLUMNS',
|
|
|
|
'TBLPROPERTIES',
|
|
|
|
'TABLE',
|
|
|
|
'TABLES',
|
|
|
|
'DATABASES',
|
|
|
|
'NAMESPACES',
|
|
|
|
'SCHEMAS',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After EXPORT', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 17,
|
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2023-10-12 17:08:21 +08:00
|
|
|
|
|
|
|
expect(suggestion).toEqual(['TABLE']);
|
|
|
|
});
|
|
|
|
});
|