update sql parser name

This commit is contained in:
xigua 2020-12-17 11:44:45 +08:00
parent 0d47b7debc
commit edbc87e8f1
15 changed files with 9046 additions and 9040 deletions

View File

@ -14,7 +14,7 @@
* This file is an adaptation of Presto's presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4 grammar. * This file is an adaptation of Presto's presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4 grammar.
*/ */
grammar SqlBase; grammar SparkSql;
@parser::members { @parser::members {
/** /**

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,19 @@
import { InputStream, CommonTokenStream, Lexer } from 'antlr4'; import { InputStream, CommonTokenStream, Lexer } from 'antlr4';
import { SqlBaseLexer } from '../lib/spark/SqlBaseLexer'; import { SparkSqlLexer } from '../lib/spark/SparkSqlLexer';
import { SqlBaseParser } from '../lib/spark/SqlBaseParser'; import { SparkSqlParser } from '../lib/spark/SparkSqlParser';
export * from '../lib/spark/SqlBaseVisitor'; export * from '../lib/spark/SparkSqlVisitor';
export * from '../lib/spark/SqlBaseListener'; export * from '../lib/spark/SparkSqlListener';
import BasicParser from './common/BasicParser'; import BasicParser from './common/BasicParser';
export default class SparkSQL extends BasicParser { export default class SparkSQL extends BasicParser {
public createLexer(input: string): Lexer { public createLexer(input: string): Lexer {
const chars = new InputStream(input.toUpperCase()); // Some Lexer only support uppercase token, So you need transform const chars = new InputStream(input.toUpperCase()); // Some Lexer only support uppercase token, So you need transform
const lexer = <unknown> new SqlBaseLexer(chars) as Lexer; const lexer = <unknown> new SparkSqlLexer(chars) as Lexer;
return lexer; return lexer;
} }
public createParserFromLexer(lexer: Lexer) { public createParserFromLexer(lexer: Lexer) {
const tokenStream = new CommonTokenStream(lexer); const tokenStream = new CommonTokenStream(lexer);
return new SqlBaseParser(tokenStream); return new SparkSqlParser(tokenStream);
} }
} }

View File

@ -1,4 +1,4 @@
import SQLParser, { SqlBaseListener } from '../../../src/parser/spark'; import SQLParser, { SparkSqlListener } from '../../../src/parser/spark';
describe('Spark SQL Listener Tests', () => { describe('Spark SQL Listener Tests', () => {
const expectTableName = 'user1'; const expectTableName = 'user1';
@ -9,7 +9,7 @@ describe('Spark SQL Listener Tests', () => {
test('Listener enterTableName', () => { test('Listener enterTableName', () => {
let result = ''; let result = '';
class MyListener extends SqlBaseListener { class MyListener extends SparkSqlListener {
enterTableName(ctx): void { enterTableName(ctx): void {
result = ctx.getText().toLowerCase(); result = ctx.getText().toLowerCase();
} }

View File

@ -1,7 +1,6 @@
/* eslint-disable max-len */ /* eslint-disable max-len */
import SQLParser from '../../../src/parser/spark'; import SQLParser from '../../../src/parser/spark';
// const log = console.log.bind(console);
const error = console.log.bind(console, '***** error\n'); const error = console.log.bind(console, '***** error\n');
const validateTest = (sqls) => { const validateTest = (sqls) => {

View File

@ -1,4 +1,4 @@
import SQLParser, { SqlBaseVisitor } from '../../../src/parser/spark'; import SQLParser, { SparkSqlVisitor } from '../../../src/parser/spark';
describe('Spark SQL Visitor Tests', () => { describe('Spark SQL Visitor Tests', () => {
const expectTableName = 'user1'; const expectTableName = 'user1';
@ -13,7 +13,7 @@ describe('Spark SQL Visitor Tests', () => {
test('Visitor visitTableName', () => { test('Visitor visitTableName', () => {
let result = ''; let result = '';
class MyVisitor extends SqlBaseVisitor { class MyVisitor extends SparkSqlVisitor {
visitTableName(ctx): void { visitTableName(ctx): void {
result = ctx.getText().toLowerCase(); result = ctx.getText().toLowerCase();
super.visitTableName(ctx); super.visitTableName(ctx);