Skip to content

Commit

Permalink
support enum range query
Browse files Browse the repository at this point in the history
  • Loading branch information
junwen12221 committed Nov 8, 2021
1 parent 314a02e commit 7cb1cf0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions router/src/main/java/io/mycat/router/function/AutoFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,15 @@ public boolean isSameDbFunctionDistribution(CustomRuleFunction customRuleFunctio
}
return false;
}

@Override
public boolean isShardingTargetEnum() {
switch (getShardingTableType()) {
case SHARDING_INSTANCE_SINGLE_TABLE:
return isShardingDbEnum();
case SINGLE_INSTANCE_SHARDING_TABLE:
case SHARDING_INSTANCE_SHARDING_TABLE:
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static class Key {
}

public static final ImmutableSet<String> FLATTEN_MAPPING = ImmutableSet.of("MOD_HASH", "UNI_HASH", "RIGHT_SHIFT", "YYYYMM", "YYYYDD", "YYYYWEEK");
public static final ImmutableSet<String> ENUM_RANGE = ImmutableSet.of("MM", "DD", "WEEK", "MMDD", "YYYYDD", "YYYYMM", "YYYYWEEK");

@SneakyThrows
public static final CustomRuleFunction
Expand All @@ -64,6 +65,7 @@ static class Key {
int dbNum = Integer.parseInt(properties.getOrDefault("dbNum", 1).toString());
int tableNum = Integer.parseInt(properties.getOrDefault("tableNum", 1).toString());


Integer storeNum = Optional.ofNullable(properties.get("storeNum"))
.map(i -> Integer.parseInt(i.toString()))
.filter(n -> n > 0)
Expand All @@ -90,6 +92,13 @@ static class Key {
tableHandler.getTableName() + ((!supportFlattenMapping(tableMethod, dbMethod)) ? "_${tableIndex}" : "_${index}")));
final boolean flattenMapping = mappingFormat.contains("${index}") && supportFlattenMapping(tableMethod, dbMethod);

boolean dbEnum = Optional.ofNullable(dbMethod).map(db -> {
return ENUM_RANGE.contains(SQLUtils.normalize(db.getMethodName().toUpperCase()));
}).orElse(false);
boolean tableEnum = Optional.ofNullable(tableMethod).map(tb -> {
return ENUM_RANGE.contains(SQLUtils.normalize(tb.getMethodName().toUpperCase()));
}).orElse(false);

if (dbMethod != null) {
int num = dbNum;
SQLMethodInvokeExpr methodInvokeExpr = dbMethod;
Expand Down Expand Up @@ -441,6 +450,16 @@ public List<Partition> scanOnlyDbIndex(int index) {
public List<Partition> scanOnlyDbTableIndex(int dbIndex, int tableIndex) {
return scanOnlyTableIndex(tableIndex);
}

@Override
public boolean isShardingDbEnum() {
return dbEnum;
}

@Override
public boolean isShardingTableEnum() {
return tableEnum;
}
};
} else {
Map<Integer, List<Partition>> dbIndexToNode = indexDataNodes.stream().collect(Collectors.groupingBy(k -> k.getDbIndex()));
Expand Down Expand Up @@ -476,6 +495,16 @@ public List<Partition> scanOnlyDbTableIndex(int dbIndex, int tableIndex) {
}
return dataNodes;
}

@Override
public boolean isShardingDbEnum() {
return dbEnum;
}

@Override
public boolean isShardingTableEnum() {
return tableEnum;
}
};
}
}
Expand Down

0 comments on commit 7cb1cf0

Please sign in to comment.