chroe: devops (#180)
* ci: add dependencies about lint tool * ci: replace eslint with prettier * ci: add husky, cz and commitlint * style: lint fix via prettier * ci: add prettier and check-types to github workflow '
This commit is contained in:
@ -2,7 +2,13 @@ import path from 'path';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL, benchmark, getReportTableHeader, getReportTableRow, exportReportTable } from '../../../helper';
|
||||
import {
|
||||
readSQL,
|
||||
benchmark,
|
||||
getReportTableHeader,
|
||||
getReportTableRow,
|
||||
exportReportTable,
|
||||
} from '../../../helper';
|
||||
|
||||
const features = {
|
||||
selectTable: readSQL(__dirname, 'selectTable.sql'),
|
||||
@ -15,13 +21,11 @@ describe('FlinkSQL benchmark tests', () => {
|
||||
let reportsHeader = getReportTableHeader('FlinkSQL Benchmark');
|
||||
const reportData: string[] = [];
|
||||
|
||||
|
||||
test('createTable Over 100 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes , msg] = benchmark('CreateTable Over 100 Rows', () => {
|
||||
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 100 Rows', () => {
|
||||
const testSQL = features.createTable[0];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('CreateTable', 100, 1, totalTimes, averageTimes));
|
||||
});
|
||||
@ -30,91 +34,75 @@ describe('FlinkSQL benchmark tests', () => {
|
||||
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 1000 Rows', () => {
|
||||
const testSQL = features.createTable[1];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('CreateTable', 1000, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
test('createTable Over 5000 Rows', async () => {
|
||||
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 5000 Rows', () => {
|
||||
const testSQL = features.createTable[2];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('CreateTable', 5000, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
test('selectTable Over 100 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes , msg] = benchmark('SelectTable Over 100 Rows', () => {
|
||||
const [totalTimes, averageTimes, msg] = benchmark('SelectTable Over 100 Rows', () => {
|
||||
const testSQL = features.selectTable[0];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('SelectTable', 100, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
test('selectTable Over 1000 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes, msg] = benchmark('SelectTable Over 1000 Rows', () => {
|
||||
const testSQL = features.selectTable[1];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('SelectTable', 1000, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
test('selectTable Over 5000 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes, msg] = benchmark('SelectTable Over 5000 Rows', () => {
|
||||
const testSQL = features.selectTable[2];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('SelectTable', 5000, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
test('insertTable Over 100 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes, msg] = benchmark('InsertTable Over 100 Rows', () => {
|
||||
const testSQL = features.insertTable[0];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('InsertTable', 100, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
test('insertTable Over 1000 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes, msg] = benchmark('InsertTable Over 1000 Rows', () => {
|
||||
const testSQL = features.insertTable[1];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('InsertTable', 1000, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
|
||||
test('insertTable Over 5000 Rows', async () => {
|
||||
|
||||
const [totalTimes, averageTimes, msg] = benchmark('InsertTable Over 5000 Rows', () => {
|
||||
const testSQL = features.insertTable[2];
|
||||
const res = parser.validate(testSQL);
|
||||
expect(res).toEqual([])
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
reportData.push(getReportTableRow('InsertTable', 5000, 1, totalTimes, averageTimes));
|
||||
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
exportReportTable(reportsHeader + reportData.join('\n'), __dirname)
|
||||
})
|
||||
|
||||
});
|
||||
exportReportTable(reportsHeader + reportData.join('\n'), __dirname);
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import FlinkSQL from '../../../src/parser/flinksql';
|
||||
import { FlinkSqlParserListener } from '../../../src/lib/flinksql/FlinkSqlParserListener';
|
||||
import { TableExpressionContext } from '../../../src/lib/flinksql/FlinkSqlParser';
|
||||
import { ParseTreeListener } from 'antlr4ts/tree';
|
||||
|
||||
describe('Flink SQL Listener Tests', () => {
|
||||
const expectTableName = 'user1';
|
||||
@ -12,14 +13,13 @@ describe('Flink SQL Listener Tests', () => {
|
||||
test('Listener enterTableName', async () => {
|
||||
let result = '';
|
||||
class MyListener implements FlinkSqlParserListener {
|
||||
|
||||
enterTableExpression = (ctx: TableExpressionContext): void => {
|
||||
result = ctx.text.toLowerCase();
|
||||
}
|
||||
};
|
||||
}
|
||||
const listenTableName = new MyListener();
|
||||
|
||||
await parser.listen(listenTableName, parserTree);
|
||||
await parser.listen(listenTableName as ParseTreeListener, parserTree);
|
||||
expect(result).toBe(expectTableName);
|
||||
});
|
||||
});
|
||||
|
@ -1,9 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CaretPosition, SyntaxContextType } from '../../../../src/parser/common/basic-parser-types';
|
||||
import FlinkSQL from '../../../../src/parser/flinksql'
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
|
||||
const syntaxSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'), 'utf-8');
|
||||
const syntaxSql = fs.readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'syntaxSuggestion.sql'),
|
||||
'utf-8'
|
||||
);
|
||||
const multipleSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'multipleSql.sql'), 'utf-8');
|
||||
|
||||
describe('Flink SQL Syntax Suggestion', () => {
|
||||
@ -13,187 +16,201 @@ describe('Flink SQL Syntax Suggestion', () => {
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||
})
|
||||
});
|
||||
|
||||
test("Multiple SQL use database", () => {
|
||||
test('Multiple SQL use database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 10,
|
||||
}
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat1', '.' ]);
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat1', '.']);
|
||||
});
|
||||
|
||||
test('Drop catalog', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 1,
|
||||
column: 17
|
||||
}
|
||||
column: 17,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.CATALOG);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.CATALOG
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat' ]);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat']);
|
||||
});
|
||||
|
||||
test('Select table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 19
|
||||
}
|
||||
column: 19,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||
);
|
||||
console.log(syntaxes);
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.']);
|
||||
});
|
||||
|
||||
test('Create table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE_CREATE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.', 'db' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.', 'db']);
|
||||
});
|
||||
|
||||
test('Show tables from', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 7,
|
||||
column: 21
|
||||
}
|
||||
column: 21,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat']);
|
||||
});
|
||||
|
||||
test('Alter database', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 9,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.DATABASE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'cat', '.' ])
|
||||
})
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cat', '.']);
|
||||
});
|
||||
|
||||
test('Drop view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 11,
|
||||
column: 12
|
||||
}
|
||||
column: 12,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([ 'v' ]);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['v']);
|
||||
});
|
||||
|
||||
test('Select view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 13,
|
||||
column: 15
|
||||
}
|
||||
column: 15,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual([]);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual([]);
|
||||
});
|
||||
|
||||
|
||||
test('Create view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 15,
|
||||
column: 15
|
||||
}
|
||||
column: 15,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['cv']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['cv']);
|
||||
});
|
||||
|
||||
test('Function call', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 17,
|
||||
column: 27
|
||||
}
|
||||
column: 27,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['calculate_age']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['calculate_age']);
|
||||
});
|
||||
|
||||
test('Create Function', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 19,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['fnc']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['fnc']);
|
||||
});
|
||||
|
||||
test('Show columns from view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 21,
|
||||
column: 22
|
||||
}
|
||||
column: 22,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['vie']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['vie']);
|
||||
});
|
||||
|
||||
test('Show create table', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 23,
|
||||
column: 22
|
||||
}
|
||||
column: 22,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.TABLE
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['tb1']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['tb1']);
|
||||
});
|
||||
|
||||
test('Show create view', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 25,
|
||||
column: 20
|
||||
}
|
||||
column: 20,
|
||||
};
|
||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||
const suggestion = syntaxes?.find(
|
||||
(syn) => syn.syntaxContextType === SyntaxContextType.VIEW
|
||||
);
|
||||
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map(token => token.text))
|
||||
.toEqual(['v1']);
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['v1']);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CaretPosition } from '../../../../src/parser/common/basic-parser-types';
|
||||
import FlinkSQL from '../../../../src/parser/flinksql'
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
|
||||
const tokenSql = fs.readFileSync(path.join(__dirname, 'fixtures', 'tokenSuggestion.sql'), 'utf-8');
|
||||
|
||||
@ -11,47 +11,50 @@ describe('Flink SQL Token Suggestion', () => {
|
||||
test('Use Statement ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 3,
|
||||
column: 5
|
||||
}
|
||||
column: 5,
|
||||
};
|
||||
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||
|
||||
expect(suggestion)
|
||||
.toEqual([ 'MODULES', 'CATALOG' ])
|
||||
})
|
||||
|
||||
expect(suggestion).toEqual(['MODULES', 'CATALOG']);
|
||||
});
|
||||
|
||||
test('Create Statement ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 5,
|
||||
column: 8
|
||||
}
|
||||
column: 8,
|
||||
};
|
||||
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||
|
||||
expect(suggestion)
|
||||
.toEqual([ 'CATALOG', 'FUNCTION', 'TEMPORARY', 'VIEW', 'DATABASE', 'TABLE' ])
|
||||
})
|
||||
|
||||
expect(suggestion).toEqual([
|
||||
'CATALOG',
|
||||
'FUNCTION',
|
||||
'TEMPORARY',
|
||||
'VIEW',
|
||||
'DATABASE',
|
||||
'TABLE',
|
||||
]);
|
||||
});
|
||||
|
||||
test('Show Statement ', () => {
|
||||
const pos: CaretPosition = {
|
||||
lineNumber: 7,
|
||||
column: 6
|
||||
}
|
||||
column: 6,
|
||||
};
|
||||
const suggestion = parser.getSuggestionAtCaretPosition(tokenSql, pos)?.keywords;
|
||||
|
||||
expect(suggestion)
|
||||
.toEqual([
|
||||
'MODULES',
|
||||
'FULL',
|
||||
'FUNCTIONS',
|
||||
'USER',
|
||||
'CREATE',
|
||||
'COLUMNS',
|
||||
'TABLES',
|
||||
'CURRENT',
|
||||
'CATALOGS',
|
||||
'DATABASES',
|
||||
'JARS',
|
||||
'VIEWS'
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
expect(suggestion).toEqual([
|
||||
'MODULES',
|
||||
'FULL',
|
||||
'FUNCTIONS',
|
||||
'USER',
|
||||
'CREATE',
|
||||
'COLUMNS',
|
||||
'TABLES',
|
||||
'CURRENT',
|
||||
'CATALOGS',
|
||||
'DATABASES',
|
||||
'JARS',
|
||||
'VIEWS',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
table: readSQL(__dirname, 'alterTable.sql'),
|
||||
@ -26,11 +26,10 @@ describe('FlinkSQL Alter Statements Syntax Tests', () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
features.function.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
// 综合测试的 sql 不做切割
|
||||
const features = {
|
||||
chores: readSQL(__dirname, 'chore.sql')
|
||||
chores: readSQL(__dirname, 'chore.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Chore Syntax Tests', () => {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
|
||||
// 注释 sql 不做切割
|
||||
const features = {
|
||||
comments: fs.readFileSync(path.join(__dirname, 'fixtures', 'comment.sql'), 'utf-8')
|
||||
comments: fs.readFileSync(path.join(__dirname, 'fixtures', 'comment.sql'), 'utf-8'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Comment Syntax Tests', () => {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
|
||||
// 综合测试的 sql 不做切割
|
||||
const features = {
|
||||
templates: fs.readFileSync(path.join(__dirname, 'fixtures', 'templates.sql'), 'utf-8')
|
||||
templates: fs.readFileSync(path.join(__dirname, 'fixtures', 'templates.sql'), 'utf-8'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Comprehensive Tests', () => {
|
||||
@ -13,4 +13,3 @@ describe('FlinkSQL Comprehensive Tests', () => {
|
||||
expect(parser.validate(features.templates).length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
describes: readSQL(__dirname, 'describe.sql')
|
||||
describes: readSQL(__dirname, 'describe.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Describe Syntax Tests', () => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
table: readSQL(__dirname, 'dropTable.sql'),
|
||||
@ -30,7 +30,7 @@ describe('FlinkSQL Drop Statements Tests', () => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
features.database.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
dtAddFiles: readSQL(__dirname, 'dtAddFile.sql')
|
||||
dtAddFiles: readSQL(__dirname, 'dtAddFile.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL DT Add File Syntax Tests', () => {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
explains: readSQL(__dirname, 'explain.sql')
|
||||
explains: readSQL(__dirname, 'explain.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Explain Syntax Tests', () => {
|
||||
|
@ -1,13 +1,12 @@
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
const features = {
|
||||
InsertFromSelectQueries: readSQL(__dirname, 'insertFromSelectQueries.sql'),
|
||||
InsertValuesIntoTable: readSQL(__dirname, 'insertValuesIntoTable.sql'),
|
||||
InsertMultipleTable: readSQL(__dirname, 'insertMultipleTable.sql')
|
||||
InsertMultipleTable: readSQL(__dirname, 'insertMultipleTable.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Insert Syntax Tests', () => {
|
||||
|
@ -1,22 +1,22 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
const features = {
|
||||
base: readSQL(__dirname, "select.sql"),
|
||||
withClause: readSQL(__dirname, "selectWithClause.sql"),
|
||||
distinct: readSQL(__dirname, "selectDistinct.sql"),
|
||||
windowTVF: readSQL(__dirname, "selectWindowTVF.sql"),
|
||||
aggregation: readSQL(__dirname, "selectAggregation.sql"),
|
||||
join: readSQL(__dirname, "selectJoin.sql"),
|
||||
setOperation: readSQL(__dirname, "selectSetOperations.sql"),
|
||||
pattern: readSQL(__dirname, "selectPatternRecognition.sql"),
|
||||
where: readSQL(__dirname, "selectWhere.sql"),
|
||||
base: readSQL(__dirname, 'select.sql'),
|
||||
withClause: readSQL(__dirname, 'selectWithClause.sql'),
|
||||
distinct: readSQL(__dirname, 'selectDistinct.sql'),
|
||||
windowTVF: readSQL(__dirname, 'selectWindowTVF.sql'),
|
||||
aggregation: readSQL(__dirname, 'selectAggregation.sql'),
|
||||
join: readSQL(__dirname, 'selectJoin.sql'),
|
||||
setOperation: readSQL(__dirname, 'selectSetOperations.sql'),
|
||||
pattern: readSQL(__dirname, 'selectPatternRecognition.sql'),
|
||||
where: readSQL(__dirname, 'selectWhere.sql'),
|
||||
};
|
||||
|
||||
describe("FlinkSQL Query Statement Tests", () => {
|
||||
describe("Base Select", () => {
|
||||
describe('FlinkSQL Query Statement Tests', () => {
|
||||
describe('Base Select', () => {
|
||||
features.base.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
@ -24,7 +24,7 @@ describe("FlinkSQL Query Statement Tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("With Clause Select", () => {
|
||||
describe('With Clause Select', () => {
|
||||
features.withClause.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
@ -32,60 +32,59 @@ describe("FlinkSQL Query Statement Tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("Select DISTINCT", () => {
|
||||
describe('Select DISTINCT', () => {
|
||||
features.distinct.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("Select Window TVF", () => {
|
||||
describe('Select Window TVF', () => {
|
||||
features.windowTVF.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("Select Aggregation", () => {
|
||||
describe('Select Aggregation', () => {
|
||||
features.aggregation.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("Select Join", () => {
|
||||
describe('Select Join', () => {
|
||||
features.join.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("Select Set Operations", () => {
|
||||
describe('Select Set Operations', () => {
|
||||
features.setOperation.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("Select Pattern Recognition", () => {
|
||||
describe('Select Pattern Recognition', () => {
|
||||
features.pattern.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("Select Where", () => {
|
||||
describe('Select Where', () => {
|
||||
features.where.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,8 +1,8 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
shows: readSQL(__dirname, 'show.sql')
|
||||
shows: readSQL(__dirname, 'show.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Show Syntax Tests', () => {
|
||||
|
@ -1,13 +1,13 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import { readSQL } from "../../../helper";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
const features = {
|
||||
uses: readSQL(__dirname, 'use.sql')
|
||||
uses: readSQL(__dirname, 'use.sql'),
|
||||
};
|
||||
|
||||
describe('FlinkSQL Use Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
features.uses.forEach((sql) => {
|
||||
it(sql, () => {
|
||||
expect(parser.validate(sql).length).toBe(0);
|
||||
|
@ -13,13 +13,16 @@ describe('Flink SQL Visitor Tests', () => {
|
||||
|
||||
test('Visitor visitTableName', () => {
|
||||
let result = '';
|
||||
class MyVisitor extends AbstractParseTreeVisitor<any> implements FlinkSqlParserVisitor<any>{
|
||||
class MyVisitor
|
||||
extends AbstractParseTreeVisitor<any>
|
||||
implements FlinkSqlParserVisitor<any>
|
||||
{
|
||||
protected defaultResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
visitTableExpression = (ctx): void => {
|
||||
result = ctx.text.toLowerCase();
|
||||
}
|
||||
};
|
||||
}
|
||||
const visitor: any = new MyVisitor();
|
||||
visitor.visit(parserTree);
|
||||
|
Reference in New Issue
Block a user