2023-12-13 11:33:47 +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, EntityContextType } from 'src/parser/common/types';
|
2023-12-13 11:33:47 +08:00
|
|
|
|
|
|
|
const syntaxSql = fs.readFileSync(
|
|
|
|
path.join(__dirname, 'fixtures', 'multipleStatement.sql'),
|
|
|
|
'utf-8'
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('ImpalaSQL Multiple Statements Syntax Suggestion', () => {
|
2024-03-27 10:33:25 +08:00
|
|
|
const impala = new ImpalaSQL();
|
2023-12-13 11:33:47 +08:00
|
|
|
|
|
|
|
test('Select from table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 1,
|
|
|
|
column: 15,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = impala.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 9,
|
|
|
|
column: 17,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = impala.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE_CREATE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Insert into table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 15,
|
|
|
|
column: 13,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = impala.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Insert into select from table ', () => {
|
|
|
|
const pos: CaretPosition = {
|
|
|
|
lineNumber: 21,
|
|
|
|
column: 39,
|
|
|
|
};
|
2024-03-27 10:33:25 +08:00
|
|
|
const syntaxes = impala.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
2023-12-13 11:33:47 +08:00
|
|
|
const suggestion = syntaxes?.find(
|
2024-03-26 14:28:27 +08:00
|
|
|
(syn) => syn.syntaxContextType === EntityContextType.TABLE
|
2023-12-13 11:33:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestion).not.toBeUndefined();
|
|
|
|
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['t1', '.']);
|
|
|
|
});
|
|
|
|
});
|