Search in sources :

Example 6 with DrdsSqlCompiler

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());
}
Also used : ValuePredicateAnalyzer(io.mycat.calcite.rewriter.ValuePredicateAnalyzer) Partition(io.mycat.Partition) MetadataManager(io.mycat.MetadataManager) DrdsSqlCompiler(io.mycat.DrdsSqlCompiler) ShardingTable(io.mycat.calcite.table.ShardingTable) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 7 with DrdsSqlCompiler

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));
}
Also used : ValuePredicateAnalyzer(io.mycat.calcite.rewriter.ValuePredicateAnalyzer) MetadataManager(io.mycat.MetadataManager) DrdsSqlCompiler(io.mycat.DrdsSqlCompiler) ShardingTable(io.mycat.calcite.table.ShardingTable) QueryType(io.mycat.querycondition.QueryType) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 8 with DrdsSqlCompiler

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);
}
Also used : DrdsSqlCompiler(io.mycat.DrdsSqlCompiler) MycatRel(io.mycat.calcite.MycatRel) OptimizationContext(io.mycat.calcite.rewriter.OptimizationContext) Plan(io.mycat.calcite.spm.Plan) DrdsSqlWithParams(io.mycat.DrdsSqlWithParams) PlanImpl(io.mycat.calcite.spm.PlanImpl)

Example 9 with DrdsSqlCompiler

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;
}
Also used : DrdsConst(io.mycat.DrdsConst) DrdsSqlCompiler(io.mycat.DrdsSqlCompiler) NameMap(io.mycat.util.NameMap)

Example 10 with 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);
}
Also used : DrdsSqlCompiler(io.mycat.DrdsSqlCompiler) MycatRel(io.mycat.calcite.MycatRel) OptimizationContext(io.mycat.calcite.rewriter.OptimizationContext) Plan(io.mycat.calcite.spm.Plan) DrdsSqlWithParams(io.mycat.DrdsSqlWithParams) PlanImpl(io.mycat.calcite.spm.PlanImpl)

Aggregations

DrdsSqlCompiler (io.mycat.DrdsSqlCompiler)12 MetadataManager (io.mycat.MetadataManager)5 ValuePredicateAnalyzer (io.mycat.calcite.rewriter.ValuePredicateAnalyzer)5 ShardingTable (io.mycat.calcite.table.ShardingTable)5 RexNode (org.apache.calcite.rex.RexNode)5 Test (org.junit.Test)5 DrdsSqlWithParams (io.mycat.DrdsSqlWithParams)4 MycatRel (io.mycat.calcite.MycatRel)4 OptimizationContext (io.mycat.calcite.rewriter.OptimizationContext)4 Plan (io.mycat.calcite.spm.Plan)4 PlanImpl (io.mycat.calcite.spm.PlanImpl)4 DrdsConst (io.mycat.DrdsConst)3 NameMap (io.mycat.util.NameMap)3 Partition (io.mycat.Partition)2 QueryType (io.mycat.querycondition.QueryType)1