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


Java IBooleanFilter.setColumn方法代码示例

本文整理汇总了Java中com.taobao.tddl.optimizer.core.expression.IBooleanFilter.setColumn方法的典型用法代码示例。如果您正苦于以下问题:Java IBooleanFilter.setColumn方法的具体用法?Java IBooleanFilter.setColumn怎么用?Java IBooleanFilter.setColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.taobao.tddl.optimizer.core.expression.IBooleanFilter的用法示例。


在下文中一共展示了IBooleanFilter.setColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildBooleanFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
protected void buildBooleanFilter(IBooleanFilter filter) {
    if (filter == null) {
        return;
    }

    Object column = filter.getColumn();
    Object value = filter.getValue();

    if (column instanceof ISelectable) {
        filter.setColumn(this.buildSelectable((ISelectable) column));
    }

    if (value instanceof ISelectable) {
        filter.setValue(this.buildSelectable((ISelectable) value));
    }

    if (value != null && value instanceof IFunction && ((IFunction) value).getArgs().size() > 0) {
        Object arg = ((IFunction) value).getArgs().get(0);
        if (arg instanceof QueryTreeNode) {
        }
    }

}
 
开发者ID:loye168,项目名称:tddl5,代码行数:24,代码来源:BaseShowNode.java

示例2: merge

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
/**
 * 将filter中的and/or条件中进行Range合并处理 <br/>
 * 
 * <pre>
 * 比如: 
 *  a. A =1 And A =2 ,永远false条件,返回EmptyResultFilterException异常
 *  b. (1 < A < 5) or (2 < A < 6),合并为 (1 < A < 6)
 *  c. A <= 1 or A = 1,永远true条件
 * </pre>
 */
public static IFilter merge(IFilter filter) throws EmptyResultFilterException {
    if (filter == null || filter instanceof IBooleanFilter) {
        return filter;
    }
    // 先转为DNF结构
    filter = toDNFAndFlat(filter);
    List<List<IFilter>> DNFNodes = toDNFNodesArray(filter);
    if (!needToMerge(DNFNodes)) {
        return filter;
    }

    DNFNodes = mergeOrDNFNodes(mergeAndDNFNodesArray(DNFNodes));
    if (DNFNodes == null || DNFNodes.isEmpty() || DNFNodes.get(0) == null || DNFNodes.get(0).isEmpty()
        || DNFNodes.get(0).get(0) == null) {
        // 返回常量true
        IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter();
        f.setOperation(OPERATION.CONSTANT);
        f.setColumn("1");
        f.setColumnName(ObjectUtils.toString("1"));
        return f;
    } else {
        return DNFToOrLogicTree(DNFNodes);
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:35,代码来源:FilterUtils.java

示例3: copyFilterToJoinOnColumns

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
/**
 * 将连接列上的约束复制到目标节点内
 * 
 * @param DNF 要复制的DNF filter
 * @param other 要复制的目标节点
 * @param qnColumns 源节点的join字段
 * @param otherColumns 目标节点的join字段
 * @throws QueryException
 */
private static List<IFilter> copyFilterToJoinOnColumns(List<IFilter> DNF, List<ISelectable> qnColumns,
                                                       List<ISelectable> otherColumns) throws QueryException {
    List<IFilter> newIFilterToPush = new LinkedList<IFilter>();
    for (IFilter bool : DNF) {
        int index = qnColumns.indexOf(((IBooleanFilter) bool).getColumn());
        if (index >= 0) {// 只考虑在源查找,在目标查找在上一层进行控制
            IBooleanFilter o = ASTNodeFactory.getInstance().createBooleanFilter().setOperation(bool.getOperation());
            o.setColumn(otherColumns.get(index));
            if (bool.getOperation() == OPERATION.IN) {
                o.setValues(((IBooleanFilter) bool).getValues());
            } else {
                o.setValue(((IBooleanFilter) bool).getValue());
            }
            newIFilterToPush.add(o);
        }
    }

    return newIFilterToPush;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:29,代码来源:FilterPusher.java

示例4: equal

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
/**
 * 创建equal filter
 */
public static IBooleanFilter equal(Object columnName, Object value) {
    IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter();
    f.setOperation(OPERATION.EQ);
    f.setColumn(columnName);
    f.setValue(value);
    return f;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:11,代码来源:FilterUtils.java

示例5: buildBooleanFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
public IBooleanFilter buildBooleanFilter(Object column, Object value, OPERATION operation, Expression exp) {
    IBooleanFilter ibf = ASTNodeFactory.getInstance().createBooleanFilter();
    ibf.setColumn(column);
    ibf.setValue(value);
    ibf.setOperation(operation);
    if (exp != null) {
        ibf.setColumnName(getSqlExprStr(exp)); // 比如将count(*)做为columnName
    }
    return ibf;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:11,代码来源:MySqlExprVisitor.java

示例6: buildBooleanFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
protected void buildBooleanFilter(IBooleanFilter filter, boolean findInSelectList) {
    if (filter == null) {
        return;
    }

    if (filter.getColumn() instanceof ISelectable) {
        filter.setColumn(this.buildSelectable((ISelectable) filter.getColumn(), findInSelectList));
    }

    if (filter.getColumn() instanceof QueryTreeNode) {
        // subQuery,比如WHERE ID = (SELECT ID FROM A)
        ((QueryTreeNode) filter.getColumn()).build();
    }

    if (filter.getValue() instanceof ISelectable) {
        filter.setValue(this.buildSelectable((ISelectable) filter.getValue(), findInSelectList));
    }

    if (filter.getValue() instanceof QueryTreeNode) {
        // subQuery,比如WHERE ID = (SELECT ID FROM A)
        ((QueryTreeNode) filter.getValue()).build();
    }

    if (filter.getOperation() == OPERATION.IN) {
        List<Object> values = filter.getValues();
        if (values != null && !values.isEmpty() && values.get(0) instanceof QueryTreeNode) {
            // in的子查询
            ((QueryTreeNode) values.get(0)).build();
        }
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:32,代码来源:QueryTreeNodeBuilder.java

示例7: buildConstanctFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
private static IBooleanFilter buildConstanctFilter(Object constant, String alias) {
    IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter();
    f.setOperation(OPERATION.CONSTANT);
    f.setColumn(constant);
    f.setColumnName(ObjectUtils.toString(constant));
    f.setAlias(alias);
    return f;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:9,代码来源:SubQueryPreProcessor.java

示例8: exchage

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的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:beebeandwer,项目名称:TDDL,代码行数:31,代码来源:FilterPreProcessor.java

示例9: getRecordFromRightByValueFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
protected Map<CloneableRecord, DuplicateKVPair> getRecordFromRightByValueFilter(List<CloneableRecord> leftJoinOnColumnCache)
                                                                                                                            throws TddlException {

    right_cursor.beforeFirst();
    if (isLeftOutJoin() && this.rightCursorMeta == null) {
        IRowSet kv = right_cursor.next();
        if (kv != null) {
            this.rightCursorMeta = kv.getParentCursorMeta();
        } else {
            rightCursorMeta = CursorMetaImp.buildNew(right_cursor.getReturnColumns());
        }

        right_cursor.beforeFirst();
    }

    IBooleanFilter ibf = ASTNodeFactory.getInstance().createBooleanFilter();
    ibf.setOperation(OPERATION.IN);
    ibf.setValues(new ArrayList<Object>());
    for (CloneableRecord record : leftJoinOnColumnCache) {
        Map<String, Object> recordMap = record.getMap();
        if (recordMap.size() == 1) {
            // 单字段in
            Entry<String, Object> entry = recordMap.entrySet().iterator().next();
            Object comp = entry.getValue();
            ibf.setColumn(this.rightJoinOnColumns.get(0).copy());
            ibf.getValues().add(comp);
        } else {
            // 多字段in
            if (ibf.getColumn() == null) {
                ibf.setColumn(buildRowFunction(recordMap.keySet(), true, record));
            }

            ibf.getValues().add(buildRowFunction(recordMap.values(), false, record));
        }
    }

    IColumn rightColumn = (IColumn) this.rightJoinOnColumns.get(0);
    IValueFilterCursor vfc = this.cursorFactory.valueFilterCursor(executionContext, right_cursor, ibf);

    Map<CloneableRecord, DuplicateKVPair> records = new HashMap();
    if (isLeftOutJoin() && !isRightOutJoin()) {
        blockNestedLoopJoin(leftJoinOnColumnCache, rightColumn, vfc, records);
    } else if (!isLeftOutJoin() && !isRightOutJoin()) {
        // inner join
        blockNestedLoopJoin(leftJoinOnColumnCache, rightColumn, vfc, records);
    } else {
        throw new UnsupportedOperationException("leftOutJoin:" + isLeftOutJoin() + " ; rightOutJoin:"
                                                + isRightOutJoin());
    }
    return records;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:52,代码来源:BlockNestedtLoopCursor.java

示例10: mgetWithDuplicate

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
@Override
public Map<CloneableRecord, DuplicateKVPair> mgetWithDuplicate(List<CloneableRecord> keys, boolean prefixMatch,
                                                               boolean keyFilterOrValueFilter) throws TddlException {
    init();
    if (prefixMatch) {
        throw new UnsupportedOperationException("not supported yet");
    } else {
        // 这里列的别名也丢了吧 似乎解决了
        IQuery iquery = (IQuery) merge.getSubNode();
        OptimizerContext optimizerContext = OptimizerContext.getContext();
        IBooleanFilter ibf = ASTNodeFactory.getInstance().createBooleanFilter();
        ibf.setOperation(OPERATION.IN);
        ibf.setValues(new ArrayList<Object>());
        String colName = null;
        for (CloneableRecord record : keys) {
            Map<String, Object> recordMap = record.getMap();
            if (recordMap.size() == 1) {
                // 单字段in
                Entry<String, Object> entry = recordMap.entrySet().iterator().next();
                Object comp = entry.getValue();
                colName = entry.getKey();
                IColumn col = ASTNodeFactory.getInstance()
                    .createColumn()
                    .setColumnName(colName)
                    .setDataType(record.getType(0));

                col.setTableName(iquery.getAlias());
                ibf.setColumn(col);
                ibf.getValues().add(comp);
            } else {
                // 多字段in
                if (ibf.getColumn() == null) {
                    ibf.setColumn(buildRowFunction(recordMap.keySet(), true, record));
                }

                ibf.getValues().add(buildRowFunction(recordMap.values(), false, record));

            }
        }

        KVIndexNode query = (KVIndexNode) OptimizerUtils.convertPlanToAst(iquery);
        if (keyFilterOrValueFilter) {
            query.keyQuery(FilterUtils.and(removeDupFilter(query.getKeyFilter(), ibf), ibf));
        } else {
            query.valueQuery(FilterUtils.and(removeDupFilter(query.getResultFilter(), ibf), ibf));
        }
        query.build();
        // 优化做法,将数据分配掉。
        Integer currentThread = merge.getThread();
        executionContext.getExtraCmds().put("initThread", currentThread);
        IDataNodeExecutor idne = optimizerContext.getOptimizer().optimizePlan(query,
            executionContext.getParams(),
            executionContext.getExtraCmds());

        ISchematicCursor cursor = null;
        Map<CloneableRecord, DuplicateKVPair> duplicateKeyMap = null;
        try {

            cursor = ExecutorContext.getContext().getTopologyExecutor().execByExecPlanNode(idne, executionContext);
            // 用于关闭,统一管理
            this.returnColumns = cursor.getReturnColumns();
            List<IColumn> cols = new ArrayList<IColumn>();
            if (ibf.getColumn() instanceof IColumn) {
                cols.add((IColumn) ibf.getColumn());
            } else {
                cols.addAll(((IFunction) ibf.getColumn()).getArgs());
            }
            duplicateKeyMap = buildDuplicateKVPairMap(cols, cursor);
        } finally {
            if (cursor != null) {
                List<TddlException> exs = new ArrayList();
                exs = cursor.close(exs);
                if (!exs.isEmpty()) {
                    throw GeneralUtil.mergeException(exs);
                }
            }
        }
        return duplicateKeyMap;
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:81,代码来源:MergeCursor.java

示例11: mgetWithDuplicate

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

    IQuery tmpQuery = (IQuery) query.copy();
    IBooleanFilter ibf = ASTNodeFactory.getInstance().createBooleanFilter();
    ibf.setOperation(OPERATION.IN);
    ibf.setValues(new ArrayList<Object>());
    String colName = null;
    for (CloneableRecord record : keys) {
        Map<String, Object> recordMap = record.getMap();
        if (recordMap.size() == 1) {
            // 单字段in
            Entry<String, Object> entry = recordMap.entrySet().iterator().next();
            Object comp = entry.getValue();
            colName = entry.getKey();
            IColumn col = ASTNodeFactory.getInstance()
                .createColumn()
                .setColumnName(colName)
                .setDataType(record.getType(0));

            col.setTableName(tmpQuery.getAlias());
            ibf.setColumn(col);
            ibf.getValues().add(comp);
        } else {
            // 多字段in
            if (ibf.getColumn() == null) {
                ibf.setColumn(buildRowFunction(recordMap.keySet(), true, record));
            }

            ibf.getValues().add(buildRowFunction(recordMap.values(), false, record));

        }
    }

    tmpQuery.setKeyFilter(FilterUtils.and(tmpQuery.getKeyFilter(), ibf));
    myJdbcHandler.setPlan(tmpQuery);
    try {
        myJdbcHandler.executeQuery(this.meta, isStreaming);
    } catch (SQLException e) {
        throw new TddlException(e);
    }

    buildReturnColumns();
    Map<CloneableRecord, DuplicateKVPair> res = buildDuplicateKVPair(keys);
    return res;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:48,代码来源:My_Cursor.java

示例12: buildFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
/**
 * 根据range结果,构造filter
 * 
 * @param range
 * @param column
 * @return
 */
protected List<IFilter> buildFilter(Range range, Object column) {
    List<IFilter> filters = new ArrayList(2);
    if (range == null) {
        return filters;
    }

    if (range.isSingleValue()) {
        IBooleanFilter en = ASTNodeFactory.getInstance().createBooleanFilter().setOperation(OPERATION.EQ);
        en.setColumn(column);
        en.setValue(range.getMaxValue());
        filters.add(en);
        return filters;
    }

    if (range.getMinValue() != null) {
        IBooleanFilter gn;
        if (range.isMinIncluded()) {
            gn = ASTNodeFactory.getInstance().createBooleanFilter().setOperation(OPERATION.GT_EQ);
        } else {
            gn = ASTNodeFactory.getInstance().createBooleanFilter().setOperation(OPERATION.GT);
        }

        gn.setColumn(column);
        gn.setValue(range.getMinValue());
        filters.add(gn);
    }

    if (range.getMaxValue() != null) {
        IBooleanFilter ln;
        if (range.isMaxIncluded()) {
            ln = ASTNodeFactory.getInstance().createBooleanFilter().setOperation(OPERATION.LT_EQ);
        } else {
            ln = ASTNodeFactory.getInstance().createBooleanFilter().setOperation(OPERATION.LT);
        }

        ln.setColumn(column);
        ln.setValue(range.getMaxValue());
        filters.add(ln);
    }
    return filters;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:49,代码来源:AbstractRangeProcessor.java

示例13: shortestFilter

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的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);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:54,代码来源:FilterPreProcessor.java

示例14: convertJoinOnColumns

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
private IBooleanFilter convertJoinOnColumns(IBooleanFilter filter) {
    IBooleanFilter newbf = filter.copy();
    newbf.setColumn(filter.getValue());
    newbf.setValue((Comparable) filter.getColumn());
    return newbf;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:7,代码来源:JoinPermutationGenerator.java

示例15: buildJoinKeys

import com.taobao.tddl.optimizer.core.expression.IBooleanFilter; //导入方法依赖的package包/类
private void buildJoinKeys() {
    if (this.getNode().isUedForIndexJoinPK()) {
        return;
    }
    List<IBooleanFilter> otherJoinOnFilters = new ArrayList(this.getNode().getJoinFilter().size());
    for (IBooleanFilter f : this.getNode().getJoinFilter()) {
        ISelectable leftKey = null;
        if (f.getColumn() != null && f.getColumn() instanceof ISelectable) {
            leftKey = this.getColumnFromOtherNode((ISelectable) f.getColumn(), this.getNode().getLeftNode());
        }

        ISelectable rightKey = null;
        if (f.getValue() != null && f.getValue() instanceof ISelectable) {
            rightKey = this.getColumnFromOtherNode((ISelectable) f.getValue(), this.getNode().getRightNode());
        }

        // 可能顺序调换了,重新找一次
        if (leftKey == null || rightKey == null) {
            if (f.getValue() != null && f.getValue() instanceof ISelectable) {
                leftKey = this.getColumnFromOtherNode((ISelectable) f.getValue(), this.getNode().getLeftNode());
            }

            if (f.getColumn() != null && f.getColumn() instanceof ISelectable) {
                rightKey = this.getColumnFromOtherNode((ISelectable) f.getColumn(), this.getNode().getRightNode());
            }
        }

        if (leftKey == null || rightKey == null) {
            // 可能有以下情况
            // id=1,s.id=s.key_id
            IFilter otherJoinOnFilter = this.getNode().getOtherJoinOnFilter();
            otherJoinOnFilter = FilterUtils.and(otherJoinOnFilter, f);
            this.getNode().setOtherJoinOnFilter(otherJoinOnFilter);
            otherJoinOnFilters.add(f);
            continue;
        }

        /**
         * 如果是回表操作,不能把索引的joinKey添加到temp中,否则如果有merge,这个列会被加到sql的select中,
         * 而导致找不到列
         */
        if (!this.getNode().isUedForIndexJoinPK()) {
            f.setColumn(buildSelectable(leftKey));
            f.setValue(buildSelectable(rightKey));
        }

    }

    this.getNode().getJoinFilter().removeAll(otherJoinOnFilters);
    this.buildFilter(this.getNode().getOtherJoinOnFilter(), false);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:52,代码来源:JoinNodeBuilder.java


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