Search in sources :

Example 1 with RangeValue

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;
}
Also used : RouteCalculateUnit(com.actiontech.dble.route.parser.druid.RouteCalculateUnit) Condition(com.alibaba.druid.stat.TableStat.Condition) ArrayList(java.util.ArrayList) RangeValue(com.actiontech.dble.sqlengine.mpp.RangeValue)

Example 2 with RangeValue

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()));
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ColumnRoutePair(com.actiontech.dble.sqlengine.mpp.ColumnRoutePair) RangeValue(com.actiontech.dble.sqlengine.mpp.RangeValue)

Aggregations

RangeValue (com.actiontech.dble.sqlengine.mpp.RangeValue)2 RouteCalculateUnit (com.actiontech.dble.route.parser.druid.RouteCalculateUnit)1 ColumnRoutePair (com.actiontech.dble.sqlengine.mpp.ColumnRoutePair)1 Condition (com.alibaba.druid.stat.TableStat.Condition)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1