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;
}
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));
}
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));
}
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());
}
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;
}
Aggregations