本文整理匯總了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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
}
}
示例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;
}
}
}
}
示例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();
}
示例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();
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
}
示例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;
}