use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlHavingTest method testHaving.
@Test
public void testHaving() throws SQLNonTransientException {
String sql = "select avg(offer_id) avgofferid, member_id from offer_detail group by member_id having avgofferid > 100";
SchemaConfig schema = schemaMap.get("cndb");
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(3, rrs.getSqlMerge().getHavingColsName().length);
sql = "select avg(offer_id) avgofferid, member_id from offer_detail group by member_id having avg(offer_id) > 100";
rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(3, rrs.getSqlMerge().getHavingColsName().length);
sql = "select count(offer_id) countofferid, member_id from offer_detail group by member_id having countofferid > 100";
rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(3, rrs.getSqlMerge().getHavingColsName().length);
sql = "select count(offer_id) countofferid, member_id from offer_detail group by member_id having count(offer_id) > 100";
rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(3, rrs.getSqlMerge().getHavingColsName().length);
}
use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlSqlParserTest method testLimitPage.
@Test
public void testLimitPage() throws SQLNonTransientException {
String sql = "select * from offer order by id desc limit 5,10";
SchemaConfig schema = schemaMap.get("mysqldb");
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("dn1", rrs.getNodes()[0].getName());
Assert.assertEquals("dn2", 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("dn1", rrs.getNodes()[0].getName());
sql = "select * from offer1 order by id desc limit 10";
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("dn1", rrs.getNodes()[0].getName());
}
use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.
the class DruidPostgresqlSqlParserTest method testPGPageSQL.
@Test
public void testPGPageSQL() throws SQLNonTransientException {
String sql = "select sid from offer order by sid limit 10 offset 5";
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 = "select sid from offer1 order by sid limit 10 offset 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("SELECT sid\n" + "FROM offer1\n" + "ORDER BY sid\n" + "LIMIT 10 OFFSET 5", rrs.getNodes()[0].getStatement());
}
use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.
the class HintDBTypeTest method testHint.
/**
* 测试注解
*
* @throws Exception
*/
@Test
public void testHint() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
// 使用注解(新注解,/*!mycat*/),runOnSlave=false 强制走主节点
String sql = "/*!mycat:db_type=master*/select * from employee where sharding_id=1";
CacheService cacheService = new CacheService();
RouteService routerService = new RouteService(cacheService);
RouteResultset rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
Assert.assertTrue(!rrs.getRunOnSlave());
// 使用注解(新注解,/*#mycat*/),runOnSlave=false 强制走主节点
sql = "/*#mycat:db_type=master*/select * from employee where sharding_id=1";
rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
Assert.assertTrue(!rrs.getRunOnSlave());
// 使用注解(新注解,/*mycat*/),runOnSlave=false 强制走主节点
sql = "/*mycat:db_type=master*/select * from employee where sharding_id=1";
rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
Assert.assertTrue(!rrs.getRunOnSlave());
// 不使用注解,runOnSlave=null, 根据读写分离策略走主从库
sql = "select * from employee where sharding_id=1";
rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
Assert.assertTrue(rrs.getRunOnSlave() == null);
}
use of io.mycat.config.model.SystemConfig in project Mycat-Server by MyCATApache.
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);
}
Aggregations