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


Java IQuery.getSubQuery方法代码示例

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


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

示例1: canComposeOneSql

import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入方法依赖的package包/类
protected boolean canComposeOneSql(IDataNodeExecutor executor) {
    if (executor instanceof IQuery) {
        IQuery iq = (IQuery) executor;
        IQueryTree iqc = iq.getSubQuery();
        if (iqc == null) {
            return true;
        }
        String groupNode1 = iq.getDataNode();
        String groupNode2 = iqc.getDataNode();
        if (TStringUtil.equals(groupNode1, groupNode2)) {
            return isConsistent(iqc, groupNode1);
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:QueryMyHandler.java

示例2: isConsistent

import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入方法依赖的package包/类
private boolean isConsistent(IQueryTree iqc, String groupNode1) {
    if (iqc instanceof IQuery) {
        IQuery iq = (IQuery) iqc;
        IQueryTree iqc1 = iq.getSubQuery();
        if (iqc1 == null) {
            return true;
        } else {
            String groupNode2 = iqc.getDataNode();
            if (TStringUtil.equals(groupNode1, groupNode2)) {
                return isConsistent(iqc, groupNode1);
            } else {
                return false;
            }
        }
    } else {
        return false;
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:QueryMyHandler.java

示例3: visit

import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入方法依赖的package包/类
@Override
public void visit(IQuery query) {
    if (query.isSubQuery() && !query.isTopQuery()) {
        sqlBuilder.append(" ( ");
    }
    if (query.isSubQuery() || query.isTopQuery()) {
        buildSelect(query);

        if (query.getTableName() == null && query.getSubQuery() == null) {
            return;
        }
        sqlBuilder.append(" from ");
    }

    if (query.getTableName() != null) {

        if (EagleeyeHelper.isTestMode()) {
            sqlBuilder.append(EagleeyeHelper.ALL_PERF_TABLE_PREFIX);
        }
        sqlBuilder.append(query.getTableName());

        if (!query.isSubQuery() && query.getAlias() != null
            && !query.getAlias().equalsIgnoreCase(query.getTableName())) {
            sqlBuilder.append(" ").append(query.getAlias());
        }
    } else if (query.getSubQuery() != null) {
        sqlBuilder.append(this.getNewVisitor(query.getSubQuery(), query.getSubQuery()).getString());
    }

    if (query.isSubQuery() || query.isTopQuery()) {
        String keyFilterStr = "";

        IFilter whereFilter = FilterUtils.and(FilterUtils.and(query.getKeyFilter(), query.getValueFilter()),
            query.getOtherJoinOnFilter());

        if (whereFilter != null) {
            MysqlPlanVisitorImpl visitor = this.getNewVisitor(whereFilter);
            keyFilterStr = visitor.getString();
        }

        if (!TStringUtil.isEmpty(keyFilterStr)) {
            sqlBuilder.append(" where ");
            sqlBuilder.append(keyFilterStr);
        }
        buildGroupBy(query);
        buildHaving(query);
        buildOrderBy(query);
        buildLimit(query);

        switch (query.getLockMode()) {
            case EXCLUSIVE_LOCK:
                sqlBuilder.append(" FOR UPDATE");
                break;
            case SHARED_LOCK:
                sqlBuilder.append(" LOCK IN SHARE MODE");
                break;
            default:
                break;
        }
    }

    if (query.isSubQuery() && !query.isTopQuery()) {
        sqlBuilder.append(" ) ");
        if (query.getAlias() != null) {
            sqlBuilder.append(" ").append(query.getAlias()).append(" ");
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:69,代码来源:MysqlPlanVisitorImpl.java

示例4: doQuery

import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入方法依赖的package包/类
@Override
protected ISchematicCursor doQuery(ISchematicCursor cursor, IDataNodeExecutor executor,
                                   ExecutionContext executionContext) throws TddlException {
    List<IOrderBy> _orderBy = ((IQueryTree) executor).getOrderBys();
    IRepository repo = executionContext.getCurrentRepository();
    IDataNodeExecutor _subQuery = null;
    IQuery query = (IQuery) executor;
    _subQuery = query.getSubQuery();
    if (_subQuery != null) {
        // 如果有subQuery,则按照subquery构建
        cursor = ExecutorContext.getContext().getTopologyExecutor().execByExecPlanNode(_subQuery, executionContext);
    } else {
        ITable table = null;
        IndexMeta meta = null;
        TableAndIndex ti = new TableAndIndex();
        buildTableAndMeta(query, ti, executionContext);
        table = ti.table;
        meta = ti.index;
        cursor = table.getCursor(executionContext, meta, (IQuery) executor);
    }

    // 获得查询结果的元数据
    // 获得本次查询的keyFilter
    IFilter keyFilter = query.getKeyFilter();
    if (keyFilter != null) {
        if (keyFilter instanceof IBooleanFilter) {
            cursor = manageToBooleanRangeCursor(executionContext, cursor, repo, keyFilter);
        } else {
            cursor = repo.getCursorFactory().rangeCursor(executionContext, cursor, keyFilter);
        }

        if (cursor instanceof RangeCursor) {//
            if (_orderBy != null) {
                if (_orderBy.size() == 1) {
                    IOrderBy o1 = _orderBy.get(0);
                    IOrderBy o2 = cursor.getOrderBy().get(0);
                    boolean needSort = !equalsIOrderBy(o1, o2);
                    boolean direction = o1.getDirection();
                    if (!needSort) {
                        if (!direction) {
                            // DescRangeCursor
                            cursor = repo.getCursorFactory().reverseOrderCursor(executionContext, cursor);
                        } else {
                            // asc,default
                        }
                        _orderBy = null;
                    }
                }
            }
        }
    }
    return cursor;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:54,代码来源:QueryHandler.java

示例5: isCondensable

import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入方法依赖的package包/类
private boolean isCondensable(IDataNodeExecutor executor, String lastGroupNode) {
    if (executor instanceof IQuery) {
        IQuery iq = (IQuery) executor;
        IQueryTree iqc = iq.getSubQuery();
        if (iqc == null) {
            return true;
        }
        String groupNode1 = lastGroupNode;
        if (groupNode1 == null) {
            groupNode1 = iq.getDataNode();
        }
        String groupNode2 = iqc.getDataNode();
        if (TStringUtil.equals(groupNode1, groupNode2)) {
            return isCondensable(iqc, groupNode1);
        } else {
            return false;
        }
    } else if (executor instanceof IJoin) {
        IJoin ijoin = (IJoin) executor;
        String leftNode = ijoin.getLeftNode().getDataNode();
        String rightNode = ijoin.getRightNode().getDataNode();
        if (leftNode == null || rightNode == null) {
            return false;
        } else if (!leftNode.equals(rightNode)) {
            return false;
        }

        if (ijoin.getLeftNode() instanceof IMerge || ijoin.getRightNode() instanceof IMerge) {
            return false;
        }

        boolean leftJoin = true;
        boolean rightJoin = true;
        if (ijoin.getLeftNode() instanceof IJoin) {
            leftJoin = isCondensable(ijoin.getLeftNode(), leftNode);
        }
        if (ijoin.getRightNode() instanceof IJoin) {
            rightJoin = isCondensable(ijoin.getRightNode(), rightNode);
        }

        return leftJoin & rightJoin;
    } else if (executor instanceof IPut) {
        // 目前put操作一定是单库的
        return true;
    } else {
        return false;
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:49,代码来源:ExplainMyHandler.java

示例6: doQuery

import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入方法依赖的package包/类
@Override
protected ISchematicCursor doQuery(ISchematicCursor cursor, IDataNodeExecutor executor,
                                   ExecutionContext executionContext) throws TddlException {
    List<IOrderBy> _orderBy = ((IQueryTree) executor).getOrderBys();
    IRepository repo = executionContext.getCurrentRepository();
    IDataNodeExecutor _subQuery = null;
    IQuery query = (IQuery) executor;
    _subQuery = query.getSubQuery();
    if (_subQuery != null) {
        // 如果有subQuery,则按照subquery构建
        cursor = ExecutorContext.getContext().getTopologyExecutor().execByExecPlanNode(_subQuery, executionContext);
    } else {
        ITable table = null;
        IndexMeta meta = null;
        buildTableAndMeta(query, executionContext);
        table = executionContext.getTable();
        meta = executionContext.getMeta();
        cursor = table.getCursor(executionContext, meta, (IQuery) executor);
    }

    // 获得查询结果的元数据
    // 获得本次查询的keyFilter
    IFilter keyFilter = query.getKeyFilter();
    if (keyFilter != null) {
        if (keyFilter instanceof IBooleanFilter) {
            // 外键约束好像没用
            // if (meta.getRelationship() == Relationship.MANY_TO_MANY) {
            // cursor = manageToReverseIndex(cursor, executor, repo,
            // transaction, executionContext.getTable(), meta,
            // keyFilter);
            // } else {}
            // 非倒排索引,即普通索引,走的查询方式
            cursor = manageToBooleanRangeCursor(executionContext, cursor, repo, keyFilter);
        } else if (keyFilter instanceof ILogicalFilter) {
            ILogicalFilter lf = (ILogicalFilter) keyFilter;
            cursor = repo.getCursorFactory().rangeCursor(executionContext, cursor, lf);
        }

        if (cursor instanceof RangeCursor) {//
            if (_orderBy != null) {
                if (_orderBy.size() == 1) {
                    IOrderBy o1 = _orderBy.get(0);
                    IOrderBy o2 = cursor.getOrderBy().get(0);
                    boolean needSort = !equalsIOrderBy(o1, o2);
                    boolean direction = o1.getDirection();
                    if (!needSort) {
                        if (!direction) {
                            // DescRangeCursor
                            cursor = repo.getCursorFactory().reverseOrderCursor(executionContext, cursor);
                        } else {
                            // asc,default
                        }
                        _orderBy = null;
                    }
                }
            }
        }
    }
    return cursor;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:61,代码来源:QueryHandler.java


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