本文整理汇总了Java中com.taobao.tddl.optimizer.core.expression.IFilter.OPERATION.CONSTANT属性的典型用法代码示例。如果您正苦于以下问题:Java OPERATION.CONSTANT属性的具体用法?Java OPERATION.CONSTANT怎么用?Java OPERATION.CONSTANT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.taobao.tddl.optimizer.core.expression.IFilter.OPERATION
的用法示例。
在下文中一共展示了OPERATION.CONSTANT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shortestFilter
/**
* 将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);
}
示例2: shortestFilter
/**
* 将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);
}