Search in sources :

Example 81 with SystemConfig

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

the class DruidOracleSqlParserTest method testLimitToOraclePage.

@Test
public void testLimitToOraclePage() throws SQLNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    SchemaConfig schema = schemaMap.get("oracledb");
    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("d_oracle1", rrs.getNodes()[0].getName());
    Assert.assertEquals("d_oracle2", rrs.getNodes()[1].getName());
    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());
    Assert.assertEquals("d_oracle1", rrs.getNodes()[0].getName());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 82 with SystemConfig

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

the class DruidOracleSqlParserTest method testInsertUpdate.

@Test
public void testInsertUpdate() throws Exception {
    SchemaConfig schema = schemaMap.get("oracledb");
    String sql = "insert into offer1(group_id,offer_id,member_id)values(234,123,'abc')";
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals(-1, rrs.getLimitSize());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(-1, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("d_oracle1", rrs.getNodes()[0].getName());
    Assert.assertEquals("insert into offer1(group_id,offer_id,member_id)values(234,123,'abc')", rrs.getNodes()[0].getStatement());
    sql = "update offer set name='x'";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    Assert.assertEquals(-1, rrs.getLimitSize());
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(-1, rrs.getNodes()[0].getLimitSize());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 83 with SystemConfig

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

the class DruidOracleSqlParserTest method testOraclePageSQL.

@Test
public void testOraclePageSQL() throws SQLNonTransientException {
    String sql = "SELECT *\n" + "FROM (SELECT XX.*, ROWNUM AS RN \n" + " FROM (\n" + "SELECT *   FROM offer\n" + "                ) XX\n" + "        WHERE ROWNUM <= 15\n" + "        ) XXX\n" + "WHERE RN > 5 \n";
    SchemaConfig schema = schemaMap.get("oracledb");
    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("d_oracle1", rrs.getNodes()[0].getName());
    Assert.assertEquals("d_oracle2", rrs.getNodes()[1].getName());
    sql = "SELECT *\n" + "FROM (SELECT XX.*, ROWNUM AS RN \n" + " FROM (\n" + "SELECT *   FROM offer1" + "                ) XX\n" + "        WHERE ROWNUM <= 15\n" + "        ) XXX\n" + "WHERE RN > 5 \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("d_oracle1", rrs.getNodes()[0].getName());
    sql = "SELECT *\n" + "FROM (SELECT t.*, ROW_NUMBER() OVER (ORDER BY sid DESC) AS ROWNUM1\n" + "\tFROM offer t\n" + "\tWHERE sts <> 'N'\n" + "\t\t\n" + "\t) XX\n" + "WHERE ROWNUM1 > 5\n" + "\tAND ROWNUM1 <= 15\n";
    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("d_oracle1", rrs.getNodes()[0].getName());
    Assert.assertEquals("d_oracle2", rrs.getNodes()[1].getName());
    sql = "SELECT *\n" + "FROM (SELECT t.*, ROW_NUMBER() OVER (ORDER BY sid DESC) AS ROWNUM1\n" + "\tFROM offer1  t\n" + "\tWHERE sts <> 'N'\n" + "\t\t\n" + "\t) XX\n" + "WHERE ROWNUM1 > 5\n" + "\tAND ROWNUM1 <= 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("d_oracle1", rrs.getNodes()[0].getName());
    sql = "select sid from (select sid from offer ) where rownum<=10";
    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("d_oracle1", rrs.getNodes()[0].getName());
    Assert.assertEquals("d_oracle2", rrs.getNodes()[1].getName());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 84 with SystemConfig

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

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 85 with SystemConfig

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

the class DruidSqlServerSqlParserTest method testLimitToSqlServerPage.

@Test
public void testLimitToSqlServerPage() throws SQLNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    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 = 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());
    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)

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