Search in sources :

Example 11 with RowExpression

use of com.alibaba.cobar.parser.ast.expression.primary.RowExpression 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);
    }
}
Also used : SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) SQLStatement(com.alibaba.cobar.parser.ast.stmt.SQLStatement) DMLInsertStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLInsertStatement) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)11 Expression (com.alibaba.cobar.parser.ast.expression.Expression)9 QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)8 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)6 Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)6 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)5 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)5 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)5 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)5 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)5 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)5 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)5 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)5 LikeExpression (com.alibaba.cobar.parser.ast.expression.string.LikeExpression)5 CollateExpression (com.alibaba.cobar.parser.ast.expression.type.CollateExpression)5 Pair (com.alibaba.cobar.parser.util.Pair)4 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)3 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)3 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)3 ArithmeticAddExpression (com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression)3