当前位置: 首页>>代码示例>>Java>>正文


Java FilterUtils类代码示例

本文整理汇总了Java中com.taobao.tddl.optimizer.utils.FilterUtils的典型用法代码示例。如果您正苦于以下问题:Java FilterUtils类的具体用法?Java FilterUtils怎么用?Java FilterUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FilterUtils类属于com.taobao.tddl.optimizer.utils包,在下文中一共展示了FilterUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:24,代码来源:MergeCursor.java

示例2: build

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
private void build(TableNode table) {
    table.build();

    Map<String, Object> extraCmd = new HashMap<String, Object>();
    extraCmd.put(ConnectionProperties.CHOOSE_INDEX, true);
    IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
        new ArrayList<ISelectable>(),
        FilterUtils.toDNFNode(table.getWhereFilter()),
        table.getTableName(),
        extraCmd);

    table.useIndex(index);

    Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
        table);

    table.setKeyFilter(result.get(FilterType.IndexQueryKeyFilter));
    table.setIndexQueryValueFilter(result.get(FilterType.IndexQueryValueFilter));
    table.setResultFilter(result.get(FilterType.ResultFilter));
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:21,代码来源:JoinChooserTest.java

示例3: 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);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:23,代码来源:MergeCursor.java

示例4: findComparisonsSubQueryToJoinNode

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
/**
 * 处理下 = in的子查询转化为join
 * http://dev.mysql.com/doc/refman/5.0/en/comparisons-using-subqueries.html
 */
private static QueryTreeNode findComparisonsSubQueryToJoinNode(QueryTreeNode qtn) {
    for (int i = 0; i < qtn.getChildren().size(); i++) {
        ASTNode ast = qtn.getChildren().get(i);
        if (!(ast instanceof QueryTreeNode)) {
            continue;
        }

        qtn.getChildren().set(i, findComparisonsSubQueryToJoinNode((QueryTreeNode) ast));
    }

    SubQueryAndFilter find = new SubQueryAndFilter();
    find.query = qtn;
    find.filter = null;
    SubQueryAndFilter result = buildSubQuery(find,
        qtn.getWhereFilter(),
        !FilterUtils.isCNFNode(qtn.getWhereFilter()));
    if (result != find) {
        // 如果出现filter,代表where条件中没有组合条件,只有单自查询的条件,直接替换即可
        result.query.query(result.filter);
        qtn.query("");
        return result.query;
    } else {
        return qtn; // 没变化
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:30,代码来源:SubQueryPreProcessor.java

示例5: build

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
private void build(TableNode table) {
    table.build();

    Map<String, Object> extraCmd = new HashMap<String, Object>();
    extraCmd.put(ExtraCmd.CHOOSE_INDEX, true);
    IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
        new ArrayList<ISelectable>(),
        FilterUtils.toDNFNode(table.getWhereFilter()),
        table.getTableName(),
        extraCmd);

    table.useIndex(index);

    Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
        table);

    table.setKeyFilter(result.get(FilterType.IndexQueryKeyFilter));
    table.setIndexQueryValueFilter(result.get(FilterType.IndexQueryValueFilter));
    table.setResultFilter(result.get(FilterType.ResultFilter));
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:21,代码来源:JoinChooserTest.java

示例6: 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
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:16,代码来源:JoinChooser.java

示例7: processFilter

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
public static IFilter processFilter(IFilter root, boolean typeConvert, Map<String, Object> extraCmd) {
    if (root == null) {
        return null;
    }

    root = processOneFilter(root, typeConvert, extraCmd); // 做一下转换处理
    root = processGroupFilter(root, extraCmd); // 合并一下or group
    root = shortestFilter(root); // 短路一下
    root = FilterUtils.merge(root);// 合并一下flter
    return root;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:12,代码来源:FilterPreProcessor.java

示例8: getSubGroupColumn

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
private static ISelectable getSubGroupColumn(ILogicalFilter parent, int index, Map<String, Object> extraCmd) {
    IFilter filter = parent.getSubFilter().get(index);
    if (filter.getOperation().equals(OPERATION.OR)) {
        filter = processGroupFilter(filter, extraCmd);
        parent.getSubFilter().set(index, filter);
        if (filter instanceof ILogicalFilter) {
            // 不符合传递性,直接退出
            return null;
        }
    }

    if (filter instanceof IBooleanFilter) {
        if (FilterUtils.isConstValue(((IBooleanFilter) filter).getColumn())) {
            // 列是常量
            return null;
        }

        if (!FilterUtils.isConstValue(((IBooleanFilter) filter).getValue())) {
            // value非常量
            return null;
        }

        return (ISelectable) ((IBooleanFilter) filter).getColumn();
    } else if (filter instanceof IGroupFilter) {
        return (ISelectable) ((IGroupFilter) filter).getColumn();
    }

    return null;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:30,代码来源:FilterPreProcessor.java

示例9: exchage

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
/**
 * 如果是1 = id的情况,转化为id = 1
 */
private static IFilter exchage(IFilter root) {
    IBooleanFilter bf = (IBooleanFilter) root;
    if (!FilterUtils.isConstValue(bf.getValue()) && FilterUtils.isConstValue(bf.getColumn())) {
        Object val = bf.getColumn();
        bf.setColumn(bf.getValue());
        bf.setValue(val);
        OPERATION newOp = bf.getOperation();
        switch (bf.getOperation()) {
            case GT:
                newOp = OPERATION.LT;
                break;
            case LT:
                newOp = OPERATION.GT;
                break;
            case GT_EQ:
                newOp = OPERATION.LT_EQ;
                break;
            case LT_EQ:
                newOp = OPERATION.GT_EQ;
                break;
            default:
                break;
        }
        bf.setOperation(newOp);
    }
    return bf;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:31,代码来源:FilterPreProcessor.java

示例10: expandIn

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
private static IFilter expandIn(IFilter root, Map<String, Object> extraCmd) {
    IBooleanFilter bf = (IBooleanFilter) root;
    if (bf.getOperation() == OPERATION.IN && isExpandIn(extraCmd)) {
        List<Object> values = bf.getValues();
        IFilter newRoot = null;
        for (Object value : values) {
            newRoot = FilterUtils.or(newRoot, FilterUtils.equal(bf.getColumn(), value));
        }

        return newRoot;
    } else {
        return root;
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:15,代码来源:FilterPreProcessor.java

示例11: addResultFilter

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
public void addResultFilter(IBooleanFilter filter) {
    if (this.resultFilter == null) {
        this.resultFilter = filter;
        return;
    }

    this.resultFilter = FilterUtils.and(this.resultFilter, filter);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:9,代码来源:QueryTreeNode.java

示例12: TableNode

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
@Test
public void test_主键索引条件() {
    TableNode table = new TableNode("TABLE1");
    table.query("ID = 1");
    build(table);

    Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
        table);
    Assert.assertEquals("TABLE1.ID = 1", result.get(FilterType.IndexQueryKeyFilter).toString());
    Assert.assertEquals(null, result.get(FilterType.IndexQueryValueFilter));
    Assert.assertEquals(null, result.get(FilterType.ResultFilter));
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:13,代码来源:FilterSpliterTest.java

示例13: build

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
private void build(TableNode table) {
    table.build();

    Map<String, Object> extraCmd = new HashMap<String, Object>();
    extraCmd.put(ConnectionProperties.CHOOSE_INDEX, true);
    IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
        new ArrayList<ISelectable>(),
        FilterUtils.toDNFNode(table.getWhereFilter()),
        table.getTableName(),
        extraCmd);

    table.useIndex(index);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:14,代码来源:FilterSpliterTest.java

示例14: TableNode

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
@Test
public void test_路径短化_组合() {
    TableNode table = new TableNode("TABLE1");
    table.query("(1 AND (ID = 1 OR ID = 2) AND NAME = 'HELLO') OR (0 AND 1) OR (ID = 3)");
    table.build();
    FilterPreProcessor.optimize(table, true, null);
    System.out.println(FilterUtils.toDNFAndFlat(table.getWhereFilter()));
    Assert.assertEquals(table.getWhereFilter().toString(),
        "((TABLE1.ID = 1 AND TABLE1.NAME = HELLO) OR (TABLE1.ID = 2 AND TABLE1.NAME = HELLO) OR TABLE1.ID = 3)");
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:11,代码来源:FilterPreProcessorTest.java

示例15: mgetWithDuplicate

import com.taobao.tddl.optimizer.utils.FilterUtils; //导入依赖的package包/类
@Override
public Map<CloneableRecord, DuplicateKVPair> mgetWithDuplicate(List<CloneableRecord> keys, boolean prefixMatch,
                                                               boolean keyFilterOrValueFilter) throws TddlException {

    IQuery tmpQuery = (IQuery) query.copy();
    List<Object> values = new ArrayList<Object>();
    String cm = keys.get(0).getColumnList().get(0);
    for (CloneableRecord key : keys) {
        values.add(key.get(cm));
    }
    IColumn ic = ASTNodeFactory.getInstance().createColumn();
    ic.setColumnName(cm);

    IBooleanFilter targetFilter = ASTNodeFactory.getInstance().createBooleanFilter();
    targetFilter.setOperation(OPERATION.IN);
    targetFilter.setColumn(ic);
    targetFilter.setValues(values);

    tmpQuery.setKeyFilter(FilterUtils.and(tmpQuery.getKeyFilter(), targetFilter));

    myJdbcHandler.setPlan(tmpQuery);
    try {
        myJdbcHandler.executeQuery(this.meta, isStreaming);
    } catch (SQLException e) {
        throw new TddlException(e);
    }
    Map<CloneableRecord, DuplicateKVPair> res = buildDuplicateKVPair(keys);
    return res;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:30,代码来源:My_Cursor.java


注:本文中的com.taobao.tddl.optimizer.utils.FilterUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。