UNPKG

dt-sql-parser

Version:

SQL Parsers for BigData, built with antlr4

111 lines (110 loc) 3.61 kB
import { AliasedRelationContext, ColumnDefinitionContext, CreateMaterializedViewContext, CreateTableAsSelectContext, CreateTableContext, CreateViewContext, } from '../../lib/trino/TrinoSqlParser'; import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector'; import { EntityContextType } from '../common/types'; export class TrinoEntityCollector extends EntityCollector { /** ====== Entity Begin */ exitCatalogRef(ctx) { this.pushEntity(ctx, EntityContextType.CATALOG); } exitCatalogNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.CATALOG_CREATE); } exitSchemaRef(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE); } exitSchemaNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE_CREATE); } exitTableRef(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: [AliasedRelationContext.name], }, ] : undefined); } exitTableNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateTableContext.name, CreateTableAsSelectContext.name], }, ]); } exitViewRef(ctx) { this.pushEntity(ctx, EntityContextType.VIEW); } exitViewNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateMaterializedViewContext.name, CreateViewContext.name], }, ]); } exitColumnNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [ { attrName: AttrName.colType, endContextList: [ColumnDefinitionContext.name], }, { attrName: AttrName.comment, endContextList: [ColumnDefinitionContext.name], }, ]); } /** ===== Statement begin */ enterSingleStatement(ctx) { this.pushStmt(ctx, StmtContextType.COMMON_STMT); } exitSingleStatement(ctx) { this.popStmt(); } enterCreateSchema(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT); } exitCreateSchema(ctx) { this.popStmt(); } enterCreateTableAsSelect(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreateTableAsSelect(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(); } enterCreateMaterializedView(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateMaterializedView(ctx) { this.popStmt(); } enterQueryStatement(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitQueryStatement(ctx) { this.popStmt(); } enterInsertInto(ctx) { this.pushStmt(ctx, StmtContextType.INSERT_STMT); } exitInsertInto(ctx) { this.popStmt(); } }