use of com.actiontech.dble.sqlengine.mpp.RangeValue in project dble by actiontech.
the class DefaultDruidParser method buildRouteCalculateUnits.
private List<RouteCalculateUnit> buildRouteCalculateUnits(Map<String, String> tableAliasMap, List<List<Condition>> conditionList) {
List<RouteCalculateUnit> retList = new ArrayList<>();
// find partition column in condition
for (List<Condition> aConditionList : conditionList) {
RouteCalculateUnit routeCalculateUnit = new RouteCalculateUnit();
for (Condition condition : aConditionList) {
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());
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
tableName = tableName.toLowerCase();
}
if (tableAliasMap != null && tableAliasMap.get(tableName) == null) {
// ignore subQuery's alias
continue;
}
if (tableAliasMap != null && tableAliasMap.get(tableName) != null && !tableAliasMap.get(tableName).equals(tableName)) {
tableName = tableAliasMap.get(tableName);
}
String operator = condition.getOperator();
// execute only between ,in and =
if (operator.equals("between")) {
RangeValue rv = new RangeValue(values.get(0), values.get(1), RangeValue.EE);
routeCalculateUnit.addShardingExpr(tableName, columnName, rv);
} else if (operator.equals("=") || operator.toLowerCase().equals("in")) {
routeCalculateUnit.addShardingExpr(tableName, columnName, values.toArray());
}
}
}
retList.add(routeCalculateUnit);
}
return retList;
}
use of com.actiontech.dble.sqlengine.mpp.RangeValue in project dble by actiontech.
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<>();
tablesAndConditions.put(tableName, tableColumnsMap);
}
String upperColName = columnName.toUpperCase();
Set<ColumnRoutePair> columnValues = tableColumnsMap.get(upperColName);
if (columnValues == null) {
columnValues = new LinkedHashSet<>();
tablesAndConditions.get(tableName).put(upperColName, columnValues);
}
if (value instanceof Object[]) {
for (Object item : (Object[]) value) {
if (item == null) {
continue;
}
columnValues.add(new ColumnRoutePair(item.toString()));
}
} else if (value instanceof RangeValue) {
columnValues.add(new ColumnRoutePair((RangeValue) value));
} else {
columnValues.add(new ColumnRoutePair(value.toString()));
}
}
Aggregations