Search in sources :

Example 76 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidPostgresqlSqlParserTest method testLimitToPgPage.

@Test
public void testLimitToPgPage() throws SQLNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    SchemaConfig schema = schemaMap.get("pgdb");
    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());
    sql = rrs.getNodes()[0].getStatement();
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(15, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals(0, rrs.getLimitStart());
    Assert.assertEquals(15, rrs.getLimitSize());
    sql = "select * from offer1 order by id desc limit 5,10";
    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());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 77 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidSqlServerSqlParserTest method testSqlServerPageSQL.

@Test
public void testSqlServerPageSQL() 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("sqlserverdb");
    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("sqlserver_1", rrs.getNodes()[0].getName());
    Assert.assertEquals("sqlserver_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("sqlserver_1", rrs.getNodes()[0].getName());
    sql = "select * from ( select row_number()over(order by tempColumn)tempRowNumber,* from ( select top \n" + "15 tempColumn=0, sid \n" + "from offer  where sts<>'N' and asf like '%'+'akka'+'%' order by sid  )t )tt where tempRowNumber>5";
    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("sqlserver_1", rrs.getNodes()[0].getName());
    Assert.assertEquals("sqlserver_2", rrs.getNodes()[1].getName());
    sql = "select * from ( select row_number()over(order by tempColumn)tempRowNumber,* from ( select top \n" + "15 tempColumn=0, sid \n" + "from offer1  where sts<>'N' and asf like '%'+'akka'+'%' order by sid  )t )tt where tempRowNumber>5";
    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("sqlserver_1", rrs.getNodes()[0].getName());
    sql = "SELECT TOP 10 sid  \n" + " FROM offer  where sts<>'N' and asf like '%'+'akka'+'%' \n" + " ORDER BY sid desc";
    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("sqlserver_1", rrs.getNodes()[0].getName());
    Assert.assertEquals("sqlserver_2", rrs.getNodes()[1].getName());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 78 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidSqlServerSqlParserTest method testTopPageSQL.

@Test
public void testTopPageSQL() throws SQLNonTransientException {
    SchemaConfig schema = schemaMap.get("sqlserverdb");
    RouteResultset rrs = null;
    String sql = "SELECT TOP 10  *  \n" + " FROM offer1  where sts<>'N' and asf like '%'+'akka'+'%' \n" + " ORDER BY sid desc";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, 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("sqlserver_1", rrs.getNodes()[0].getName());
    sql = "SELECT TOP 10  offer1.name,offer1.id  \n" + " FROM offer1  where sts<>'N' and asf like '%'+'akka'+'%' \n" + " ORDER BY sid desc";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, 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("sqlserver_1", rrs.getNodes()[0].getName());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 79 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

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)

Aggregations

SchemaConfig (io.mycat.config.model.SchemaConfig)79 SystemConfig (io.mycat.config.model.SystemConfig)54 RouteResultset (io.mycat.route.RouteResultset)34 Test (org.junit.Test)31 TableConfig (io.mycat.config.model.TableConfig)12 MycatConfig (io.mycat.config.MycatConfig)9 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 SQLNonTransientException (java.sql.SQLNonTransientException)7 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)6 RowDataPacket (io.mycat.net.mysql.RowDataPacket)6 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)5 CacheService (io.mycat.cache.CacheService)5 MycatCluster (io.mycat.config.MycatCluster)5 UserConfig (io.mycat.config.model.UserConfig)5 ArrayList (java.util.ArrayList)5 NoSuchElementException (java.util.NoSuchElementException)5 EOFPacket (io.mycat.net.mysql.EOFPacket)4 FieldPacket (io.mycat.net.mysql.FieldPacket)4 RouteService (io.mycat.route.RouteService)4