Search in sources :

Example 1 with DrdsSqlCompiler

use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.

the class ShardingJoinRBOMegreTest method getDrds.

public static DrdsSqlCompiler getDrds(boolean bkaJoin) {
    DrdsSqlCompiler sqlCompiler = DrdsTest.getDrds();
    DrdsConst config = sqlCompiler.getConfig();
    DrdsSqlCompiler.RBO_MERGE_JOIN = true;
    DrdsSqlCompiler.RBO_BKA_JOIN = bkaJoin;
    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 2 with DrdsSqlCompiler

use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.

the class ValuePredicateAnalyzerTest method testNot.

// 
@Test
public void testNot() {
    DrdsSqlCompiler drds = DrdsTest.getDrds();
    RexNode leftRexNode = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, rexBuilder.makeInputRef(MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), 0), rexBuilder.makeLiteral(0, MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), true));
    RexNode rexNode = rexBuilder.makeCall(SqlStdOperatorTable.NOT, leftRexNode);
    List<String> columnList = Arrays.asList("id");
    MetadataManager metadataManager = DrdsTest.getMetadataManager();
    ShardingTable table = (ShardingTable) metadataManager.getTable("db1", "sharding");
    ValuePredicateAnalyzer valuePredicateAnalyzer2 = new ValuePredicateAnalyzer(Arrays.asList(KeyMeta.of("default", "id")), columnList);
    Object o = ValueIndexCondition.getPartitions(table.getShardingFuntion(), valuePredicateAnalyzer2.translateMatch(rexNode), Arrays.asList());
    Assert.assertEquals("[{targetName='c0', schemaName='db1_0', tableName='sharding_0', index=0, dbIndex=0, tableIndex=0}, {targetName='c0', schemaName='db1_0', tableName='sharding_1', index=1, dbIndex=0, tableIndex=1}, {targetName='c1', schemaName='db1_1', tableName='sharding_0', index=2, dbIndex=1, tableIndex=0}, {targetName='c1', schemaName='db1_1', tableName='sharding_1', index=3, dbIndex=1, tableIndex=1}]", Objects.toString(o));
}
Also used : ValuePredicateAnalyzer(io.mycat.calcite.rewriter.ValuePredicateAnalyzer) 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 3 with DrdsSqlCompiler

use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.

the class ValuePredicateAnalyzerTest method testOr.

@Test
public void testOr() {
    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.makeDynamicParam(MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), 1));
    RexNode rexNode = rexBuilder.makeCall(SqlStdOperatorTable.OR, 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");
    Object o = ValueIndexCondition.getPartitions(table.getShardingFuntion(), valuePredicateAnalyzer2.translateMatch(rexNode), Arrays.asList());
    Assert.assertEquals("[{targetName='c0', schemaName='db1_0', tableName='sharding_0', index=0, dbIndex=0, tableIndex=0}, {targetName='c0', schemaName='db1_0', tableName='sharding_1', index=1, dbIndex=0, tableIndex=1}, {targetName='c1', schemaName='db1_1', tableName='sharding_0', index=2, dbIndex=1, tableIndex=0}, {targetName='c1', schemaName='db1_1', tableName='sharding_1', index=3, dbIndex=1, tableIndex=1}]", Objects.toString(o));
}
Also used : ValuePredicateAnalyzer(io.mycat.calcite.rewriter.ValuePredicateAnalyzer) 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 4 with DrdsSqlCompiler

use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.

the class ValuePredicateAnalyzerTest method testEqual.

@Test
public void testEqual() {
    DrdsSqlCompiler drds = DrdsTest.getDrds();
    MetadataManager metadataManager = DrdsTest.getMetadataManager();
    ShardingTable table = (ShardingTable) metadataManager.getTable("db1", "sharding");
    RexNode rexNode = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, rexBuilder.makeInputRef(MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), 0), rexBuilder.makeLiteral(1, MycatCalciteSupport.TypeFactory.createSqlType(SqlTypeName.INTEGER), true));
    List<String> columnList = Arrays.asList("id");
    ValuePredicateAnalyzer valuePredicateAnalyzer2 = new ValuePredicateAnalyzer(Collections.singletonList(KeyMeta.of("default", "id")), columnList);
    List<Partition> dataNodes = ValueIndexCondition.getPartitions(table.getShardingFuntion(), valuePredicateAnalyzer2.translateMatch(rexNode), Arrays.asList(1));
    Assert.assertEquals(("[{targetName='c1', schemaName='db1_1', tableName='sharding_1', index=3, dbIndex=1, tableIndex=1}]").toString(), dataNodes.toString());
}
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 5 with DrdsSqlCompiler

use of io.mycat.DrdsSqlCompiler in project Mycat2 by MyCATApache.

the class AllShardingJoinTest method getDrds.

public static DrdsSqlCompiler getDrds(boolean bkaJoin) {
    DrdsSqlCompiler sqlCompiler = DrdsTest.getDrds();
    DrdsSqlCompiler.RBO_MERGE_JOIN = true;
    DrdsSqlCompiler.RBO_BKA_JOIN = bkaJoin;
    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)

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