UNPKG

dt-sql-parser

Version:

SQL Parsers for BigData, built with antlr4

136 lines (135 loc) 4.41 kB
import { ColumnDefinitionContext, CreateKuduTableAsSelectContext, CreateSchemaContext, CreateTableSelectContext, CreateViewContext, KuduTableElementContext, SampledRelationContext, ViewColumnItemContext, } from '../../lib/impala/ImpalaSqlParser'; import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector'; import { EntityContextType } from '../common/types'; export class ImpalaEntityCollector extends EntityCollector { /** ===== Entity begin */ exitTableNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [ { attrName: AttrName.comment, endContextList: [ CreateTableSelectContext.name, CreateKuduTableAsSelectContext.name, ], }, ]); } exitTableNamePath(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: [SampledRelationContext.name], }, ] : undefined); } exitColumnNamePathCreate(ctx) { this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [ { attrName: AttrName.comment, endContextList: [ ColumnDefinitionContext.name, KuduTableElementContext.name, ViewColumnItemContext.name, ], }, { attrName: AttrName.colType, endContextList: [ ColumnDefinitionContext.name, KuduTableElementContext.name, ViewColumnItemContext.name, ], }, ]); } exitViewNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateViewContext.name], }, ]); } exitViewNamePath(ctx) { this.pushEntity(ctx, EntityContextType.VIEW); } exitDatabaseNamePath(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE); } exitDatabaseNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateSchemaContext.name], }, ]); } exitFunctionNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE); } /** ===== Statement begin */ enterSingleStatement(ctx) { this.pushStmt(ctx, StmtContextType.COMMON_STMT); } exitSingleStatement(ctx) { this.popStmt(); } enterCreateTableLike(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreateTableLike(ctx) { this.popStmt(); } enterCreateTableSelect(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreateTableSelect(ctx) { this.popStmt(); } enterCreateKuduTableAsSelect(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreateKuduTableAsSelect(ctx) { this.popStmt(); } enterQueryStatement(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitQueryStatement(ctx) { this.popStmt(); } enterCreateView(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateView(ctx) { this.popStmt(); } enterInsertStatement(ctx) { this.pushStmt(ctx, StmtContextType.INSERT_STMT); } exitInsertStatement(ctx) { this.popStmt(); } enterCreateSchema(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT); } exitCreateSchema(ctx) { this.popStmt(); } enterCreateAggregateFunction(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT); } exitCreateAggregateFunction(ctx) { this.popStmt(); } enterCreateFunction(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT); } exitCreateFunction(ctx) { this.popStmt(); } }