本文整理汇总了Java中com.taobao.tddl.optimizer.core.ast.query.MergeNode.build方法的典型用法代码示例。如果您正苦于以下问题:Java MergeNode.build方法的具体用法?Java MergeNode.build怎么用?Java MergeNode.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.core.ast.query.MergeNode
的用法示例。
在下文中一共展示了MergeNode.build方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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;
}
示例3: 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;
}
}
示例4: 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;
}
示例5: buildMergeQuery
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入方法依赖的package包/类
private static QueryTreeNode buildMergeQuery(QueryNode query, MergeNode mergeNode) {
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.copy();
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());
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;
}
}
示例6: TableNode
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入方法依赖的package包/类
@Test
public void test_merge的distinct下推() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
IColumn id = ASTNodeFactory.getInstance().createColumn();
id.setColumnName("ID");
id.setDistinct(true);
IColumn name = ASTNodeFactory.getInstance().createColumn();
name.setColumnName("NAME");
name.setDistinct(true);
IColumn school = ASTNodeFactory.getInstance().createColumn();
school.setColumnName("SCHOOL");
school.setDistinct(true);
table1.groupBy("NAME");
table1.orderBy("ID");
MergeNode merge = table1.merge(table2);
merge.select(id, name, school);
merge.build();
OrderByPusher.optimize(merge);
Assert.assertEquals(3, table1.getOrderBys().size());
Assert.assertEquals("TABLE1.NAME", table1.getOrderBys().get(0).getColumn().toString());
}
示例7: buildMergeTable
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入方法依赖的package包/类
/**
* 根据执行的目标节点,构建MergeNode
*/
private static QueryTreeNode buildMergeTable(TableNode table, List<TargetDB> dataNodeChoosed,
Map<String, Object> extraCmd, boolean traceIn) {
long maxRowCount = 0;
String maxRowCountDataNode = dataNodeChoosed.get(0).getDbIndex();
List<List<QueryTreeNode>> subs = new ArrayList();
// 单库单表是大多数场景,此时无需复制执行计划
// 大部分情况只有一张表
boolean needCopy = false;
if (dataNodeChoosed.size() > 0 && dataNodeChoosed.get(0).getTableNameMap().size() > 0) {
Map<String, Field> tabMap = dataNodeChoosed.get(0).getTableNameMap();
Entry<String, Field> entry = tabMap.entrySet().iterator().next();
// 如果存在in,则必须使用复制
if (traceIn && entry.getValue() != null) {
needCopy |= traceSourceInFilter(table.getKeyFilter(), entry.getValue().getSourceKeys(), true);
needCopy |= traceSourceInFilter(table.getResultFilter(), entry.getValue().getSourceKeys(), true);
}
if (!chooseShareNode(extraCmd) && tabMap.size() > 1) {
// 如果不使用share模式,并且多于一张表,那就采用复制模式
needCopy = true;
}
if (!needCopy && tabMap.size() > 1) {
table = table.copy(); // 针对share模式,需要复制一份
}
}
int index = 0;
for (TargetDB target : dataNodeChoosed) {
OneDbNodeWithCount oneDbNodeWithCount = buildMergeTableInOneDB(table, target, index, needCopy, traceIn);
if (!oneDbNodeWithCount.subs.isEmpty()) {
subs.add(oneDbNodeWithCount.subs);
}
index += target.getTableNameMap().size();
if (oneDbNodeWithCount.totalRowCount > maxRowCount) {
maxRowCount = oneDbNodeWithCount.totalRowCount;
maxRowCountDataNode = target.getDbIndex();
}
}
if (subs.isEmpty()) {
throw new EmptyResultFilterException();
} else if (subs.size() == 1 && subs.get(0).size() == 1) {
return subs.get(0).get(0); // 只有单库
} else {
// 多库执行
MergeNode merge = new MergeNode();
merge.setAlias(table.getAlias());
merge.setSubQuery(table.isSubQuery());
merge.setSubAlias(table.getSubAlias());
merge.executeOn(maxRowCountDataNode);
merge.setSubqueryOnFilterId(table.getSubqueryOnFilterId());
for (List<QueryTreeNode> subList : subs) {
for (QueryTreeNode sub : subList) {
merge.merge(sub);
}
}
merge.setBroadcast(false);// merge不可能是广播表
merge.build();// build过程中会复制子节点的信息
return merge;
}
}
示例8: buildMergeTable
import com.taobao.tddl.optimizer.core.ast.query.MergeNode; //导入方法依赖的package包/类
/**
* 根据执行的目标节点,构建MergeNode
*/
private static QueryTreeNode buildMergeTable(TableNode table, List<TargetDB> dataNodeChoosed) {
long maxRowCount = 0;
String maxRowCountDataNode = dataNodeChoosed.get(0).getDbIndex();
List<List<QueryTreeNode>> subs = new ArrayList();
// 单库单表是大多数场景,此时无需复制执行计划
boolean needCopy = true;
if (dataNodeChoosed != null && dataNodeChoosed.size() == 1
&& dataNodeChoosed.get(0).getTableNameMap().size() == 1) {
needCopy = false;
}
for (TargetDB target : dataNodeChoosed) {
OneDbNodeWithCount oneDbNodeWithCount = buildMergeTableInOneDB(table, target, needCopy);
if (!oneDbNodeWithCount.subs.isEmpty()) {
subs.add(oneDbNodeWithCount.subs);
}
if (oneDbNodeWithCount.totalRowCount > maxRowCount) {
maxRowCount = oneDbNodeWithCount.totalRowCount;
maxRowCountDataNode = target.getDbIndex();
}
}
if (subs.isEmpty()) {
throw new EmptyResultFilterException("无对应执行节点");
} else if (subs.size() == 1 && subs.get(0).size() == 1) {
return subs.get(0).get(0); // 只有单库
} else {
// 多库执行
MergeNode merge = new MergeNode();
merge.executeOn(LOCAL);// 随意的一个名字
merge.setAlias(table.getAlias());
merge.setSubQuery(table.isSubQuery());
merge.setSubAlias(table.getSubAlias());
merge.executeOn(maxRowCountDataNode);
for (List<QueryTreeNode> subList : subs) {
for (QueryTreeNode sub : subList) {
merge.merge(sub);
}
}
merge.setBroadcast(false);// merge不可能是广播表
merge.build();// build过程中会复制子节点的信息
return merge;
}
}