com.alibaba.fastsql.sql.ast.expr.SQLPropertyExpr Java Examples
The following examples show how to use
com.alibaba.fastsql.sql.ast.expr.SQLPropertyExpr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DruidDdlParser.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
private static void processName(DdlResult ddlResult, String schema, SQLExpr sqlName, boolean isOri) { if (sqlName == null) { if (StringUtils.isNotBlank(schema)) { ddlResult.setSchemaName(schema); } return; } String table = null; if (sqlName instanceof SQLPropertyExpr) { SQLIdentifierExpr owner = (SQLIdentifierExpr) ((SQLPropertyExpr) sqlName).getOwner(); schema = unescapeName(owner.getName()); table = unescapeName(((SQLPropertyExpr) sqlName).getName()); } else if (sqlName instanceof SQLIdentifierExpr) { table = unescapeName(((SQLIdentifierExpr) sqlName).getName()); } if (isOri) { ddlResult.setOriSchemaName(schema); ddlResult.setOriTableName(table); } else { ddlResult.setSchemaName(schema); ddlResult.setTableName(table); } }
Example #2
Source File: MysqlTableReplacer.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
@Override public boolean visit(SQLExprTableSource x) { String schemaName = x.getSchema(); String tableName = x.getTableName(); if (schemaName != null) { schemaName = SQLUtils.forcedNormalize(schemaName, DbType.mysql); } if (tableName != null) { tableName = SQLUtils.forcedNormalize(tableName, DbType.mysql); } if (schemaName == null) { schemaName = this.schemaName; } Objects.requireNonNull(tableName); SchemaInfo mappingTable = getMappingTable(schemaName, tableName); if (mappingTable!=null){ x.setExpr(new SQLPropertyExpr(mappingTable.getTargetSchema(), mappingTable.getTargetTable())); } return super.visit(x); }
Example #3
Source File: MemoryTableMeta.java From canal with Apache License 2.0 | 6 votes |
private String getSqlName(SQLExpr sqlName) { if (sqlName == null) { return null; } if (sqlName instanceof SQLPropertyExpr) { SQLIdentifierExpr owner = (SQLIdentifierExpr) ((SQLPropertyExpr) sqlName).getOwner(); return DruidDdlParser.unescapeName(owner.getName()) + "." + DruidDdlParser.unescapeName(((SQLPropertyExpr) sqlName).getName()); } else if (sqlName instanceof SQLIdentifierExpr) { return DruidDdlParser.unescapeName(((SQLIdentifierExpr) sqlName).getName()); } else if (sqlName instanceof SQLCharExpr) { return ((SQLCharExpr) sqlName).getText(); } else if (sqlName instanceof SQLMethodInvokeExpr) { return DruidDdlParser.unescapeName(((SQLMethodInvokeExpr) sqlName).getMethodName()); } else if (sqlName instanceof MySqlOrderingExpr) { return getSqlName(((MySqlOrderingExpr) sqlName).getExpr()); } else { return sqlName.toString(); } }
Example #4
Source File: DruidDdlParser.java From canal with Apache License 2.0 | 6 votes |
private static void processName(DdlResult ddlResult, String schema, SQLExpr sqlName, boolean isOri) { if (sqlName == null) { if (StringUtils.isNotBlank(schema)) { ddlResult.setSchemaName(schema); } return; } String table = null; if (sqlName instanceof SQLPropertyExpr) { SQLIdentifierExpr owner = (SQLIdentifierExpr) ((SQLPropertyExpr) sqlName).getOwner(); schema = unescapeName(owner.getName()); table = unescapeName(((SQLPropertyExpr) sqlName).getName()); } else if (sqlName instanceof SQLIdentifierExpr) { table = unescapeName(((SQLIdentifierExpr) sqlName).getName()); } if (isOri) { ddlResult.setOriSchemaName(schema); ddlResult.setOriTableName(table); } else { ddlResult.setSchemaName(schema); ddlResult.setTableName(table); } }
Example #5
Source File: Converters.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
public static SQLColumnDefinition getColumnDef(SQLExpr sqlExpr) { SQLColumnDefinition resolvedColumn = null; if (sqlExpr instanceof SQLIdentifierExpr) { resolvedColumn = ((SQLIdentifierExpr)sqlExpr).getResolvedColumn(); } else if (sqlExpr instanceof SQLPropertyExpr) { resolvedColumn = ((SQLPropertyExpr)sqlExpr).getResolvedColumn(); } else { return null; } return resolvedColumn; }
Example #6
Source File: ShowCreateTableSQLHandler.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@Override protected ExecuteCode onExecute(SQLRequest<SQLShowCreateTableStatement> request, MycatDataContext dataContext, Response response) { SQLShowCreateTableStatement ast = request.getAst(); SQLName nameExpr = ast.getName(); if (nameExpr == null) { response.sendError(new MycatException("table name is null")); return ExecuteCode.PERFORMED; } String schemaName = dataContext.getDefaultSchema(); String tableName; if (nameExpr instanceof SQLIdentifierExpr) { tableName = ((SQLIdentifierExpr) nameExpr).normalizedName(); }else if (nameExpr instanceof SQLPropertyExpr){ schemaName = ((SQLIdentifierExpr)((SQLPropertyExpr) nameExpr).getOwner()).normalizedName(); tableName = SQLUtils.normalize(((SQLPropertyExpr) nameExpr).getName()); }else { response.proxyShow(ast); return ExecuteCode.PERFORMED; } TableHandler table = MetadataManager.INSTANCE.getTable(schemaName, tableName); if (table == null){ response.proxyShow(ast); return ExecuteCode.PERFORMED; } String createTableSQL = table.getCreateTableSQL(); ResultSetBuilder resultSetBuilder = ResultSetBuilder.create(); resultSetBuilder.addColumnInfo("Table", JDBCType.VARCHAR); resultSetBuilder.addColumnInfo("Create Table", JDBCType.VARCHAR); resultSetBuilder.addObjectRowPayload(Arrays.asList(table.getTableName(),createTableSQL)); response.sendResultSet(()->resultSetBuilder.build(),()->{throw new UnsupportedOperationException();}); return ExecuteCode.PERFORMED; }
Example #7
Source File: PreProcesssor.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean visit(SQLIdentifierExpr x) { SQLTableSource peek = stack.peek(); if (peek != null) { SQLPropertyExpr propertyExpr = new SQLPropertyExpr(peek.computeAlias(), x.normalizedName()); replaceInParent(x, propertyExpr, x.getParent()); } return false; }
Example #8
Source File: PreProcesssor.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
@Override public void endVisit(SQLPropertyExpr x) { super.endVisit(x); }