Search in sources :

Example 41 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class DDLRouteTest method testSpecialCharDDL.

@Test
public void testSpecialCharDDL() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    CacheService cacheService = new CacheService(false);
    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 = "COMPANY";
    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(schema, sqlType, sql, null);
    Assert.assertTrue("COMPANY".equals(tablename));
    Assert.assertTrue(rrs.getNodes().length == nodeSize);
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) ArrayList(java.util.ArrayList) TableConfig(com.actiontech.dble.config.model.TableConfig) CacheService(com.actiontech.dble.cache.CacheService) Test(org.junit.Test)

Example 42 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class DruidMysqlCreateTableTest method testInsert.

// @Test
public void testInsert() throws SQLException {
    SchemaConfig schema = schemaMap.get("mysqldb");
    RouteResultset rrs = routeStrategy.route(schema, -1, "insert into autoslot (id,sid) values(1,2) ", sc, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    // Assert.assertTrue(isInsertHasSlot(rrs.getStatement()));
    Assert.assertFalse(isInsertHasSlot(rrs.getStatement()));
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig)

Example 43 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class DruidMysqlCreateTableTest method testCreate.

@Test
public void testCreate() throws SQLException {
    SchemaConfig schema = schemaMap.get("mysqldb");
    RouteResultset rrs = routeStrategy.route(schema, -1, originSql1, sc, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    String sql = rrs.getNodes()[0].getStatement();
    // Assert.assertTrue(parseSql(sql));
    Assert.assertFalse(parseSql(sql));
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Test(org.junit.Test)

Example 44 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class DruidMysqlRouteStrategyTest method testMultiLevelOr.

/**
 * testMultiLevelOr
 *
 * @throws Exception
 */
@Test
public void testMultiLevelOr() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    String sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan'";
    RouteResultset rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 1);
    sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan' or id = 2000001";
    rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 2);
    sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan' or id = 2000001 or id = 4000001";
    rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 3);
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Test(org.junit.Test)

Example 45 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class DruidMysqlRouteStrategyTest method testDuplicatePartitionKey.

public void testDuplicatePartitionKey() throws Exception {
    String sql = null;
    SchemaConfig schema = schemaMap.get("cndb");
    RouteResultset rrs = null;
    sql = "select * from cndb.offer where (offer_id, group_id ) In (123,234)";
    schema = schemaMap.get("cndb");
    rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    Assert.assertEquals(-1L, rrs.getLimitSize());
    Assert.assertEquals(128, rrs.getNodes().length);
    for (int i = 0; i < 128; i++) {
        Assert.assertEquals("select * from offer where (offer_id, group_id ) In (123,234)", rrs.getNodes()[i].getStatement());
    }
    sql = "SELECT * FROM offer WHERE FALSE OR offer_id = 123 AND member_id = 123 OR member_id = 123 AND member_id = 234 OR member_id = 123 AND member_id = 345 OR member_id = 123 AND member_id = 456 OR offer_id = 234 AND group_id = 123 OR offer_id = 234 AND group_id = 234 OR offer_id = 234 AND group_id = 345 OR offer_id = 234 AND group_id = 456 OR offer_id = 345 AND group_id = 123 OR offer_id = 345 AND group_id = 234 OR offer_id = 345 AND group_id = 345 OR offer_id = 345 AND group_id = 456 OR offer_id = 456 AND group_id = 123 OR offer_id = 456 AND group_id = 234 OR offer_id = 456 AND group_id = 345 OR offer_id = 456 AND group_id = 456";
    schema = schemaMap.get("cndb");
    rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    getNodeMap(rrs, 128);
    sql = "select * from  offer where false" + " or offer_id=123 and group_id=123" + " or group_id=123 and offer_id=234" + " or offer_id=123 and group_id=345" + " or offer_id=123 and group_id=456  ";
    schema = schemaMap.get("cndb");
    rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    Assert.assertEquals(-1L, rrs.getLimitSize());
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig)

Aggregations

SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)70 TableConfig (com.actiontech.dble.config.model.TableConfig)16 SQLNonTransientException (java.sql.SQLNonTransientException)16 Test (org.junit.Test)15 RouteResultset (com.actiontech.dble.route.RouteResultset)6 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)5 ServerConfig (com.actiontech.dble.config.ServerConfig)5 UserConfig (com.actiontech.dble.config.model.UserConfig)5 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)5 CacheService (com.actiontech.dble.cache.CacheService)4 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)4 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 StringPtr (com.actiontech.dble.plan.common.ptr.StringPtr)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)3 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3