use of com.actiontech.dble.route.parser.druid.ServerSchemaStatVisitor in project dble by actiontech.
the class DQLRouteTest method test.
@Test
public void test() throws Exception {
String stmt = "select * from `offer` where id = 100";
SchemaConfig schema = schemaMap.get("mysqldb");
RouteResultset rrs = new RouteResultset(stmt, 7);
SQLStatementParser parser = null;
parser = new MySqlStatementParser(stmt);
SQLStatement statement;
ServerSchemaStatVisitor visitor = null;
try {
statement = parser.parseStatement();
visitor = new ServerSchemaStatVisitor();
} catch (Exception t) {
throw new SQLSyntaxErrorException(t);
}
ctx = new DruidShardingParseInfo();
List<RouteCalculateUnit> taskList = visitorParse(rrs, statement, visitor);
Assert.assertEquals(true, !taskList.get(0).getTablesAndConditions().isEmpty());
}
use of com.actiontech.dble.route.parser.druid.ServerSchemaStatVisitor in project dble by actiontech.
the class ServerSchemaStatVisitorTest method getConditionList.
private List<List<Condition>> getConditionList(String sql) {
SQLStatementParser parser = null;
parser = new MySqlStatementParser(sql);
ServerSchemaStatVisitor visitor = null;
SQLStatement statement = null;
// throw exception
try {
statement = parser.parseStatement();
visitor = new ServerSchemaStatVisitor();
} catch (Exception e) {
e.printStackTrace();
}
statement.accept(visitor);
List<List<Condition>> mergedConditionList = new ArrayList<List<Condition>>();
if (visitor.hasOrCondition()) {
// contains OR
mergedConditionList = visitor.splitConditions();
} else {
mergedConditionList.add(visitor.getConditions());
}
return mergedConditionList;
}
use of com.actiontech.dble.route.parser.druid.ServerSchemaStatVisitor in project dble by actiontech.
the class DefaultRouteStrategy method routeNormalSqlWithAST.
@Override
public RouteResultset routeNormalSqlWithAST(SchemaConfig schema, String originSql, RouteResultset rrs, LayerCachePool cachePool, ServerConnection sc) throws SQLException {
SQLStatement statement = parserSQL(originSql);
sc.getSession2().endParse();
DruidParser druidParser = DruidParserFactory.create(statement, rrs.getSqlType());
return RouterUtil.routeFromParser(druidParser, schema, rrs, statement, originSql, cachePool, new ServerSchemaStatVisitor(), sc);
}
use of com.actiontech.dble.route.parser.druid.ServerSchemaStatVisitor in project dble by actiontech.
the class MergeBuilder method constructByStatement.
public RouteResultset constructByStatement(String sql, SQLSelectStatement select) throws SQLException {
ServerSchemaStatVisitor visitor = new ServerSchemaStatVisitor();
DruidParser druidParser = new DruidSingleUnitSelectParser();
RouteResultset rrs = new RouteResultset(sql, ServerParse.SELECT);
LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
SchemaConfig schemaConfig = schemaConfigMap.get(node.getReferedTableNodes().get(0).getSchema());
return RouterUtil.routeFromParser(druidParser, schemaConfig, rrs, select, sql, pool, visitor, session.getSource());
}
Aggregations