use of io.mycat.sqlengine.mpp.RangeValue in project Mycat_plus by coderczp.
the class RouteCalculateUnit method addShardingExpr.
public void addShardingExpr(String tableName, String columnName, Object value) {
Map<String, Set<ColumnRoutePair>> tableColumnsMap = tablesAndConditions.get(tableName);
if (value == null) {
// where a=null
return;
}
if (tableColumnsMap == null) {
tableColumnsMap = new LinkedHashMap<String, Set<ColumnRoutePair>>();
tablesAndConditions.put(tableName, tableColumnsMap);
}
String uperColName = columnName.toUpperCase();
Set<ColumnRoutePair> columValues = tableColumnsMap.get(uperColName);
if (columValues == null) {
columValues = new LinkedHashSet<ColumnRoutePair>();
tablesAndConditions.get(tableName).put(uperColName, columValues);
}
if (value instanceof Object[]) {
for (Object item : (Object[]) value) {
if (item == null) {
continue;
}
columValues.add(new ColumnRoutePair(item.toString()));
}
} else if (value instanceof RangeValue) {
columValues.add(new ColumnRoutePair((RangeValue) value));
} else {
columValues.add(new ColumnRoutePair(value.toString()));
}
}
use of io.mycat.sqlengine.mpp.RangeValue in project Mycat_plus by coderczp.
the class DefaultDruidParser method buildRouteCalculateUnits.
private List<RouteCalculateUnit> buildRouteCalculateUnits(SchemaStatVisitor visitor, List<List<Condition>> conditionList) {
List<RouteCalculateUnit> retList = new ArrayList<RouteCalculateUnit>();
// 遍历condition ,找分片字段
for (int i = 0; i < conditionList.size(); i++) {
RouteCalculateUnit routeCalculateUnit = new RouteCalculateUnit();
for (Condition condition : conditionList.get(i)) {
List<Object> values = condition.getValues();
if (values.size() == 0) {
continue;
}
if (checkConditionValues(values)) {
String columnName = StringUtil.removeBackquote(condition.getColumn().getName().toUpperCase());
String tableName = StringUtil.removeBackquote(condition.getColumn().getTable().toUpperCase());
if (visitor.getAliasMap() != null && visitor.getAliasMap().get(tableName) != null && !visitor.getAliasMap().get(tableName).equals(tableName)) {
tableName = visitor.getAliasMap().get(tableName);
}
if (visitor.getAliasMap() != null && visitor.getAliasMap().get(StringUtil.removeBackquote(condition.getColumn().getTable().toUpperCase())) == null) {
// 子查询的别名条件忽略掉,不参数路由计算,否则后面找不到表
continue;
}
String operator = condition.getOperator();
// 只处理between ,in和=3中操作符
if (operator.equals("between")) {
RangeValue rv = new RangeValue(values.get(0), values.get(1), RangeValue.EE);
routeCalculateUnit.addShardingExpr(tableName.toUpperCase(), columnName, rv);
} else if (operator.equals("=") || operator.toLowerCase().equals("in")) {
// 只处理=号和in操作符,其他忽略
routeCalculateUnit.addShardingExpr(tableName.toUpperCase(), columnName, values.toArray());
}
}
}
retList.add(routeCalculateUnit);
}
return retList;
}
use of io.mycat.sqlengine.mpp.RangeValue in project Mycat-Server by MyCATApache.
the class DefaultDruidParser method buildRouteCalculateUnits.
private List<RouteCalculateUnit> buildRouteCalculateUnits(SchemaStatVisitor visitor, List<List<Condition>> conditionList) {
List<RouteCalculateUnit> retList = new ArrayList<RouteCalculateUnit>();
// 遍历condition ,找分片字段
for (int i = 0; i < conditionList.size(); i++) {
RouteCalculateUnit routeCalculateUnit = new RouteCalculateUnit();
for (Condition condition : conditionList.get(i)) {
List<Object> values = condition.getValues();
if (values.size() == 0) {
continue;
}
if (checkConditionValues(values)) {
String columnName = StringUtil.removeBackquote(condition.getColumn().getName().toUpperCase());
String tableName = StringUtil.removeBackquote(condition.getColumn().getTable().toUpperCase());
if (visitor.getAliasMap() != null && visitor.getAliasMap().get(tableName) != null && !visitor.getAliasMap().get(tableName).equals(tableName)) {
tableName = visitor.getAliasMap().get(tableName);
}
if (visitor.getAliasMap() != null && visitor.getAliasMap().get(StringUtil.removeBackquote(condition.getColumn().getTable().toUpperCase())) == null) {
// 子查询的别名条件忽略掉,不参数路由计算,否则后面找不到表
continue;
}
String operator = condition.getOperator();
// 只处理between ,in和=3中操作符
if (operator.equals("between")) {
RangeValue rv = new RangeValue(values.get(0), values.get(1), RangeValue.EE);
routeCalculateUnit.addShardingExpr(tableName.toUpperCase(), columnName, rv);
} else if (operator.equals("=") || operator.toLowerCase().equals("in")) {
// 只处理=号和in操作符,其他忽略
routeCalculateUnit.addShardingExpr(tableName.toUpperCase(), columnName, values.toArray());
}
}
}
retList.add(routeCalculateUnit);
}
return retList;
}
use of io.mycat.sqlengine.mpp.RangeValue in project Mycat-Server by MyCATApache.
the class RouteCalculateUnit method addShardingExpr.
public void addShardingExpr(String tableName, String columnName, Object value) {
Map<String, Set<ColumnRoutePair>> tableColumnsMap = tablesAndConditions.get(tableName);
if (value == null) {
// where a=null
return;
}
if (tableColumnsMap == null) {
tableColumnsMap = new LinkedHashMap<String, Set<ColumnRoutePair>>();
tablesAndConditions.put(tableName, tableColumnsMap);
}
String uperColName = columnName.toUpperCase();
Set<ColumnRoutePair> columValues = tableColumnsMap.get(uperColName);
if (columValues == null) {
columValues = new LinkedHashSet<ColumnRoutePair>();
tablesAndConditions.get(tableName).put(uperColName, columValues);
}
if (value instanceof Object[]) {
for (Object item : (Object[]) value) {
if (item == null) {
continue;
}
columValues.add(new ColumnRoutePair(item.toString()));
}
} else if (value instanceof RangeValue) {
columValues.add(new ColumnRoutePair((RangeValue) value));
} else {
columValues.add(new ColumnRoutePair(value.toString()));
}
}
Aggregations