use of com.alibaba.cobar.parser.ast.stmt.SQLStatement in project cobar by alibaba.
the class ServerRouteTest method testRouteInsertLong.
public void testRouteInsertLong() throws Exception {
StringBuilder sb = new StringBuilder("insert into offer_detail (offer_id, gmt) values ");
for (int i = 0; i < 1024; ++i) {
if (i > 0)
sb.append(", ");
sb.append("(" + i + ", now())");
}
SchemaConfig schema = schemaMap.get("cndb");
RouteResultset rrs = ServerRouter.route(schema, sb.toString(), null, null);
Assert.assertEquals(-1l, rrs.getLimitSize());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 128);
IndexedNodeNameAsserter nameAsserter = new IndexedNodeNameAsserter("detail_dn", 0, 128);
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
RouteNodeAsserter asserter = new RouteNodeAsserter(nameAsserter, new ParseredSQLAsserter() {
@Override
protected void assertAST(SQLStatement stmt, int nodeIndex) {
DMLInsertStatement insert = (DMLInsertStatement) stmt;
List<RowExpression> rows = insert.getRowList();
Assert.assertNotNull(rows);
Assert.assertEquals(8, rows.size());
List<Integer> vals = new ArrayList<Integer>(8);
for (RowExpression row : rows) {
int val = ((Number) row.getRowExprList().get(0).evaluation(null)).intValue();
vals.add(val);
}
Assert.assertEquals(8, vals.size());
for (int i = 8 * nodeIndex; i < 8 * nodeIndex + 8; ++i) {
Assert.assertTrue(vals.contains(i));
}
}
});
for (RouteResultsetNode node : nodeMap.values()) {
asserter.assertNode(node);
}
}
use of com.alibaba.cobar.parser.ast.stmt.SQLStatement in project cobar by alibaba.
the class MySQLDALParserTest method testdesc.
public void testdesc() throws Exception {
String sql = "desc tb1";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDALParser parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
SQLStatement desc = (DescTableStatement) parser.desc();
parser.match(MySQLToken.EOF);
String output = output2MySQL(desc, sql);
Assert.assertEquals("DESC tb1", output);
sql = "desc db.tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
desc = (DescTableStatement) parser.desc();
parser.match(MySQLToken.EOF);
output = output2MySQL(desc, sql);
Assert.assertEquals("DESC db.tb1", output);
sql = "describe db.tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
desc = (DescTableStatement) parser.desc();
parser.match(MySQLToken.EOF);
output = output2MySQL(desc, sql);
Assert.assertEquals("DESC db.tb1", output);
}
Aggregations