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


Java ASTNode类代码示例

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


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

示例1: findAndChangeRightJoinToLeftJoin

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
/**
 * 会遍历所有节点将right join的左右节点进行调换,转换成left join.
 * 
 * <pre>
 * 比如 A right join B on A.id = B.id
 * 转化为 B left join B on A.id = B.id
 * </pre>
 */
private static QueryTreeNode findAndChangeRightJoinToLeftJoin(QueryTreeNode qtn) {
    for (ASTNode child : qtn.getChildren()) {
        findAndChangeRightJoinToLeftJoin((QueryTreeNode) child);
    }

    if (qtn instanceof JoinNode && ((JoinNode) qtn).isRightOuterJoin()) {
        /**
         * 如果带有其他非column=column条件,不能做这种转换,否则语义改变
         */
        if (qtn.getOtherJoinOnFilter() != null) {
            return qtn;
        }

        JoinNode jn = (JoinNode) qtn;
        jn.exchangeLeftAndRight();
        jn.build();
    }

    return qtn;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:29,代码来源:JoinPreProcessor.java

示例2: needReChooseJoinOrder

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
/**
 * 判断是否需要调整join顺序
 * 
 * <pre>
 * 比如mysql: select xx from a,b,c where a.id = c.id and b.name = c.name
 * 这时的结构树为 (a join b) join c , a join b上不存在join条件,需要调整join顺序为 (a join c) join b 或者 (b join c) join a
 * </pre>
 */
private static boolean needReChooseJoinOrder(QueryTreeNode qtn) {
    if (qtn instanceof JoinNode) {
        if (((JoinNode) qtn).getJoinFilter() == null || ((JoinNode) qtn).getJoinFilter().isEmpty()) {
            return true;
        }
    }

    for (ASTNode node : qtn.getChildren()) {
        if (!(node instanceof QueryTreeNode)) {
            return false;
        }

        if (needReChooseJoinOrder((QueryTreeNode) node)) {
            return true;
        }
    }

    return false;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:28,代码来源:JoinChooser.java

示例3: getQueryNodesFromQueryTree

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
/**
 * 从查询树中收集不会再被调整Join顺序的子树
 * 
 * <pre>
 * 包括: 
 * 1、非InnerJoin的Join节点。因为既然用户已经指定了left或者right,说明用户已经指定了outter的就为驱动表,所以无需再做额外的调整
 * 2、被标记为子查询的Join节点,子查询中的节点会单独去调整
 * 3、不在1中的Query节点
 * </pre>
 */
private void getQueryNodesFromQueryTree(QueryTreeNode node) {
    if (node instanceof JoinNode) {
        if (!((JoinNode) node).isInnerJoin() || node.isSubQuery()
            || ((JoinNode) node).getOtherJoinOnFilter() != null) {
            this.queryNodes.add(node);
            return;
        }
    }

    if (node instanceof TableNode || node instanceof QueryNode) {
        this.queryNodes.add(node);
        return;
    }

    for (ASTNode child : node.getChildren()) {
        getQueryNodesFromQueryTree((QueryTreeNode) child);
    }

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

示例4: preProcess

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
private static QueryTreeNode preProcess(QueryTreeNode qtn, boolean typeConvert, Map<String, Object> extraCmd) {
    qtn.setOtherJoinOnFilter(processFilter(qtn.getOtherJoinOnFilter(), typeConvert, extraCmd));
    qtn.having(processFilter(qtn.getHavingFilter(), typeConvert, extraCmd));
    qtn.query(processFilter(qtn.getWhereFilter(), typeConvert, extraCmd));
    qtn.setKeyFilter(processFilter(qtn.getKeyFilter(), typeConvert, extraCmd));
    qtn.setResultFilter(processFilter(qtn.getResultFilter(), typeConvert, extraCmd));
    if (qtn instanceof TableNode) {
        ((TableNode) qtn).setIndexQueryValueFilter(processFilter(((TableNode) qtn).getIndexQueryValueFilter(),
            typeConvert,
            extraCmd));
    }

    if (qtn instanceof JoinNode) {
        for (int i = 0; i < ((JoinNode) qtn).getJoinFilter().size(); i++) {
            processFilter(((JoinNode) qtn).getJoinFilter().get(i), typeConvert, extraCmd);
        }
    }

    for (ASTNode child : qtn.getChildren()) {
        preProcess((QueryTreeNode) child, typeConvert, extraCmd);
    }

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

示例5: optimizePlan

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
@Override
public IDataNodeExecutor optimizePlan(ASTNode node, Parameters parameterSettings, Map<String, Object> extraCmd)
                                                                                                               throws OptimizerException {
    try {
        // 处理batch下的sequence问题
        if (parameterSettings != null && parameterSettings.isBatch()) {
            SequencePreProcessor.opitmize(node, parameterSettings, extraCmd);
        }
        // 分库,选择执行节点
        node = DataNodeChooser.shard(node, parameterSettings, extraCmd);
        node = this.createMergeForJoin(node, extraCmd);
        if (node instanceof QueryTreeNode) {
            OrderByPusher.optimize((QueryTreeNode) node);
        }

        IDataNodeExecutor plan = node.toDataNodeExecutor();
        // 进行一些自定义的额外处理
        for (QueryPlanOptimizer after : afterOptimizers) {
            plan = after.optimize(plan, parameterSettings, extraCmd);
        }
        return plan;
    } finally {
        // 清理last_sequence_id,避免干扰
        ThreadLocalMap.remove(IDataNodeExecutor.LAST_SEQUENCE_VAL);
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:27,代码来源:CostBasedOptimizer.java

示例6: buildExistAggregate

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
protected void buildExistAggregate() {
    // 存在distinct
    for (ISelectable select : this.node.getColumnsRefered()) {
        if (select.isDistinct() || (select instanceof IFunction && ((IFunction) select).isNeedDistinctArg())) {
            setExistAggregate();
            return;
        }
    }

    // 如果子节点中有一个是聚合查询,则传递到父节点
    for (ASTNode sub : this.getNode().getChildren()) {
        if (sub instanceof QueryTreeNode) {
            if (((QueryTreeNode) sub).isExistAggregate()) {
                setExistAggregate();
                return;
            }
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:20,代码来源:QueryTreeNodeBuilder.java

示例7: buildExistSequenceVal

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
protected void buildExistSequenceVal() {
    // 如果子节点中有一个是聚合查询,则传递到父节点
    for (ASTNode sub : this.getNode().getChildren()) {
        if (sub instanceof QueryTreeNode) {
            if (((QueryTreeNode) sub).isExistSequenceVal()) {
                setExistSequenceVal();
                return;
            }
        } else if (sub instanceof DMLNode) {
            if (((DMLNode) sub).isExistSequenceVal()) {
                setExistSequenceVal();
                return;
            }
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:17,代码来源:QueryTreeNodeBuilder.java

示例8: build

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
@Override
public void build() {
    for (ASTNode sub : this.getNode().getChildren()) {
        sub.build();
    }

    this.buildExistSequenceVal();
    if (!(this.getNode().getChild() instanceof QueryTreeNode)) {
        return;
    }
    this.buildAlias();
    this.buildSelected();
    this.buildWhere();
    this.buildGroupBy();
    this.buildOrderBy();
    this.buildHaving();
    this.buildFunction();
    this.buildExistAggregate();
    // 最后一个处理
    this.buildLimit();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:22,代码来源:MergeNodeBuilder.java

示例9: build

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
public void build() {
    for (ASTNode sub : this.getNode().getChildren()) {
        sub.build();
    }

    if (!(this.getNode().getChild() instanceof QueryTreeNode)) {// 嵌套子类
        return;
    }

    this.buildAlias();
    this.buildSelected();

    this.buildWhere();
    this.buildGroupBy();
    this.buildOrderBy();

    if (this.getNode().getDataNode() == null) {
        this.getNode().executeOn(this.getNode().getChild().getDataNode());
    }

    this.buildExistAggregate();
    this.buildExistSequenceVal();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:24,代码来源:QueryNodeBuilder.java

示例10: KVIndexNode

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
@Test
public void test_insertSelect查询_select为join查询_生成merge_设置where条件() {
    KVIndexNode table1 = new KVIndexNode("TABLE1");

    KVIndexNode table2 = new KVIndexNode("TABLE2");
    table2.keyQuery("ID IN (2,3)");
    KVIndexNode table3 = new KVIndexNode("TABLE3");
    table3.keyQuery("ID IN (2,3)");
    JoinNode join = table2.join(table3, "ID", "ID");
    join.select("TABLE2.*");

    InsertNode insert = new InsertNode(table1);
    insert.setSelectNode(join);
    insert.build();
    ASTNode qtn = shard(insert);

    Assert.assertTrue(qtn instanceof MergeNode);
    Assert.assertTrue(((MergeNode) qtn).getChild() instanceof InsertNode);
    Assert.assertEquals(2, ((MergeNode) qtn).getChildren().size());
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:21,代码来源:DataNodeChooserTest.java

示例11: shard

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
public static ASTNode shard(ASTNode dne, Map<Integer, ParameterContext> parameterSettings,
                            Map<String, Object> extraCmd) throws QueryException {
    if (dne instanceof DMLNode) {
        if (dne instanceof InsertNode) {
            return shardInsert((InsertNode) dne, parameterSettings, extraCmd);
        }
        if (dne instanceof UpdateNode) {
            return shardUpdate((UpdateNode) dne, parameterSettings, extraCmd);
        }
        if (dne instanceof DeleteNode) {
            return shardDelete((DeleteNode) dne, parameterSettings, extraCmd);
        }
        if (dne instanceof PutNode) {
            return shardPut((PutNode) dne, parameterSettings, extraCmd);
        }
    }
    if (dne instanceof QueryTreeNode) {
        return shardQuery((QueryTreeNode) dne, parameterSettings, extraCmd);
    }

    return dne;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:23,代码来源:DataNodeChooser.java

示例12: shardUpdate

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
private static ASTNode shardUpdate(UpdateNode dne, Map<Integer, ParameterContext> parameterSettings,
                                   Map<String, Object> extraCmd) throws QueryException {
    QueryTreeNode qtn = shardQuery(dne.getNode(), parameterSettings, extraCmd);
    List<ASTNode> subs = new ArrayList();
    if (qtn instanceof MergeNode) {
        subs.addAll(qtn.getChildren());
    } else {
        subs.add(qtn);
    }

    if (subs.size() == 1) {
        return buildOneQueryUpdate((QueryTreeNode) subs.get(0), dne.getColumns(), dne.getValues());
    }

    MergeNode updateMerge = new MergeNode();
    for (ASTNode sub : subs) {
        updateMerge.merge(buildOneQueryUpdate((QueryTreeNode) sub, dne.getColumns(), dne.getValues()));
    }
    updateMerge.executeOn(updateMerge.getChild().getDataNode());
    return updateMerge;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:22,代码来源:DataNodeChooser.java

示例13: shardDelete

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
private static ASTNode shardDelete(DeleteNode dne, Map<Integer, ParameterContext> parameterSettings,
                                   Map<String, Object> extraCmd) throws QueryException {
    QueryTreeNode qtn = shardQuery(dne.getNode(), parameterSettings, extraCmd);
    List<ASTNode> subs = new ArrayList();
    if (qtn instanceof MergeNode) {
        subs.addAll(qtn.getChildren());
    } else {
        subs.add(qtn);
    }

    if (subs.size() == 1) {
        return buildOneQueryDelete((QueryTreeNode) subs.get(0));
    }

    MergeNode deleteMerge = new MergeNode();
    for (ASTNode sub : subs) {
        deleteMerge.merge(buildOneQueryDelete((QueryTreeNode) sub));
    }
    deleteMerge.executeOn(deleteMerge.getChild().getDataNode());
    return deleteMerge;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:22,代码来源:DataNodeChooser.java

示例14: shardPut

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
private static ASTNode shardPut(PutNode dne, Map<Integer, ParameterContext> parameterSettings,
                                Map<String, Object> extraCmd) {
    String indexName = null;
    if (dne.getNode() instanceof KVIndexNode) {
        indexName = ((KVIndexNode) dne.getNode()).getIndexName();
    } else {
        indexName = dne.getNode().getTableMeta().getPrimaryIndex().getName();
    }

    IFilter insertFilter = createFilter(dne.getColumns(), dne.getValues());
    List<TargetDB> dataNodeChoosed = shard(indexName, insertFilter, true);
    TargetDB itarget = dataNodeChoosed.get(0);
    dne.executeOn(itarget.getDbIndex());
    if (dataNodeChoosed.size() == 1 && itarget.getTableNameMap() != null && itarget.getTableNameMap().size() == 1) {
        KVIndexNode query = new KVIndexNode(indexName);
        query.executeOn(itarget.getDbIndex());
        query.setActualTableName(itarget.getTableNameMap().keySet().iterator().next());
        dne = query.put(dne.getColumns(), dne.getValues());
        dne.executeOn(query.getDataNode());
        dne.build();
        return dne;
    } else {
        throw new OptimizerException("insert not support muti tables");
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:26,代码来源:DataNodeChooser.java

示例15: preProcess

import com.taobao.tddl.optimizer.core.ast.ASTNode; //导入依赖的package包/类
private static QueryTreeNode preProcess(QueryTreeNode qtn, boolean typeConvert) throws QueryException {
    qtn.setOtherJoinOnFilter(processFilter(qtn.getOtherJoinOnFilter(), typeConvert));
    qtn.having(processFilter(qtn.getHavingFilter(), typeConvert));
    qtn.query(processFilter(qtn.getWhereFilter(), typeConvert));
    qtn.setKeyFilter(processFilter(qtn.getKeyFilter(), typeConvert));
    qtn.setResultFilter(processFilter(qtn.getResultFilter(), typeConvert));
    if (qtn instanceof TableNode) {
        ((TableNode) qtn).setIndexQueryValueFilter(processFilter(((TableNode) qtn).getIndexQueryValueFilter(),
            typeConvert));
    }

    if (qtn instanceof JoinNode) {
        for (int i = 0; i < ((JoinNode) qtn).getJoinFilter().size(); i++) {
            processFilter(((JoinNode) qtn).getJoinFilter().get(i), typeConvert);
        }
    }

    for (ASTNode child : qtn.getChildren()) {
        preProcess((QueryTreeNode) child, typeConvert);
    }

    return qtn;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:24,代码来源:FilterPreProcessor.java


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