本文整理汇总了Java中com.taobao.tddl.optimizer.utils.FilterUtils.toColumnFiltersMap方法的典型用法代码示例。如果您正苦于以下问题:Java FilterUtils.toColumnFiltersMap方法的具体用法?Java FilterUtils.toColumnFiltersMap怎么用?Java FilterUtils.toColumnFiltersMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.utils.FilterUtils
的用法示例。
在下文中一共展示了FilterUtils.toColumnFiltersMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBestIndex
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
public static IndexMeta findBestIndex(TableMeta tableMeta, List<ISelectable> columns, List<IFilter> filters,
String tablename, Map<String, Object> extraCmd) {
if (!chooseIndex(extraCmd)) {
return null;
}
List<IndexMeta> indexs = tableMeta.getIndexs();
if (indexs.isEmpty()) {
return null;
}
Map<Object, List<IFilter>> columnFilters = FilterUtils.toColumnFiltersMap(filters);
int scores[] = new int[indexs.size()];
for (int i = 0; i < scores.length; i++) {
scores[i] = initialScore;
}
for (int i = 0; i < indexs.size(); i++) {
// 目前不使用弱一致索引
if (!indexs.get(i).isStronglyConsistent()) {
scores[i] = Integer.MAX_VALUE;
continue;
}
KVIndexStat kvIndexStat = OptimizerContext.getContext()
.getStatManager()
.getKVIndex(indexs.get(i).getName());
List<ISelectable> indexColumns = OptimizerUtils.columnMetaListToIColumnList(indexs.get(i).getKeyColumns(),
tablename);
for (int j = 0; j < indexColumns.size(); j++) {
boolean isContain = false;
if (columnFilters.isEmpty()) {// 此时以columns为准
isContain = columns.contains(indexColumns.get(j));
} else {
isContain = columnFilters.containsKey(indexColumns.get(j));
}
if (isContain) {
scores[i] = (int) CostEsitimaterFactory.estimateRowCount(scores[i],
columnFilters.get((indexColumns.get(j))),
indexs.get(i),
kvIndexStat);
scores[i] -= 1; // 命中一个主键字段
} else {
break;
}
}
}
for (int i = 0; i < scores.length; i++) {
scores[i] = initialScore - scores[i];
}
int maxIndex = 0;
int maxScore = scores[maxIndex];
for (int i = 1; i < scores.length; i++) {
if (scores[i] > maxScore) {
maxIndex = i;
maxScore = scores[i];
}
}
if (maxScore == 0) {
return null;
}
return indexs.get(maxIndex);
}
示例2: getKeyAndValueFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 返回结果的List<IFilter> 0是keyFilter,1是valueFilter
*
* @param DNFNode
* @param indexs
* @param tablename
* @return
*/
public Map<FilterType, IFilter> getKeyAndValueFilter(IFilter filter, IndexMeta index) {
List<IFilter> DNFNode = FilterUtils.toDNFNode(filter);
Map<FilterType, IFilter> filters = new HashMap();
Map<Object, List<IFilter>> columnAndItsFilters = FilterUtils.toColumnFiltersMap(DNFNode);
List<ISelectable> indexKeyColumns = index == null ? new ArrayList<ISelectable>(0) : (OptimizerUtils.columnMetaListToIColumnList(index.getKeyColumns(),
index.getName()));
List<IFilter> indexQueryKeyFilters = new LinkedList<IFilter>();
List<IFilter> indexQueryValueFilters = new LinkedList<IFilter>();
// hbase索引需要前缀匹配
for (int i = 0; i < indexKeyColumns.size(); i++) {
boolean range = false;
List<IFilter> fs = columnAndItsFilters.get(indexKeyColumns.get(i));
List<IFilter> keyFilter = new ArrayList();
if (fs != null) {
for (IFilter f : fs) {
// filter右边不是常量的,不能走索引
if (((IBooleanFilter) f).getValue() != null
&& (((IBooleanFilter) f).getValue() instanceof ISelectable)) {
continue;
}
// 范围条件一个rowkey只能有一个,之后的列无法走索引了
switch (f.getOperation()) {
case EQ:
keyFilter.add(f);
break;
case LT:
case LT_EQ:
case GT:
case GT_EQ:
keyFilter.add(f);
range = true;
break;
default:
break;
}
}
fs.clear();
}
indexQueryKeyFilters.addAll(keyFilter);
// 不是前缀索引,不能用
if (keyFilter.isEmpty()) break;
if (range) break;
}
DNFNode.removeAll(indexQueryKeyFilters);
IFilter indexQueryKeyTree = FilterUtils.DNFToAndLogicTree(indexQueryKeyFilters);
IFilter indexQueryValueTree = FilterUtils.DNFToAndLogicTree(DNFNode);
filters.put(FilterType.IndexQueryValueFilter, indexQueryValueTree);
filters.put(FilterType.IndexQueryKeyFilter, indexQueryKeyTree);
return filters;
}