use of io.mycat.Partition in project Mycat2 by MyCATApache.
the class HBTQueryConvertor method filterFromTable.
public RelNode filterFromTable(FilterFromTableSchema input) {
List<String> names = input.getNames();
relBuilder.scan(names);
TableScan tableScan = (TableScan) relBuilder.peek();
RelOptTable table = tableScan.getTable();
relBuilder.as(names.get(names.size() - 1));
relBuilder.filter(toRex(input.getFilter()));
Filter build = (Filter) relBuilder.build();
relBuilder.clear();
MycatLogicTable mycatTable = table.unwrap(MycatLogicTable.class);
Distribution distribution = mycatTable.createDistribution();
Iterable<Partition> dataNodes = distribution.getDataNodes().flatMap(i -> i.values().stream()).collect(Collectors.toList());
return build.copy(build.getTraitSet(), ImmutableList.of(toPhyTable(mycatTable, dataNodes)));
}
use of io.mycat.Partition in project Mycat2 by MyCATApache.
the class HBTQueryConvertor method toPhyTable.
private RelNode toPhyTable(MycatLogicTable unwrap, Iterable<Partition> dataNodes) {
int count = 0;
for (Partition partition : dataNodes) {
MycatPhysicalTable mycatPhysicalTable = new MycatPhysicalTable(unwrap, partition);
LogicalTableScan tableScan = LogicalTableScan.create(relBuilder.getCluster(), RelOptTableImpl.create(relBuilder.getRelOptSchema(), unwrap.getRowType(), mycatPhysicalTable, ImmutableList.of(partition.getSchema(), partition.getTable())), ImmutableList.of());
count++;
relBuilder.push(tableScan);
}
return relBuilder.union(true, count).build();
}
use of io.mycat.Partition in project Mycat2 by MyCATApache.
the class IndexShardingTableVO method toShardingTableConfig.
public ShardingTableConfig toShardingTableConfig() {
shardingTableConfig.setShardingIndexTables(Collections.emptyMap());
String sql = this.indexCreateTableSQL.getText();
String shardingInfoText = this.indexShardingInfo.getText();
List<List> partitions = new ArrayList<>();
for (PartitionEntry item : indexPartitionsView.getItems()) {
Partition partition = item.toPartition();
String targetName = partition.getTargetName();
String schema = partition.getSchema();
String table = partition.getTable();
Integer dbIndex = partition.getDbIndex();
Integer tableIndex = partition.getTableIndex();
Integer index = partition.getIndex();
partitions.add(Arrays.asList(targetName, schema, table, dbIndex, tableIndex, index));
}
ShardingFunction shardingFuntion;
if (!StringUtil.isEmpty(shardingInfoText)) {
shardingFuntion = Json.decodeValue(shardingInfoText, ShardingFunction.class);
} else {
shardingFuntion = new ShardingFunction();
}
shardingTableConfig.setCreateTableSQL(sql);
shardingTableConfig.setFunction(shardingFuntion);
shardingTableConfig.setPartition(ShardingBackEndTableInfoConfig.builder().data(partitions).build());
shardingTableConfig.setShardingIndexTables(Collections.emptyMap());
return shardingTableConfig;
}
use of io.mycat.Partition in project Mycat2 by MyCATApache.
the class CustomRuleFunction method calculateOne.
public Partition calculateOne(Map<String, RangeVariable> values) {
List<Partition> partitions = calculate(values);
if (partitions.isEmpty()) {
throw new IllegalArgumentException("路由计算返回结果个数为0");
}
if (partitions.size() != 1) {
List<Partition> dataNodes2 = calculate(values);
dataNodes2 = calculate(values);
throw new IllegalArgumentException("路由计算返回结果个数为" + partitions.size());
}
Partition partition = partitions.get(0);
if (partition == null) {
throw new IllegalArgumentException("路由计算返回结果为NULL");
}
return partitions.get(0);
}
use of io.mycat.Partition in project Mycat2 by MyCATApache.
the class CustomRuleFunction method getPartition.
public Partition getPartition(int index) {
List<Partition> partitions = calculate(Collections.emptyMap());
Partition maybePartition = partitions.get(index);
if (maybePartition.getIndex() != null) {
if (maybePartition.getIndex() == index) {
return maybePartition;
} else {
return partitions.stream().filter(p -> p.getIndex() == index).findFirst().orElse(null);
}
}
return maybePartition;
}
Aggregations