本文整理汇总了Java中com.taobao.tddl.optimizer.core.ast.query.MergeNode类的典型用法代码示例。如果您正苦于以下问题:Java MergeNode类的具体用法?Java MergeNode怎么用?Java MergeNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MergeNode类属于com.taobao.tddl.optimizer.core.ast.query包,在下文中一共展示了MergeNode类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLeftJoinRightOnOneGroup
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
/**
* 左表是单库单表,右表为单库多表,是否满足join on group条件
*
* @param left
* @param right
* @return
*/
private static boolean isLeftJoinRightOnOneGroup(QueryTreeNode left, QueryTreeNode right) {
if (left instanceof MergeNode) {// 左表不是merge
return false;
}
if (!(right instanceof MergeNode)) {// 右表是merge
return false;
}
String group1 = getOneGroup(left);
String group2 = getOneGroup(right);
if (group1 != null && group2 != null) {
if (group1.equals(group2)) {
left.setBroadcast(true); // 将左表设置为广播表
return true;
}
}
return false;
}
示例2: KVIndexNode
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
@Test
public void test_join查询_生成JoinMergeJoin_嵌套子查询和Join带条件局部join_开启优化参数() {
KVIndexNode table1 = new KVIndexNode("TABLE1");
table1.alias("A");
QueryNode query1 = new QueryNode(table1);
query1.select("A.ID AS AID , A.NAME AS ANAME , A.SCHOOL AS ASCHOOL");
KVIndexNode table2 = new KVIndexNode("TABLE2");
table2.alias("B");
QueryNode query2 = new QueryNode(table2);
query2.select("B.ID AS BID , B.NAME AS BNAME , B.SCHOOL AS BSCHOOL");
JoinNode join = query1.join(query2, "AID", "BID");// 用的是子表的别名
join.build();
QueryTreeNode qtn = shard(join, false, true);
Assert.assertTrue(qtn instanceof MergeNode);
Assert.assertEquals(8, qtn.getChildren().size());
Assert.assertTrue(qtn.getChild() instanceof JoinNode);// join merge join
Assert.assertTrue(((JoinNode) qtn.getChild()).getChild() instanceof QueryNode);
}
示例3: TableNode
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
@Test
public void test_orderby_merge下推_group为order的子集() {
TableNode table1 = new TableNode("TABLE1");
table1.orderBy("ID", false);
table1.orderBy("NAME", true);
table1.groupBy("ID");
MergeNode merge = new MergeNode();
merge.addChild(table1);
merge.build();
QueryTreeNode qtn = OrderByPusher.optimize(merge);
// 子节点先按照NAME做group
// by,因为子节点的orderby和父节点的groupBy满足一个前序匹配,这里直接使用父节点id,Name做order by
// merge节点先按id做group
// by(底下子节点为id,name排序,不需要临时表排序),groupby处理后的结果也满足id,name的排序,直接返回,不需要临时表
Assert.assertEquals(2, ((TableNode) qtn.getChild()).getOrderBys().size());
Assert.assertEquals("ID", ((TableNode) qtn.getChild()).getOrderBys().get(0).getColumnName());
Assert.assertEquals("NAME", ((TableNode) qtn.getChild()).getOrderBys().get(1).getColumnName());
Assert.assertEquals(1, ((TableNode) qtn.getChild()).getGroupBys().size());
Assert.assertEquals("ID", ((TableNode) qtn.getChild()).getGroupBys().get(0).getColumnName());
}
示例4: shardUpdate
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的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;
}
示例5: shardDelete
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的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;
}
示例6: convertPlanToAst
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
public static MergeNode convertPlanToAst(IMerge merge) {
MergeNode node = new MergeNode();
for (IDataNodeExecutor plan : merge.getSubNodes()) {
if (!(plan instanceof IQueryTree)) {
throw new OptimizerException("不支持将非merge(query)转为语法树");
}
node.addChild(convertPlanToAst((IQueryTree) plan));
}
node.setLimitFrom(merge.getLimitFrom());
node.setLimitTo(merge.getLimitTo());
node.select(merge.getColumns());
node.setAlias(merge.getAlias());
node.setSubQuery(merge.isSubQuery());
node.setUnion(merge.isUnion());
node.setOrderBys(merge.getOrderBys());
node.setLimitFrom(merge.getLimitFrom());
node.setLimitTo(merge.getLimitTo());
node.setGroupBys(merge.getGroupBys());
node.setSharded(merge.isSharded());
node.having(merge.getHavingFilter());
node.setOtherJoinOnFilter(merge.getOtherJoinOnFilter());
node.setExistAggregate(merge.isExistAggregate());
node.setGroupByShardColumns(merge.isGroupByShardColumns());
node.setDistinctByShardColumns(merge.isDistinctByShardColumns());
node.executeOn(merge.getDataNode());
node.setSubqueryOnFilterId(merge.getSubqueryOnFilterId());
node.setSubqueryFilter(merge.getSubqueryFilter());
node.build();
node = node.deepCopy();
return node;
}
示例7: buildMergeQuery
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
private static QueryTreeNode buildMergeQuery(QueryNode query, MergeNode mergeNode, Map<String, Object> extraCmd) {
List<QueryNode> mergeQuerys = new LinkedList<QueryNode>();
for (ASTNode child : mergeNode.getChildren()) {
// 在未做shard之前就有存在mergeNode的可能,要识别出来
// 比如OR条件,可能会被拆分为两个Query的Merge,这个经过build之后,会是Merge套Merge或者是Merge套Query
if (!(child instanceof MergeNode) && child.getExtra() != null) {
QueryNode newQuery = query.copySelf();// 只复制自己,不复制子节点
newQuery.setChild((QueryTreeNode) child);
newQuery.executeOn(child.getDataNode());
newQuery.setExtra(child.getExtra());
newQuery.setBroadcast(child.isBroadcast());
mergeQuerys.add(newQuery);
}
}
if (mergeQuerys.size() > 1) {
MergeNode merge = new MergeNode();
merge.setAlias(query.getAlias());
merge.setSubQuery(query.isSubQuery());
merge.setSubAlias(query.getSubAlias());
// 复制子节点的limit/to信息
merge.setLimitFrom(query.getLimitFrom());
merge.setLimitTo(query.getLimitTo());
merge.setSubqueryOnFilterId(query.getSubqueryOnFilterId());
for (QueryNode q : mergeQuerys) {
merge.merge(q);
}
merge.executeOn(mergeQuerys.get(0).getDataNode()).setExtra(mergeQuerys.get(0).getExtra());
merge.build();
return merge;
} else if (mergeQuerys.size() == 1) {
return mergeQuerys.get(0);
} else {
return query;
}
}
示例8: getOneGroup
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
private static String getOneGroup(QueryTreeNode qtn) {
String group = qtn.getDataNode();
for (ASTNode node : qtn.getChildren()) {
if (node instanceof MergeNode) {
return null;
}
if (!group.equals(node.getDataNode())) {
return null;
}
}
return group;
}
示例9: createMergeForJoin
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
private ASTNode createMergeForJoin(ASTNode dne, Map<String, Object> extraCmd) {
if (dne instanceof MergeNode) {
for (ASTNode sub : ((MergeNode) dne).getChildren()) {
this.createMergeForJoin(sub, extraCmd);
}
}
if (dne instanceof JoinNode) {
this.createMergeForJoin(((JoinNode) dne).getLeftNode(), extraCmd);
this.createMergeForJoin(((JoinNode) dne).getRightNode(), extraCmd);
// 特殊处理子查询
if (((JoinNode) dne).getRightNode() instanceof QueryNode) {
QueryNode right = (QueryNode) ((JoinNode) dne).getRightNode();
if (right.getDataNode() != null) {
// right和join节点跨机,则需要右边生成Merge来做mget
if (!right.getDataNode().equals(dne.getDataNode())) {
MergeNode merge = new MergeNode();
merge.merge(right);
merge.setSharded(false);
merge.executeOn(right.getDataNode());
merge.build();
((JoinNode) dne).setRightNode(merge);
}
}
}
}
if (dne instanceof QueryNode) {
if (((QueryNode) dne).getChild() != null) {
this.createMergeForJoin(((QueryNode) dne).getChild(), extraCmd);
}
}
return dne;
}
示例10: buildOrderBy
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
@Override
protected void buildOrderBy() {
super.buildOrderBy();
// 如果子节点出现merge,说明不可下推,需要自己做计算
if (this.getNode().getLeftNode() instanceof MergeNode || this.getNode().getRightNode() instanceof MergeNode) {
// 检查group列是否在select列中
for (IOrderBy order : node.getOrderBys()) {
checkOrderColumnExist(order, node);
}
}
}
示例11: buildGroupBy
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入依赖的package包/类
@Override
protected void buildGroupBy() {
super.buildGroupBy();
// 如果子节点出现merge,说明不可下推,需要自己做计算
if (this.getNode().getLeftNode() instanceof MergeNode || this.getNode().getRightNode() instanceof MergeNode) {
// 检查group列是否在select列中
for (IOrderBy order : node.getGroupBys()) {
checkOrderColumnExist(order, node);
}
}
}