use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.
the class ValuePredicateAnalyzerTest method testEqualParam.
@Test
public void testEqualParam() {
DrdsSqlCompiler drds = DrdsTest.getDrds();
RexNode rexNode = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, rexBuilder.makeInputRef(MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), 0), rexBuilder.makeLiteral(1, MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), true));
MetadataManager metadataManager = DrdsTest.getMetadataManager();
ShardingTable table = (ShardingTable) metadataManager.getTable("db1", "sharding");
List<String> columnList = Arrays.asList("id");
ValuePredicateAnalyzer valuePredicateAnalyzer2 = new ValuePredicateAnalyzer(Arrays.asList(KeyMeta.of("default", "id")), columnList);
List<Partition> dataNodes = ValueIndexCondition.getPartitions(table.getShardingFuntion(), valuePredicateAnalyzer2.translateMatch(rexNode), Arrays.asList(0));
Assert.assertEquals(1, dataNodes.size());
}
use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.
the class ValuePredicateAnalyzerTest method testRange.
@Test
public void testRange() {
DrdsSqlCompiler drds = DrdsTest.getDrds();
RexNode leftRexNode = rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN, rexBuilder.makeInputRef(MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), 0), rexBuilder.makeLiteral(0, MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), true));
RexNode rightRexNode = rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN, rexBuilder.makeInputRef(MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), 0), rexBuilder.makeLiteral(1, MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), true));
RexNode rexNode = rexBuilder.makeCall(SqlStdOperatorTable.AND, leftRexNode, rightRexNode);
List<String> columnList = Arrays.asList("id");
ValuePredicateAnalyzer valuePredicateAnalyzer2 = new ValuePredicateAnalyzer(Arrays.asList(KeyMeta.of("default", "id")), columnList);
MetadataManager metadataManager = DrdsTest.getMetadataManager();
ShardingTable table = (ShardingTable) metadataManager.getTable("db1", "sharding");
Map<QueryType, List<ValueIndexCondition>> condition = valuePredicateAnalyzer2.translateMatch(rexNode);
Assert.assertEquals("{PK_RANGE_QUERY=[ValueIndexCondition(fieldNames=[id], indexName=default, indexColumnNames=[id], queryType=PK_RANGE_QUERY, rangeQueryLowerOp=GT, rangeQueryLowerKey=[0], rangeQueryUpperOp=LT, rangeQueryUpperKey=[1], pointQueryKey=null)]}", Objects.toString(condition));
}
use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.
the class ShardingJoinRBOMegreTest method parse.
public static Explain parse(String sql) {
DrdsSqlCompiler drds = getDrds();
DrdsSqlWithParams drdsSqlWithParams = DrdsRunnerHelper.preParse(sql, null);
OptimizationContext optimizationContext = new OptimizationContext();
MycatRel dispatch = drds.dispatch(optimizationContext, drdsSqlWithParams);
Plan plan = new PlanImpl(dispatch, DrdsExecutorCompiler.getCodeExecuterContext(optimizationContext.relNodeContext.getConstantMap(), dispatch, false), drdsSqlWithParams.getAliasList());
return new Explain(plan, drdsSqlWithParams);
}
use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.
the class ShardingJoinTest method getDrds.
public static DrdsSqlCompiler getDrds(boolean rboMergeJoin) {
DrdsSqlCompiler.RBO_MERGE_JOIN = rboMergeJoin;
DrdsSqlCompiler.RBO_BKA_JOIN = false;
DrdsSqlCompiler sqlCompiler = DrdsTest.getDrds();
DrdsConst config = sqlCompiler.getConfig();
DrdsSqlCompiler drdsSqlCompiler = new DrdsSqlCompiler(new DrdsConst() {
@Override
public NameMap<SchemaHandler> schemas() {
return config.schemas();
}
});
return drdsSqlCompiler;
}
use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.
the class ShardingJoinTest method parse.
public static Explain parse(String sql) {
DrdsSqlCompiler drds = getDrds();
DrdsSqlWithParams drdsSqlWithParams = DrdsRunnerHelper.preParse(sql, null);
OptimizationContext optimizationContext = new OptimizationContext();
MycatRel dispatch = drds.dispatch(optimizationContext, drdsSqlWithParams);
Plan plan = new PlanImpl(dispatch, DrdsExecutorCompiler.getCodeExecuterContext(optimizationContext.relNodeContext.getConstantMap(), dispatch, false), drdsSqlWithParams.getAliasList());
return new Explain(plan, drdsSqlWithParams);
}
Aggregations