dt-sql-parser
Version:
SQL Parsers for BigData, built with antlr4
119 lines (118 loc) • 3.77 kB
JavaScript
import { CreateDatabaseContext, CreateTableContext, CreateViewContext, PhysicalColumnDefinitionContext, TableReferenceContext, } from '../../lib/flink/FlinkSqlParser';
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
import { EntityContextType } from '../common/types';
export class FlinkEntityCollector extends EntityCollector {
/** ====== Entity Begin */
exitCatalogPathCreate(ctx) {
this.pushEntity(ctx, EntityContextType.CATALOG_CREATE);
}
exitCatalogPath(ctx) {
this.pushEntity(ctx, EntityContextType.CATALOG);
}
exitDatabasePathCreate(ctx) {
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, [
{
attrName: AttrName.comment,
endContextList: [CreateDatabaseContext.name],
},
]);
}
exitDatabasePath(ctx) {
this.pushEntity(ctx, EntityContextType.DATABASE);
}
exitTablePath(ctx) {
var _a;
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
? [
{
attrName: AttrName.alias,
endContextList: [TableReferenceContext.name],
},
]
: undefined);
}
exitTablePathCreate(ctx) {
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
{
attrName: AttrName.comment,
endContextList: [CreateTableContext.name],
},
]);
}
exitViewPath(ctx) {
this.pushEntity(ctx, EntityContextType.VIEW);
}
exitViewPathCreate(ctx) {
this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [
{
attrName: AttrName.comment,
endContextList: [CreateViewContext.name],
},
]);
}
exitColumnNameCreate(ctx) {
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
{
attrName: AttrName.comment,
endContextList: [PhysicalColumnDefinitionContext.name],
},
{
attrName: AttrName.colType,
endContextList: [PhysicalColumnDefinitionContext.name],
},
]);
}
exitFunctionNameCreate(ctx) {
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
}
/** ===== Statement begin */
enterSqlStatement(ctx) {
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
}
exitSqlStatement(ctx) {
this.popStmt();
}
enterCreateCatalog(ctx) {
this.pushStmt(ctx, StmtContextType.CREATE_CATALOG_STMT);
}
exitCreateCatalog(ctx) {
this.popStmt();
}
enterCreateDatabase(ctx) {
this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT);
}
exitCreateDatabase(ctx) {
this.popStmt();
}
enterCreateTable(ctx) {
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
}
exitCreateTable(ctx) {
this.popStmt();
}
enterCreateView(ctx) {
this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT);
}
exitCreateView(ctx) {
this.popStmt();
}
enterQueryStatement(ctx) {
this.pushStmt(ctx, StmtContextType.SELECT_STMT);
}
exitQueryStatement(ctx) {
this.popStmt();
}
enterCreateFunction(ctx) {
this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT);
}
exitCreateFunction(ctx) {
this.popStmt();
}
enterInsertStatement(ctx) {
this.pushStmt(ctx, StmtContextType.INSERT_STMT);
}
exitInsertStatement(ctx) {
this.popStmt();
}
}