本文整理汇总了Java中com.taobao.tddl.optimizer.utils.FilterUtils.toDNFNodesArray方法的典型用法代码示例。如果您正苦于以下问题:Java FilterUtils.toDNFNodesArray方法的具体用法?Java FilterUtils.toDNFNodesArray怎么用?Java FilterUtils.toDNFNodesArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.utils.FilterUtils
的用法示例。
在下文中一共展示了FilterUtils.toDNFNodesArray方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeDupFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 合并两个条件去除重复的key条件,比如构造了id in (xxx)的请求后,原先条件中有可能也存在id的条件,这时需要替换原先的id条件
*
* @param srcFilter
* @param mergeFilter
*/
private IFilter removeDupFilter(IFilter srcFilter, IBooleanFilter inFilter) {
List<List<IFilter>> filters = FilterUtils.toDNFNodesArray(srcFilter);
List<List<IFilter>> newFilters = new ArrayList<List<IFilter>>();
for (List<IFilter> sf : filters) {
List<IFilter> newSf = new ArrayList<IFilter>();
for (IFilter f : sf) {
Object column = FilterUtils.getFilterColumn(f);
if (!column.equals(inFilter.getColumn())) {
newSf.add(f);
}
}
newFilters.add(newSf);
}
return FilterUtils.DNFToOrLogicTree(newFilters);
}
示例2: removeDupFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 合并两个条件去除重复的key条件,比如构造了id in (xxx)的请求后,原先条件中有可能也存在id的条件,这时需要替换原先的id条件
*
* @param srcFilter
* @param mergeFilter
*/
private IFilter removeDupFilter(IFilter srcFilter, IBooleanFilter inFilter) {
List<List<IFilter>> filters = FilterUtils.toDNFNodesArray(srcFilter);
List<List<IFilter>> newFilters = new ArrayList<List<IFilter>>();
for (List<IFilter> sf : filters) {
List<IFilter> newSf = new ArrayList<IFilter>();
for (IFilter f : sf) {
if (!((IBooleanFilter) f).getColumn().equals(inFilter.getColumn())) {
newSf.add(f);
}
}
newFilters.add(newSf);
}
return FilterUtils.DNFToOrLogicTree(newFilters);
}
示例3: buildTableFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
private static void buildTableFilter(TableNode tableNode) {
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(tableNode.getWhereFilter());
if (DNFNodes.size() == 1) {
// 即使索引没有选择主键,但是有的filter依旧会在s主键上进行,作为valueFilter,所以要把主键也传进去
Map<FilterType, IFilter> filters = FilterSpliter.splitByIndex(DNFNodes.get(0), tableNode);
tableNode.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
tableNode.setResultFilter(filters.get(FilterType.ResultFilter));
tableNode.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
tableNode.query((IFilter) null);// 清空where
} else {
// 如果存在多个合取方式的的or组合时,无法区分出key/indexValue/result,直接下推
tableNode.setResultFilter(tableNode.getWhereFilter());
tableNode.query((IFilter) null);// 清空where
}
}
示例4: buildTableFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
private static void buildTableFilter(TableNode tableNode) {
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(tableNode.getWhereFilter());
if (DNFNodes.size() == 1) {
// 即使索引没有选择主键,但是有的filter依旧会在s主键上进行,作为valueFilter,所以要把主键也传进去
Map<FilterType, IFilter> filters = FilterSpliter.splitByIndex(DNFNodes.get(0), tableNode);
tableNode.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
tableNode.setResultFilter(filters.get(FilterType.ResultFilter));
tableNode.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
} else {
// 如果存在多个合取方式的的or组合时,无法区分出key/indexValue/result,直接下推
tableNode.setResultFilter(tableNode.getWhereFilter());
}
}
示例5: splitByDNF
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 根据where中的所有条件按照or进行分隔,生成多个query请求. (主要考虑部分存储引擎不支持or语法)
*/
public static List<QueryTreeNode> splitByDNF(TableNode node, Map<String, Object> extraCmd) {
if (node.getWhereFilter() == null) {
return new LinkedList<QueryTreeNode>();
}
if (!FilterUtils.isDNF(node.getWhereFilter())) {
throw new IllegalArgumentException("not dnf!!! fuck!!\n" + node.getWhereFilter());
}
List<QueryTreeNode> subQueries = new LinkedList<QueryTreeNode>();
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(node.getWhereFilter());
// 判断是否要处理OR转化为index merge,比如mysql可以push
// 比如hbase/bdb这一类,OR条件目前只能是主键索引,由执行器层面去解决
// 如果涉及多字段时就需要拆分为index merge,同时做uniq
boolean needCopy = (DNFNodes.size() > 1);
if (isOptimizeIndexMerge(extraCmd) || DNFNodes.size() == 1) {
for (List<IFilter> DNFNode : DNFNodes) {
List columns = Arrays.asList(FilterUtils.toColumnFiltersMap(DNFNode).keySet().toArray());
String tablename = node.getTableName();
IndexMeta index = IndexChooser.findBestIndex(node.getTableMeta(), columns, DNFNode, tablename, extraCmd);
if (index == null) {
index = node.getTableMeta().getPrimaryIndex();
}
// 如果找不到对应条件的主键,可能需要全表扫描
TableNode subQuery = node;
if (needCopy) {
subQuery = node.deepCopy();
}
subQuery.useIndex(index);
if (index == null) {// 如果无主键进行全表扫描
subQuery.setFullTableScan(true);
} else {
subQuery.query((IFilter) null);// 清空where
}
Map<FilterType, IFilter> filters = splitByIndex(DNFNode, subQuery);
subQuery.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
subQuery.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
subQuery.setResultFilter(filters.get(FilterType.ResultFilter));
subQueries.add(subQuery);
}
} else {
node.useIndex(node.getTableMeta().getPrimaryIndex());// 默认选中主键
node.setResultFilter(node.getWhereFilter());
}
return subQueries;
}
示例6: shortestFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 将0=1/1=1/true的恒等式进行优化
*/
private static IFilter shortestFilter(IFilter root) throws EmptyResultFilterException {
IFilter filter = FilterUtils.toDNFAndFlat(root);
List<List<IFilter>> DNFfilter = FilterUtils.toDNFNodesArray(filter);
List<List<IFilter>> newDNFfilter = new ArrayList<List<IFilter>>();
for (List<IFilter> andDNFfilter : DNFfilter) {
boolean isShortest = false;
List<IFilter> newAndDNFfilter = new ArrayList<IFilter>();
for (IFilter one : andDNFfilter) {
if (one.getOperation() == OPERATION.CONSTANT) {
boolean flag = false;
if (((IBooleanFilter) one).getColumn() instanceof ISelectable) {// 可能是个not函数
newAndDNFfilter.add(one);// 不能丢弃
} else {
Object value = ((IBooleanFilter) one).getColumn();
if (value == null) {
flag = false;
} else if (value.getClass() == Boolean.class || value.getClass() == boolean.class) {
flag = (Boolean) value;
} else {
// mysql中字符串'true'会被当作0处理
flag = (DataType.LongType.convertFrom(value) != 0);
}
// if (StringUtils.isNumeric(value)) {
// flag =
// BooleanUtils.toBoolean(Integer.valueOf(value));
// } else {
// flag = BooleanUtils.toBoolean(((IBooleanFilter)
// one).getColumn().toString());
// }
if (!flag) {
isShortest = true;
break;
}
}
} else {
newAndDNFfilter.add(one);
}
}
if (!isShortest) {
if (newAndDNFfilter.isEmpty()) {
// 代表出现为true or xxx,直接返回true
IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter();
f.setOperation(OPERATION.CONSTANT);
f.setColumn("1");
f.setColumnName(ObjectUtils.toString("1"));
return f;
} else {// 针对非false的情况
newDNFfilter.add(newAndDNFfilter);
}
}
}
if (newDNFfilter.isEmpty()) {
throw new EmptyResultFilterException();
}
return FilterUtils.DNFToOrLogicTree(newDNFfilter);
}
示例7: addOtherJoinFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
private void addOtherJoinFilter(JoinNode jn, String filter) {
IFilter f = FilterUtils.createFilter(filter);
f = FilterPreProcessor.processFilter(f, true, null);
List<List<IFilter>> DNFFilters = FilterUtils.toDNFNodesArray(FilterUtils.toDNFAndFlat(f));
jn.setOtherJoinOnFilter(FilterUtils.DNFToOrLogicTree(DNFFilters));
}
示例8: splitByDNF
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 根据where中的所有条件按照or进行分隔,生成多个query请求. (主要考虑部分存储引擎不支持or语法)
*/
public static List<QueryTreeNode> splitByDNF(TableNode node, Map<String, Object> extraCmd) throws QueryException {
if (node.getWhereFilter() == null) {
return new LinkedList<QueryTreeNode>();
}
if (!FilterUtils.isDNF(node.getWhereFilter())) {
throw new IllegalArgumentException("not dnf!!! fuck!!\n" + node.getWhereFilter());
}
List<QueryTreeNode> subQueries = new LinkedList<QueryTreeNode>();
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(node.getWhereFilter());
// 判断是否要处理OR转化为index merge,比如mysql可以push
// 比如hbase/bdb这一类,OR条件目前只能是主键索引,由执行器层面去解决
// 如果涉及多字段时就需要拆分为index merge,同时做uniq
boolean needCopy = (DNFNodes.size() > 1);
if (isOptimizeIndexMerge(extraCmd) || DNFNodes.size() == 1) {
for (List<IFilter> DNFNode : DNFNodes) {
List columns = Arrays.asList(FilterUtils.toColumnFiltersMap(DNFNode).keySet().toArray());
String tablename = node.getTableName();
IndexMeta index = IndexChooser.findBestIndex(node.getTableMeta(), columns, DNFNode, tablename, extraCmd);
if (index == null) {
index = node.getTableMeta().getPrimaryIndex();
}
// 如果找不到对应条件的主键,可能需要全表扫描
TableNode subQuery = node;
if (needCopy) {
subQuery = node.deepCopy();
}
subQuery.useIndex(index);
if (index == null) {// 如果无主键进行全表扫描
subQuery.setFullTableScan(true);
}
Map<FilterType, IFilter> filters = splitByIndex(DNFNode, subQuery);
subQuery.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
subQuery.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
subQuery.setResultFilter(filters.get(FilterType.ResultFilter));
subQueries.add(subQuery);
}
} else {
node.useIndex(node.getTableMeta().getPrimaryIndex());// 默认选中主键
node.setResultFilter(node.getWhereFilter());
}
return subQueries;
}
示例9: shortestFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
/**
* 将0=1/1=1/true的恒等式进行优化
*/
private static IFilter shortestFilter(IFilter root) throws EmptyResultFilterException {
IFilter filter = FilterUtils.toDNFAndFlat(root);
List<List<IFilter>> DNFfilter = FilterUtils.toDNFNodesArray(filter);
List<List<IFilter>> newDNFfilter = new ArrayList<List<IFilter>>();
for (List<IFilter> andDNFfilter : DNFfilter) {
boolean isShortest = false;
List<IFilter> newAndDNFfilter = new ArrayList<IFilter>();
for (IFilter one : andDNFfilter) {
if (one.getOperation() == OPERATION.CONSTANT) {
boolean flag = false;
if (((IBooleanFilter) one).getColumn() instanceof ISelectable) {// 可能是个not函数
newAndDNFfilter.add(one);// 不能丢弃
} else {
String value = ((IBooleanFilter) one).getColumn().toString();
if (StringUtils.isNumeric(value)) {
flag = BooleanUtils.toBoolean(Integer.valueOf(value));
} else {
flag = BooleanUtils.toBoolean(((IBooleanFilter) one).getColumn().toString());
}
if (!flag) {
isShortest = true;
break;
}
}
} else {
newAndDNFfilter.add(one);
}
}
if (!isShortest) {
if (newAndDNFfilter.isEmpty()) {
// 代表出现为true or xxx,直接返回true
IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter();
f.setOperation(OPERATION.CONSTANT);
f.setColumn("1");
f.setColumnName(ObjectUtils.toString("1"));
return f;
} else {// 针对非false的情况
newDNFfilter.add(newAndDNFfilter);
}
}
}
if (newDNFfilter.isEmpty()) {
throw new EmptyResultFilterException("空结果");
}
return FilterUtils.DNFToOrLogicTree(newDNFfilter);
}
示例10: addOtherJoinFilter
import com.taobao.tddl.optimizer.utils.FilterUtils; //导入方法依赖的package包/类
private void addOtherJoinFilter(JoinNode jn, String filter) {
IFilter f = FilterUtils.createFilter(filter);
List<List<IFilter>> DNFFilters = FilterUtils.toDNFNodesArray(FilterUtils.toDNFAndFlat(f));
jn.setOtherJoinOnFilter(FilterUtils.DNFToAndLogicTree(DNFFilters.get(0)));
}