2023-10-13 11:16:36 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-19 21:10:00 +08:00
|
|
|
import { commentOtherLine } from 'test/helper';
|
|
|
|
import HiveSQL from 'src/parser/hive';
|
|
|
|
import { CaretPosition } from 'src/parser/common/basic-parser-types';
|
2023-10-10 16:37:49 +08:00
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
2023-10-10 16:37:49 +08:00
|
|
|
|
2023-10-18 10:53:43 +08:00
|
|
|
describe('Hive SQL Token Suggestion', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
const parser = new HiveSQL();
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After ALTER', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
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;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-10-13 11:16:36 +08:00
|
|
|
'APPLICATION',
|
|
|
|
'GROUP',
|
|
|
|
'USER',
|
|
|
|
'POOL',
|
|
|
|
'TRIGGER',
|
|
|
|
'RESOURCE',
|
|
|
|
'SCHEDULED',
|
|
|
|
'INDEX',
|
|
|
|
'CONNECTOR',
|
|
|
|
'DATABASE',
|
|
|
|
'SCHEMA',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'VIEW',
|
|
|
|
'TABLE',
|
2023-10-10 16:37:49 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After CREATE', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
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;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-10-13 11:16:36 +08:00
|
|
|
'CONNECTOR',
|
|
|
|
'APPLICATION',
|
|
|
|
'GROUP',
|
|
|
|
'USER',
|
|
|
|
'POOL',
|
|
|
|
'TRIGGER',
|
|
|
|
'RESOURCE',
|
|
|
|
'ROLE',
|
|
|
|
'INDEX',
|
|
|
|
'TEMPORARY',
|
|
|
|
'FUNCTION',
|
|
|
|
'SCHEDULED',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'VIEW',
|
|
|
|
'OR',
|
|
|
|
'MANAGED',
|
|
|
|
'TABLE',
|
|
|
|
'EXTERNAL',
|
|
|
|
'TRANSACTIONAL',
|
|
|
|
'REMOTE',
|
|
|
|
'DATABASE',
|
|
|
|
'SCHEMA',
|
2023-10-10 16:37:49 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After DELETE', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
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;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['FROM']);
|
2023-10-10 16:37:49 +08:00
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After DESCRIBE', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
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;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-10-13 11:16:36 +08:00
|
|
|
'EXTENDED',
|
|
|
|
'FORMATTED',
|
|
|
|
'FUNCTION',
|
|
|
|
'CONNECTOR',
|
|
|
|
'DATABASE',
|
|
|
|
'SCHEMA',
|
2023-10-10 16:37:49 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After DROP', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
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;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-10-13 11:16:36 +08:00
|
|
|
'CONNECTOR',
|
|
|
|
'APPLICATION',
|
|
|
|
'GROUP',
|
|
|
|
'USER',
|
|
|
|
'POOL',
|
|
|
|
'TRIGGER',
|
|
|
|
'RESOURCE',
|
|
|
|
'ROLE',
|
|
|
|
'INDEX',
|
|
|
|
'TEMPORARY',
|
|
|
|
'FUNCTION',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'VIEW',
|
|
|
|
'SCHEDULED',
|
|
|
|
'TABLE',
|
|
|
|
'DATABASE',
|
|
|
|
'SCHEMA',
|
2023-10-10 16:37:49 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After EXPORT', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
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;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['TABLE']);
|
2023-10-10 16:37:49 +08:00
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After IMPORT', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 13,
|
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['FROM', 'TABLE', 'EXTERNAL']);
|
2023-10-10 16:37:49 +08:00
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After INSERT', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 15,
|
|
|
|
column: 8,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['INTO', 'OVERWRITE']);
|
2023-10-10 16:37:49 +08:00
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After LOAD', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 17,
|
|
|
|
column: 6,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary(['DATA']);
|
2023-10-10 16:37:49 +08:00
|
|
|
});
|
|
|
|
|
2023-10-13 11:16:36 +08:00
|
|
|
test('After SHOW', () => {
|
2023-10-10 16:37:49 +08:00
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 19,
|
|
|
|
column: 6,
|
|
|
|
};
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = parser.getSuggestionAtCaretPosition(
|
|
|
|
commentOtherLine(tokenSql, pos.lineNumber),
|
|
|
|
pos
|
|
|
|
)?.keywords;
|
2024-03-01 16:48:53 +08:00
|
|
|
expect(suggestion).toMatchUnorderedArrary([
|
2023-10-13 11:16:36 +08:00
|
|
|
'CURRENT',
|
|
|
|
'ROLES',
|
|
|
|
'PRINCIPALS',
|
|
|
|
'ROLE',
|
|
|
|
'GRANT',
|
|
|
|
'INDEX',
|
|
|
|
'INDEXES',
|
|
|
|
'FORMATTED',
|
|
|
|
'CONNECTORS',
|
|
|
|
'RESOURCE',
|
|
|
|
'CONF',
|
|
|
|
'TRANSACTIONS',
|
|
|
|
'COMPACTIONS',
|
|
|
|
'LOCKS',
|
|
|
|
'TBLPROPERTIES',
|
|
|
|
'TABLE',
|
|
|
|
'CREATE',
|
|
|
|
'PARTITIONS',
|
|
|
|
'FUNCTIONS',
|
|
|
|
'COLUMNS',
|
|
|
|
'SORTED',
|
|
|
|
'MATERIALIZED',
|
|
|
|
'VIEWS',
|
|
|
|
'TABLES',
|
|
|
|
'EXTENDED',
|
|
|
|
'DATABASES',
|
|
|
|
'SCHEMAS',
|
2023-10-10 16:37:49 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|