2023-06-13 09:28:48 +08:00
|
|
|
import path from 'path';
|
|
|
|
import { writeFileSync } from 'node:fs';
|
|
|
|
|
|
|
|
import FlinkSQL from '../../../../src/parser/flinksql';
|
2023-10-13 11:16:36 +08:00
|
|
|
import {
|
|
|
|
readSQL,
|
|
|
|
benchmark,
|
|
|
|
getReportTableHeader,
|
|
|
|
getReportTableRow,
|
|
|
|
exportReportTable,
|
|
|
|
} from '../../../helper';
|
2023-06-13 09:28:48 +08:00
|
|
|
|
|
|
|
const features = {
|
|
|
|
selectTable: readSQL(__dirname, 'selectTable.sql'),
|
|
|
|
createTable: readSQL(__dirname, 'createTable.sql'),
|
|
|
|
insertTable: readSQL(__dirname, 'insertTable.sql'),
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('FlinkSQL benchmark tests', () => {
|
|
|
|
const parser = new FlinkSQL();
|
|
|
|
let reportsHeader = getReportTableHeader('FlinkSQL Benchmark');
|
|
|
|
const reportData: string[] = [];
|
|
|
|
|
|
|
|
test('createTable Over 100 Rows', async () => {
|
2023-10-13 11:16:36 +08:00
|
|
|
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 100 Rows', () => {
|
2023-06-13 09:28:48 +08:00
|
|
|
const testSQL = features.createTable[0];
|
|
|
|
const res = parser.validate(testSQL);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
reportData.push(getReportTableRow('CreateTable', 100, 1, totalTimes, averageTimes));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('createTable Over 1000 Rows', async () => {
|
|
|
|
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 1000 Rows', () => {
|
|
|
|
const testSQL = features.createTable[1];
|
|
|
|
const res = parser.validate(testSQL);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
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);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
reportData.push(getReportTableRow('CreateTable', 5000, 1, totalTimes, averageTimes));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('selectTable Over 100 Rows', async () => {
|
2023-10-13 11:16:36 +08:00
|
|
|
const [totalTimes, averageTimes, msg] = benchmark('SelectTable Over 100 Rows', () => {
|
2023-06-13 09:28:48 +08:00
|
|
|
const testSQL = features.selectTable[0];
|
|
|
|
const res = parser.validate(testSQL);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
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);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
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);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
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);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
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);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
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);
|
2023-10-13 11:16:36 +08:00
|
|
|
expect(res).toEqual([]);
|
2023-06-13 09:28:48 +08:00
|
|
|
});
|
|
|
|
reportData.push(getReportTableRow('InsertTable', 5000, 1, totalTimes, averageTimes));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
2023-10-13 11:16:36 +08:00
|
|
|
exportReportTable(reportsHeader + reportData.join('\n'), __dirname);
|
|
|
|
});
|
|
|
|
});
|