Search in sources :

Example 76 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.

the class DruidDb2SqlParserTest method testDb2PageSQL.

@Test
public void testDb2PageSQL() throws SQLNonTransientException {
    String sql = "SELECT *\n" + "FROM (SELECT sid, ROW_NUMBER() OVER (ORDER BY sid DESC) AS ROWNUM\n" + "\tFROM offer \n" + "\tWHERE sts <> 'N'\n" + "\t\t\t) XX\n" + "WHERE ROWNUM > 5\n" + "\tAND ROWNUM <= 15\n";
    SchemaConfig schema = schemaMap.get("db2db");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    Assert.assertEquals(5, rrs.getLimitStart());
    Assert.assertEquals(10, rrs.getLimitSize());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(15, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("db2_1", rrs.getNodes()[0].getName());
    Assert.assertEquals("db2_2", rrs.getNodes()[1].getName());
    sql = "SELECT *\n" + "FROM (SELECT sid, ROW_NUMBER() OVER (ORDER BY sid DESC) AS ROWNUM\n" + "\tFROM offer1 \n" + "\tWHERE sts <> 'N'\n" + "\t\t\t) XX\n" + "WHERE ROWNUM > 5\n" + "\tAND ROWNUM <= 15\n";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals(5, rrs.getLimitStart());
    Assert.assertEquals(10, rrs.getLimitSize());
    Assert.assertEquals(5, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(10, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals(sql, rrs.getNodes()[0].getStatement());
    Assert.assertEquals("db2_1", rrs.getNodes()[0].getName());
    sql = "SELECT sid\n" + "FROM offer  \n" + "ORDER BY sid desc\n" + "FETCH FIRST 10  ROWS ONLY";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    Assert.assertEquals(0, rrs.getLimitStart());
    Assert.assertEquals(10, rrs.getLimitSize());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(10, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals(sql, rrs.getNodes()[0].getStatement());
    Assert.assertEquals("db2_1", rrs.getNodes()[0].getName());
    Assert.assertEquals("db2_2", rrs.getNodes()[1].getName());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 77 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.

the class NoShardingSpace method testDefaultSpace.

public void testDefaultSpace() throws SQLNonTransientException {
    SchemaConfig schema = this.schema;
    String stmt = "insert into offer (member_id, gmt_create) values ('1','2001-09-13 20:20:33')";
    for (int i = 0; i < total; i++) {
        RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, stmt, null, null, cachePool);
    }
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig)

Example 78 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.

the class ShardingMultiTableSpace method testTableSpace.

/**
 * 路由到tableSpace的性能测试
 *
 * @throws SQLNonTransientException
 */
public void testTableSpace() throws SQLNonTransientException {
    SchemaConfig schema = getSchema();
    String sql = "select id,member_id,gmt_create from offer where member_id in ('1','22','333','1124','4525')";
    for (int i = 0; i < total; i++) {
        RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    }
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig)

Example 79 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.

the class TestSelectBetweenSqlParser method testBetweenSqlRoute.

@Test
public void testBetweenSqlRoute() throws SQLNonTransientException, IOException {
    String sql = "select * from offer_detail where offer_id between 1 and 33";
    SchemaConfig schema = schemaMap.get("cndb");
    RouteResultset rrs = RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(5, rrs.getNodes().length);
    sql = "select * from offer_detail where col_1 = 33 and offer_id between 1 and 33 and col_2 = 18";
    schema = schemaMap.get("cndb");
    rrs = RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(5, rrs.getNodes().length);
    // sql = "select b.* from offer_date b join  offer_detail a on a.id=b.id " +
    // "where b.col_date between '2014-02-02' and '2014-04-12' and col_1 = 3 and offer_id between 1 and 33";
    sql = "select b.* from offer_detail a  join  offer_date b on a.id=b.id " + "where b.col_date between '2014-02-02' and '2014-04-12' and col_1 = 3 and offer_id between 1 and 33";
    // sql = "select a.* from offer_detail a join offer_date b on a.id=b.id " +
    // "where b.col_date = '2014-04-02' and col_1 = 33 and offer_id =1";
    schema = schemaMap.get("cndb");
    // 两个路由规则不一样的表现在 走catlet. 不再取交集, catlet 测试时需要前端连接.这里注释掉.
    // rrs = RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(),schema, -1, sql, null,
    // null, cachePool);
    // Assert.assertEquals(2, rrs.getNodes().length);    //这里2个表都有条件路由,取的是交集,
    // 确认大于小于操作符
    sql = "select b.* from  offer_date b " + "where b.col_date > '2014-02-02'";
    // sql = "select a.* from offer_detail a join offer_date b on a.id=b.id " +
    // "where b.col_date = '2014-04-02' and col_1 = 33 and offer_id =1";
    schema = schemaMap.get("cndb");
    rrs = RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(128, rrs.getNodes().length);
    sql = "select * from offer_date where col_1 = 33 and col_date between '2014-01-02' and '2014-01-12'";
    schema = schemaMap.get("cndb");
    rrs = RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    sql = "select * from offer_date a where col_1 = 33 and a.col_date between '2014-01-02' and '2014-01-12'";
    schema = schemaMap.get("cndb");
    rrs = RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 80 with SystemConfig

use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.

the class PartitionByRangeDateHashTest method testRange.

@Test
public void testRange() throws SQLNonTransientException {
    String sql = "select * from offer1  where col_date between '2014-01-01 00:00:00'  and '2014-01-03 23:59:59'     order by id desc limit 100";
    SchemaConfig schema = schemaMap.get("TESTDB");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    junit.framework.Assert.assertEquals(6, rrs.getNodes().length);
    sql = "select * from offer1  where col_date between '2014-01-01 00:00:00'  and '2014-01-04 00:00:59'      order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    junit.framework.Assert.assertEquals(12, rrs.getNodes().length);
    sql = "select * from offer1  where col_date between '2014-01-04 00:00:00'  and '2014-01-06 23:59:59'      order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    junit.framework.Assert.assertEquals(6, rrs.getNodes().length);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Aggregations

SystemConfig (io.mycat.config.model.SystemConfig)120 SchemaConfig (io.mycat.config.model.SchemaConfig)110 RouteResultset (io.mycat.route.RouteResultset)64 Test (org.junit.Test)60 RouteResultsetNode (io.mycat.route.RouteResultsetNode)14 CacheService (io.mycat.cache.CacheService)10 SQLNonTransientException (java.sql.SQLNonTransientException)10 NoSuchElementException (java.util.NoSuchElementException)10 RouteService (io.mycat.route.RouteService)8 ArrayList (java.util.ArrayList)8 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)6 TableConfig (io.mycat.config.model.TableConfig)6 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 DirectByteBufferPool (io.mycat.buffer.DirectByteBufferPool)2 NettyBufferPool (io.mycat.buffer.NettyBufferPool)2 MycatConfig (io.mycat.config.MycatConfig)2 ManagerConnectionFactory (io.mycat.manager.ManagerConnectionFactory)2 MyCatMemory (io.mycat.memory.MyCatMemory)2 AIOAcceptor (io.mycat.net.AIOAcceptor)2