use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project Mycat_plus by coderczp.
the class JoinParser method parserTable.
private void parserTable(SQLTableSource table, TableFilter tFilter, boolean isOutJoin) {
if (table instanceof SQLJoinTableSource) {
SQLJoinTableSource table1 = (SQLJoinTableSource) table;
joinType = table1.getJoinType().toString();
if ((table1.getJoinType() == JoinType.COMMA) || (table1.getJoinType() == JoinType.JOIN) || (table1.getJoinType() == JoinType.INNER_JOIN) || (table1.getJoinType() == JoinType.LEFT_OUTER_JOIN)) {
tFilter = setTableFilter(tFilter, getTableFilter(table1.getLeft(), isOutJoin));
if (tableFilter == null) {
tableFilter = tFilter;
}
}
// parserTable(table1.getLeft()); //SQLExprTableSource
parserTable(table1.getRight(), tFilter, true);
// SQLBinaryOpExpr
SQLExpr expr = table1.getCondition();
parserJoinKey(expr);
} else {
tFilter = setTableFilter(tFilter, getTableFilter(table, isOutJoin));
LOGGER.info("table " + table.toString() + " Alias:" + table.getAlias() + " Hints:" + table.getHints());
}
}
use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project druid by alibaba.
the class SQLTransformUtils method transformOracleToPostgresql.
public static SQLTableSource transformOracleToPostgresql(SQLTableSource x) {
if (x instanceof OracleSelectTableReference) {
OracleSelectTableReference xx = (OracleSelectTableReference) x;
SQLExprTableSource y = new SQLExprTableSource();
xx.cloneTo(y);
y.setParent(x.getParent());
return y;
}
if (x instanceof OracleSelectJoin) {
OracleSelectJoin xx = (OracleSelectJoin) x;
SQLJoinTableSource y = new SQLJoinTableSource();
xx.cloneTo(y);
y.setLeft(transformOracleToPostgresql(y.getLeft()));
y.setRight(transformOracleToPostgresql(y.getRight()));
y.setParent(x.getParent());
return y;
}
if (x instanceof OracleSelectSubqueryTableSource) {
OracleSelectSubqueryTableSource xx = (OracleSelectSubqueryTableSource) x;
SQLSubqueryTableSource y = new SQLSubqueryTableSource();
xx.cloneTo(y);
y.setParent(x.getParent());
return y;
}
if (x instanceof OracleWithSubqueryEntry) {
SQLWithSubqueryClause.Entry entry = new SQLWithSubqueryClause.Entry();
((OracleWithSubqueryEntry) x).cloneTo(entry);
entry.setParent(x.getParent());
return entry;
}
return x;
}
use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project druid by alibaba.
the class SQLJoinTest method test_0.
public void test_0() throws Exception {
SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements("select a.* from t_user a inner join t_group b on a.gid = b.id", JdbcConstants.ORACLE).get(0);
SQLSelectQueryBlock queryBlock = stmt.getSelect().getQueryBlock();
assertNotNull(queryBlock);
SQLJoinTableSource join = (SQLJoinTableSource) queryBlock.getFrom();
assertTrue(join.match("a", "b"));
}
use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project canal by alibaba.
the class SqlParser method visitSelectTable.
/**
* 解析表
*
* @param schemaItem 视图对象
* @param sqlTableSource sqlTableSource
* @param tableItems 表对象列表
* @param tableItemTmp 表对象(临时)
*/
private static void visitSelectTable(SchemaItem schemaItem, SQLTableSource sqlTableSource, List<TableItem> tableItems, TableItem tableItemTmp) {
if (sqlTableSource instanceof SQLExprTableSource) {
SQLExprTableSource sqlExprTableSource = (SQLExprTableSource) sqlTableSource;
TableItem tableItem;
if (tableItemTmp != null) {
tableItem = tableItemTmp;
} else {
tableItem = new TableItem(schemaItem);
}
tableItem.setSchema(sqlExprTableSource.getSchema());
tableItem.setTableName(sqlExprTableSource.getTableName());
if (tableItem.getAlias() == null) {
tableItem.setAlias(sqlExprTableSource.getAlias());
}
if (tableItems.isEmpty()) {
// 第一张表为主表
tableItem.setMain(true);
}
tableItems.add(tableItem);
} else if (sqlTableSource instanceof SQLJoinTableSource) {
SQLJoinTableSource sqlJoinTableSource = (SQLJoinTableSource) sqlTableSource;
SQLTableSource leftTableSource = sqlJoinTableSource.getLeft();
visitSelectTable(schemaItem, leftTableSource, tableItems, null);
SQLTableSource rightTableSource = sqlJoinTableSource.getRight();
TableItem rightTableItem = new TableItem(schemaItem);
// 解析on条件字段
visitOnCondition(sqlJoinTableSource.getCondition(), rightTableItem);
visitSelectTable(schemaItem, rightTableSource, tableItems, rightTableItem);
} else if (sqlTableSource instanceof SQLSubqueryTableSource) {
SQLSubqueryTableSource subQueryTableSource = (SQLSubqueryTableSource) sqlTableSource;
MySqlSelectQueryBlock sqlSelectQuery = (MySqlSelectQueryBlock) subQueryTableSource.getSelect().getQuery();
TableItem tableItem;
if (tableItemTmp != null) {
tableItem = tableItemTmp;
} else {
tableItem = new TableItem(schemaItem);
}
tableItem.setAlias(subQueryTableSource.getAlias());
tableItem.setSubQuerySql(SQLUtils.toMySqlString(sqlSelectQuery));
tableItem.setSubQuery(true);
tableItem.setSubQueryFields(collectSelectQueryFields(sqlSelectQuery));
visitSelectTable(schemaItem, sqlSelectQuery.getFrom(), tableItems, tableItem);
}
}
use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project druid by alibaba.
the class Issue2049 method test_0.
public void test_0() throws Exception {
String sql = "select * from emp a,dmp b;";
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
SQLSelectStatement stmt = (SQLSelectStatement) stmtList.get(0);
SQLSelectQueryBlock queryBlock = stmt.getSelect().getQueryBlock();
SQLJoinTableSource joinTableSource = (SQLJoinTableSource) queryBlock.getFrom();
assertEquals("a", joinTableSource.getLeft().getAlias());
assertEquals("b", joinTableSource.getRight().getAlias());
}
Aggregations