UNPKG

dt-sql-parser

Version:

SQL Parsers for BigData, built with antlr4

125 lines (124 loc) 4.09 kB
import { ColumnNameCommentContext, ColumnNameTypeConstraintContext, CreateDatabaseStatementContext, CreateTableStatementContext, CreateViewStatementContext, TableSourceContext, UniqueJoinSourceContext, } from '../../lib/hive/HiveSqlParser'; import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector'; import { EntityContextType } from '../common/types'; export class HiveEntityCollector extends EntityCollector { /** ====== Entity Begin */ exitTableNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateTableStatementContext.name], }, ]); } exitTableName(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: [TableSourceContext.name, UniqueJoinSourceContext.name], }, ] : undefined); } exitColumnNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [ { attrName: AttrName.comment, endContextList: [ColumnNameCommentContext.name], }, { attrName: AttrName.colType, endContextList: [ColumnNameTypeConstraintContext.name], }, ]); } exitViewNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateViewStatementContext.name], }, ]); } exitViewName(ctx) { this.pushEntity(ctx, EntityContextType.VIEW); } exitDbSchemaNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateDatabaseStatementContext.name], }, ]); } exitDbSchemaName(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE); } exitFunctionNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE); } /** ==== Statement begin */ enterStatement(ctx) { this.pushStmt(ctx, StmtContextType.COMMON_STMT); } exitStatement() { this.popStmt(); } enterCreateTableStatement(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreateTableStatement() { this.popStmt(); } enterSelectStatement(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitSelectStatement(ctx) { this.popStmt(); } enterFromSelectStmt(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitFromSelectStmt(ctx) { this.popStmt(); } enterCreateViewStatement(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateViewStatement(ctx) { this.popStmt(); } enterCreateMaterializedViewStatement(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateMaterializedViewStatement(ctx) { this.popStmt(); } enterInsertStmt(ctx) { this.pushStmt(ctx, StmtContextType.INSERT_STMT); } exitInsertStmt(ctx) { this.popStmt(); } enterFromInsertStmt(ctx) { this.pushStmt(ctx, StmtContextType.INSERT_STMT); } exitFromInsertStmt(ctx) { this.popStmt(); } enterCreateDatabaseStatement(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT); } exitCreateDatabaseStatement(ctx) { this.popStmt(); } enterFunctionNameCreate(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT); } exitCreateFunctionStatement(ctx) { this.popStmt(); } }