Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
junwen12221 committed Apr 29, 2022
1 parent f08c515 commit 1bd0454
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/src/test/java/io/mycat/sql/UserCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public void case11() throws Exception {
String explain = explain(mycatConnection, "select count(*) from db1.travelrecord");
Assert.assertTrue(explain.contains("MycatHashAggregate(group=[{}], count(*)=[$SUM0($0)])\n" +
" MycatView(distribution=[[db1.travelrecord]])\n" +
"Each(targetName=c0, sql=SELECT COUNT(*) AS `count(*)` FROM db1_0.travelrecord_0 AS `travelrecord`)"));
"Each(targetName=c0, sql=SELECT COUNT(*) AS `count(*)` FROM db1.travelrecord_0 AS `travelrecord`)"));
System.out.println();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,22 @@ static class Key {
int dbNum = Integer.parseInt(properties.getOrDefault("dbNum", 1).toString());
int tableNum = Integer.parseInt(properties.getOrDefault("tableNum", 1).toString());


int storeNum = Optional.ofNullable(properties.get("storeNum"))
.map(i -> Integer.parseInt(i.toString())).orElse(0);

boolean prototype = (storeNum == 0);
if (prototype){

if (storeNum < 2) {
storeNum = 1;
}
Integer storeDbNum = Optional.ofNullable(properties.get("storeDbNum"))

int storeDbNum = Optional.ofNullable(properties.get("storeDbNum"))
.map(i -> Integer.parseInt(i.toString())).orElse(dbNum * tableNum / storeNum);

if (storeDbNum < 2) {
storeDbNum = 1;
}

SQLMethodInvokeExpr tableMethod = converyToMethodExpr((String) properties.get("tableMethod"));
SQLMethodInvokeExpr dbMethod = converyToMethodExpr((String) properties.get("dbMethod"));
String sep = "/";
Expand All @@ -91,7 +97,7 @@ static class Key {

String mappingFormat = (String) properties.computeIfAbsent("mappingFormat", (unused) ->
String.join(sep, prototype ? "prototype" : "c${targetIndex}",
tableHandler.getSchemaName() + "_${dbIndex}",
dbNum < 2 ? tableHandler.getSchemaName() : tableHandler.getSchemaName() + "_${dbIndex}",
tableHandler.getTableName() + ((!supportFlattenMapping(tableMethod, dbMethod)) ? "_${tableIndex}" : "_${index}")));
final boolean flattenMapping = mappingFormat.contains("${index}");

Expand Down

0 comments on commit 1bd0454

Please sign in to comment.