use of io.mycat.config.model.SchemaConfig 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.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlRouteStrategyTest method testGroupLimit.
public void testGroupLimit() throws Exception {
final SchemaConfig schema = schemaMap.get("cndb");
String sql = null;
RouteResultset rrs = null;
sql = "select count(*) from (select * from(select * from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
// Assert.assertEquals(88L, rrs.getLimitSize());
// Assert.assertEquals(RouteResultset.SUM_FLAG, rrs.getFlag());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 2);
NodeNameAsserter nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select count(*) from (select * from(select max(id) from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select * from (select * from(select max(id) from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select * from (select count(*) from(select * from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
// Assert.assertEquals(88L, rrs.getLimitSize());
// Assert.assertEquals(RouteResultset.SUM_FLAG, rrs.getFlag());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DDLRouteTest method testSpecialCharDDL.
@Test
public void testSpecialCharDDL() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
CacheService cacheService = new CacheService();
RouteService routerService = new RouteService(cacheService);
// alter table test
String sql = " ALTER TABLE COMPANY\r\nADD COLUMN TEST VARCHAR(255) NULL AFTER CREATE_DATE,\r\n CHARACTER SET = UTF8";
sql = RouterUtil.getFixedSql(sql);
List<String> dataNodes = new ArrayList<>();
String tablename = RouterUtil.getTableName(sql, RouterUtil.getAlterTablePos(sql, 0));
Map<String, TableConfig> tables = schema.getTables();
TableConfig tc;
if (tables != null && (tc = tables.get(tablename)) != null) {
dataNodes = tc.getDataNodes();
}
int nodeSize = dataNodes.size();
int rs = ServerParse.parse(sql);
int sqlType = rs & 0xff;
RouteResultset rrs = routerService.route(new SystemConfig(), schema, sqlType, sql, "UTF-8", null);
Assert.assertTrue("COMPANY".equals(tablename));
Assert.assertTrue(rrs.getNodes().length == nodeSize);
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DDLRouteTest method testTableMetaRead.
@Test
public void testTableMetaRead() throws Exception {
final SchemaConfig schema = schemaMap.get("cndb");
String sql = "desc offer";
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.DESCRIBE, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("desc offer", rrs.getNodes()[0].getStatement());
sql = " desc cndb.offer";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.DESCRIBE, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("desc offer", rrs.getNodes()[0].getStatement());
sql = " desc cndb.offer col1";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.DESCRIBE, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("desc offer col1", rrs.getNodes()[0].getStatement());
sql = "SHOW FULL COLUMNS FROM offer IN db_name WHERE true";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW FULL COLUMNS FROM offer WHERE true", rrs.getNodes()[0].getStatement());
sql = "SHOW FULL COLUMNS FROM db.offer IN db_name WHERE true";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW FULL COLUMNS FROM offer WHERE true", rrs.getNodes()[0].getStatement());
sql = "SHOW FULL TABLES FROM `TESTDB` WHERE Table_type != 'VIEW'";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals("SHOW FULL TABLES WHERE Table_type != 'VIEW'", rrs.getNodes()[0].getStatement());
sql = "SHOW INDEX IN offer FROM db_name";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW INDEX FROM offer", rrs.getNodes()[0].getStatement());
}
use of io.mycat.config.model.SchemaConfig 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