本文整理汇总了Java中com.taobao.tddl.optimizer.parse.hint.SimpleHintParser类的典型用法代码示例。如果您正苦于以下问题:Java SimpleHintParser类的具体用法?Java SimpleHintParser怎么用?Java SimpleHintParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleHintParser类属于com.taobao.tddl.optimizer.parse.hint包,在下文中一共展示了SimpleHintParser类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParser
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testParser() {
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("relation", "and");
map1.put("paramtype", "int");
List<String> exprs = new ArrayList<String>();
exprs.add("pk>4");
exprs.add("pk<10");
map1.put("expr", JSON.toJSON(exprs));
List<Object> paramsO = new ArrayList<Object>();
paramsO.add(JSON.toJSON(map1));
Map<String, Object> hintmap = new HashMap<String, Object>();
hintmap.put("params", JSON.toJSON(paramsO));
hintmap.put("type", "condition");
hintmap.put("vtab", "vtabxxx");
String text = JSON.toJSONString(hintmap);
System.out.println(text);
RouteCondition route = SimpleHintParser.convertHint2RouteCondition("/*+TDDL(" + text + ")*/", null);
System.out.println(route);
}
示例2: optimizeAndAssignment
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Override
public IDataNodeExecutor optimizeAndAssignment(String sql, Map<Integer, ParameterContext> parameterSettings,
Map<String, Object> extraCmd, boolean cached) throws QueryException,
SqlParserException {
// 处理sql hint
RouteCondition routeCondition = SimpleHintParser.convertHint2RouteCondition(sql, parameterSettings);
if (routeCondition != null && !routeCondition.getExtraCmds().isEmpty()) {
// 合并sql中的extra cmd参数
if (extraCmd == null) {
extraCmd = new HashMap<String, Object>();
}
extraCmd.putAll(routeCondition.getExtraCmds());
}
if (routeCondition != null
&& (routeCondition instanceof DirectlyRouteCondition || routeCondition instanceof RuleRouteCondition)) {
sql = SimpleHintParser.removeHint(sql, parameterSettings);
return optimizerHint(sql, cached, routeCondition, parameterSettings, extraCmd);
} else {
return optimizeAndAssignment(null, parameterSettings, extraCmd, sql, cached);
}
}
示例3: testExecuteByDB
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testExecuteByDB() {
String sql = "/*+TDDL({type:executeByDB,dbId:xxx_group})*/delete from moddbtab_0000 where pk=?";
DirectlyRouteCondition route = (DirectlyRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
Assert.assertEquals("xxx_group", route.getDbId());
Assert.assertEquals(0, route.getTables().size());
}
示例4: testExecuteByDBAndTab
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testExecuteByDBAndTab() {
String sql = "/*+TDDL({type:executeByDBAndTab,tables:[real_tab_0,real_tab_1],dbId:xxx_group,virtualTableName:real_tab})*/delete from moddbtab where pk=?";
DirectlyRouteCondition route = (DirectlyRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
Assert.assertEquals("xxx_group", route.getDbId());
Assert.assertEquals("real_tab", route.getVirtualTableName());
Assert.assertEquals(2, route.getTables().size());
}
示例5: testExecuteByCondition
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testExecuteByCondition() {
String sql = "/*+TDDL({type:executeByCondition,parameters:[\"your_sharding_column=4;i\"],virtualTableName:real_tab})*/delete from moddbtab where pk=?";
RuleRouteCondition route = (RuleRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
Assert.assertEquals("real_tab", route.getVirtualTableName());
Assert.assertEquals("{YOUR_SHARDING_COLUMN=(=4)}", route.getParameters().toString());
sql = "/*+TDDL({type:executeByCondition,parameters:[\"a=4;i or a=5;i\" , \"b>1;l and b<5;l\"],virtualTableName:real_tab})*/delete from moddbtab where pk=?";
route = (RuleRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
Assert.assertEquals("real_tab", route.getVirtualTableName());
Assert.assertEquals("{A=(=4) OR (=5), B=(>1) AND (<5)}", route.getParameters().toString());
}
示例6: ParameterContext
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void test_绑定变量测试() {
String sql = "/*+TDDL({type:?,dbId:?})*/delete from moddbtab_0000 where pk=?";
Map<Integer, ParameterContext> map = new HashMap<Integer, ParameterContext>();
map.put(1, new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, "executeByDB" }));
map.put(2, new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, "xxx_group" }));
DirectlyRouteCondition route = (DirectlyRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, map);
Assert.assertEquals("xxx_group", route.getDbId());
Assert.assertEquals(0, route.getTables().size());
}
示例7: testDirect
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testDirect() {
String sql = "/*+TDDL({'type':'direct','vtab':'real_tab','dbid':'xxx_group','realtabs':['real_tab_0','real_tab_1']})*/select * from real_tab";
DirectlyRouteCondition route = (DirectlyRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
System.out.println(route);
Assert.assertEquals("xxx_group", route.getDbId());
Assert.assertEquals(2, route.getTables().size());
Assert.assertEquals("real_tab", route.getVirtualTableName());
}
示例8: testCondition
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testCondition() {
String sql = "/*+TDDL({'type':'condition','vtab':'vtabxxx','params':[{'relation':'and','expr':['pk>4','pk<10'],'paramtype':'int'}]})*/";
RuleRouteCondition route = (RuleRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
System.out.println(route);
Assert.assertEquals("vtabxxx", route.getVirtualTableName());
Assert.assertEquals("(>4) AND (<10)", route.getParameters().get("PK").toString());
}
示例9: testExtraCmd
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testExtraCmd() {
String sql = "/*+TDDL({'extra':{'ChooseIndex':'true','ALLOW_TEMPORARY_TABLE':'true'}})*/select * from real_tab";
ExtraCmdRouteCondition route = (ExtraCmdRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
System.out.println(route);
Assert.assertEquals("{CHOOSEINDEX=true, ALLOW_TEMPORARY_TABLE=true}", route.getExtraCmds().toString());
}
示例10: testDirect
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testDirect() {
String sql = "/*+TDDL({\"type\":\"direct\",\"vtab\":\"real_tab\",\"dbid\":\"xxx_group\",\"realtabs\":[\"real_tab_0\",\"real_tab_1\"]})*/select * from real_tab";
DirectlyRouteCondition route = (DirectlyRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
System.out.println(route);
Assert.assertEquals("xxx_group", route.getDbId());
Assert.assertEquals(2, route.getTables().size());
Assert.assertEquals("real_tab", route.getVirtualTableName());
}
示例11: testCondition
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testCondition() {
String sql = "/*+TDDL({\"type\":\"condition\",\"vtab\":\"vtabxxx\",\"params\":[{\"relation\":\"and\",\"expr\":[\"pk>4\",\"pk<10\"],\"paramtype\":\"int\"}],\"skip\":10,\"max\":20,\"orderby\":\"col1\",\"asc\":\"true\"})*/";
RuleRouteCondition route = (RuleRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
System.out.println(route);
Assert.assertEquals("vtabxxx", route.getVirtualTableName());
Assert.assertEquals("(>4) AND (<10)", route.getParameters().get("PK").toString());
}
示例12: testExtraCmd
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Test
public void testExtraCmd() {
String sql = "/*+TDDL({\"extra\":{\"ChooseIndex\":\"true\",\"ALLOW_TEMPORARY_TABLE\":\"true\"}})*/select * from real_tab";
ExtraCmdRouteCondition route = (ExtraCmdRouteCondition) SimpleHintParser.convertHint2RouteCondition(sql, null);
System.out.println(route);
Assert.assertEquals("{CHOOSEINDEX=true, ALLOW_TEMPORARY_TABLE=true}", route.getExtraCmds().toString());
}
示例13: prepareCall
import com.taobao.tddl.optimizer.parse.hint.SimpleHintParser; //导入依赖的package包/类
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
checkClosed();
// 先检查下是否有db hint
DirectlyRouteCondition route = (DirectlyRouteCondition) SimpleHintParser.getRouteContiongFromThreadLocal(ThreadLocalString.DB_SELECTOR);
String defaultDbIndex = null;
if (route != null) {
defaultDbIndex = route.getDbId();
} else {
// 针对存储过程,直接下推到default库上执行
defaultDbIndex = this.ds.getConfigHolder().getOptimizerContext().getRule().getDefaultDbIndex(null);
}
IGroupExecutor groupExecutor = this.ds.getConfigHolder()
.getExecutorContext()
.getTopologyHandler()
.get(defaultDbIndex);
Object groupDataSource = groupExecutor.getRemotingExecutableObject();
if (groupDataSource instanceof DataSource) {
GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
Connection conn = ((DataSource) groupDataSource).getConnection();
CallableStatement target = null;
if (resultSetType != Integer.MIN_VALUE && resultSetHoldability != Integer.MIN_VALUE) {
target = conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
} else if (resultSetType != Integer.MIN_VALUE) {
target = conn.prepareCall(sql, resultSetType, resultSetConcurrency);
} else {
target = conn.prepareCall(sql);
}
ExecutionContext context = prepareExecutionContext();
TCallableStatement stmt = new TCallableStatement(ds, this, sql, context, target);
openedStatements.add(stmt);
return stmt;
} else {
throw new UnsupportedOperationException();
}
}