use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project Mycat-Server by MyCATApache.
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 dble by actiontech.
the class DruidDeleteParser method visitorParse.
@Override
public SchemaConfig visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt, ServerSchemaStatVisitor visitor, ServerConnection sc) throws SQLException {
String schemaName = schema == null ? null : schema.getName();
MySqlDeleteStatement delete = (MySqlDeleteStatement) stmt;
SQLTableSource tableSource = delete.getTableSource();
SQLTableSource fromSource = delete.getFrom();
if (fromSource != null) {
tableSource = fromSource;
}
if (tableSource instanceof SQLJoinTableSource) {
StringPtr sqlSchema = new StringPtr(null);
if (!SchemaUtil.isNoSharding(sc, (SQLJoinTableSource) tableSource, stmt, schemaName, sqlSchema)) {
String msg = "DELETE query with multiple tables is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
} else {
if (delete.getWhere() != null && !SchemaUtil.isNoSharding(sc, delete.getWhere(), schemaName, sqlSchema)) {
String msg = "DELETE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
String realSchema = sqlSchema.get() == null ? schemaName : sqlSchema.get();
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(realSchema);
rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), realSchema));
RouterUtil.routeToSingleNode(rrs, schemaConfig.getDataNode());
rrs.setFinishedRoute(true);
return schema;
}
} else {
SQLExprTableSource deleteTableSource = (SQLExprTableSource) tableSource;
SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(sc.getUser(), schemaName, deleteTableSource);
if (!ServerPrivileges.checkPrivilege(sc, schemaInfo.getSchema(), schemaInfo.getTable(), CheckType.DELETE)) {
String msg = "The statement DML privilege check is not passed, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
schema = schemaInfo.getSchemaConfig();
rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), schemaInfo.getSchema()));
if (RouterUtil.isNoSharding(schema, schemaInfo.getTable())) {
if (delete.getWhere() != null && !SchemaUtil.isNoSharding(sc, delete.getWhere(), schemaName, new StringPtr(schemaInfo.getSchema()))) {
String msg = "DELETE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
RouterUtil.routeToSingleNode(rrs, schema.getDataNode());
return schema;
}
super.visitorParse(schema, rrs, stmt, visitor, sc);
if (visitor.isHasSubQuery()) {
String msg = "DELETE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
TableConfig tc = schema.getTables().get(schemaInfo.getTable());
if (tc != null && tc.isGlobalTable()) {
RouterUtil.routeToMultiNode(false, rrs, tc.getDataNodes(), tc.isGlobalTable());
rrs.setFinishedRoute(true);
return schema;
}
}
return schema;
}
use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project druid by alibaba.
the class Issue2876 method test_0.
public void test_0() throws Exception {
String sql = "SELECT CONCAT(\"'\",b.PRIMARY_ID,\"'\") \n" + "FROM s_user_session_attributes a \n" + "LEFT JOIN s_user_session b ON a.SESSION_PRIMARY_ID=b.PRIMARY_ID \n" + "WHERE a.ATTRIBUTE_NAME='KAPTCHA_SESSION_KEY' AND b.LAST_ACCESS_TIME <= 1540429945459";
System.out.println(sql);
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());
}
use of com.alibaba.druid.sql.ast.statement.SQLJoinTableSource in project druid by alibaba.
the class MySqlSelectTest_178 method test_0.
public void test_0() throws Exception {
String sql = "select rt_dws_csn_sta_lgt_ord_ri.metrics_id as yujiu from rt_dws_csn_sta_lgt_ord_ri CROSS JOIN rt_dws_csn_sta_lgt_ord_mi ;";
//
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL, SQLParserFeature.EnableSQLBinaryOpExprGroup, SQLParserFeature.OptimizedForParameterized);
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
assertEquals(1, statementList.size());
assertEquals("SELECT rt_dws_csn_sta_lgt_ord_ri.metrics_id AS yujiu\n" + "FROM rt_dws_csn_sta_lgt_ord_ri\n" + "\tCROSS JOIN rt_dws_csn_sta_lgt_ord_mi;", stmt.toString());
assertEquals("select rt_dws_csn_sta_lgt_ord_ri.metrics_id as yujiu\n" + "from rt_dws_csn_sta_lgt_ord_ri\n" + "\tcross join rt_dws_csn_sta_lgt_ord_mi;", stmt.toLowerCaseString());
assertEquals("SELECT rt_dws_csn_sta_lgt_ord_ri.metrics_id AS yujiu\n" + "FROM rt_dws_csn_sta_lgt_ord_ri\n" + "\tCROSS JOIN rt_dws_csn_sta_lgt_ord_mi;", stmt.toParameterizedString());
SQLJoinTableSource join = (SQLJoinTableSource) stmt.getSelect().getQueryBlock().getFrom();
assertEquals(SQLJoinTableSource.JoinType.CROSS_JOIN, join.getJoinType());
assertNull(join.getLeft().getAlias());
}
Aggregations