本文整理匯總了Java中com.taobao.tddl.optimizer.core.ast.query.JoinNode.build方法的典型用法代碼示例。如果您正苦於以下問題:Java JoinNode.build方法的具體用法?Java JoinNode.build怎麽用?Java JoinNode.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.taobao.tddl.optimizer.core.ast.query.JoinNode
的用法示例。
在下文中一共展示了JoinNode.build方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: TableNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_join條件下推_子表_case5_函數不下推() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
table1.alias("A");
table2.alias("B");
JoinNode join = table1.join(table2);
join.setJoinStrategy(JoinStrategy.INDEX_NEST_LOOP);
join.select("A.ID AS CID, (A.NAME + A.SCHOOL) AS NAME");
join.orderBy("CID ");
join.orderBy("NAME"); // 這裏的name為select中的函數
join.build();
OrderByPusher.optimize(join);
Assert.assertEquals(0, table1.getOrderBys().size());
}
示例2: KVIndexNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的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: KVIndexNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_join查詢_不生成JoinMergeJoin_左邊是不是Merge_開啟優化參數() {
KVIndexNode table1 = new KVIndexNode("TABLE8");// 這是一個單表,不分庫
table1.keyQuery("TABLE8.ID IN (1,2,3)");
KVIndexNode table2 = new KVIndexNode("TABLE2");// 分庫表
table2.keyQuery("TABLE2.ID IN (1,2,3)");
JoinNode join = table1.join(table2, "ID", "ID");
join.build();
QueryTreeNode qtn = shard(join, false, true);
Assert.assertTrue(qtn instanceof JoinNode);
Assert.assertTrue(((JoinNode) qtn).getLeftNode() instanceof KVIndexNode);
Assert.assertTrue(((JoinNode) qtn).getRightNode() instanceof MergeNode);
Assert.assertEquals(1, ((JoinNode) qtn).getRightNode().getChildren().size());// 因為是個未決節點
}
示例4: findAndChangeRightJoinToLeftJoin
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的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;
}
示例5: TableNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_join條件下推_條件推導下推() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
JoinNode join = table1.join(table2).addJoinKeys("TABLE1.ID", "TABLE2.ID");
addOtherJoinFilter(join, "TABLE1.ID>5 AND TABLE2.ID<10");
join.build();
FilterPusher.optimize(join);
Assert.assertEquals("(TABLE1.ID > 5 AND TABLE1.ID < 10)", join.getLeftNode().getOtherJoinOnFilter().toString());
Assert.assertEquals("(TABLE2.ID < 10 AND TABLE2.ID > 5)", join.getRightNode().getOtherJoinOnFilter().toString());
Assert.assertEquals("TABLE1.ID = TABLE2.ID", join.getJoinFilter().get(0).toString());
}
示例6: getQueryTreeFromQueryNodes
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
/**
* 構造一個join
*/
private QueryTreeNode getQueryTreeFromQueryNodes(List<QueryTreeNode> nodes) {
if (nodes.size() == 1) {
return nodes.get(0);
}
JoinNode join = null;
for (int i = 1; i < nodes.size(); i++) {
List<IBooleanFilter> filterToJoinOn;
if (join == null) {
filterToJoinOn = canJoinAndThenReturnFilters(nodes.get(i - 1), nodes.get(i));
if (filterToJoinOn == null || filterToJoinOn.isEmpty()) {
return null;
}
join = nodes.get(i - 1).join(nodes.get(i));
join.setJoinFilter(filterToJoinOn);
} else {
filterToJoinOn = canJoinAndThenReturnFilters(join, nodes.get(i));
if (filterToJoinOn == null) {
return null;
}
join = join.join(nodes.get(i));
join.setJoinFilter(filterToJoinOn);
}
join.build();
}
return join;
}
示例7: TableNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_JoinStrategy不選擇sortmerge_右表存在order條件() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
JoinNode join = table1.join(table2).setLeftOuterJoin().addJoinKeys("ID", "ID").addJoinKeys("NAME", "NAME");
join.orderBy("TABLE2.SCHOOL"); // join列的順序沒法推導
join.build();
QueryTreeNode qn = optimize(join, true, true, true);
Assert.assertEquals(JoinStrategy.INDEX_NEST_LOOP, ((JoinNode) qn).getJoinStrategy());
}
示例8: TableNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_等於子查詢_外部是個join節點() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
JoinNode join = table1.join(table2, "ID", "ID");
join.query("TABLE1.ID = (SELECT ID FROM TABLE3 WHERE NAME = 'HELLO' AND SCHOOL = 'HELLO' ) AND TABLE1.NAME = 3 AND TABLE1.SCHOOL IN ('A','B')");
join.build();
QueryTreeNode qn = SubQueryPreProcessor.optimize(join);
Assert.assertTrue(qn instanceof JoinNode);
Assert.assertTrue(((JoinNode) qn).getLeftNode() instanceof JoinNode);
Assert.assertEquals(null, join.getWhereFilter());
}
示例9: TableNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_JoinStrategy選擇sortmerge_右表存在group條件() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
JoinNode join = table1.join(table2).setLeftOuterJoin().addJoinKeys("ID", "ID").addJoinKeys("NAME", "NAME");
join.orderBy("TABLE2.ID");
join.groupBy("TABLE2.NAME").groupBy("TABLE2.ID").groupBy("TABLE2.SCHOOL");
join.build();
QueryTreeNode qn = optimize(join, true, true, true);
Assert.assertEquals(JoinStrategy.SORT_MERGE_JOIN, ((JoinNode) qn).getJoinStrategy());
}
示例10: TableNode
import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
@Test
public void test_orderby_SortMerge下推_多級結構下推() {
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
// 如果底層join的順序不是ID,NAME的順序,暫時沒法推,要遞歸做最優,算法太複雜,先簡單隻考慮一層
JoinNode join = table1.join(table2).addJoinKeys("ID", "ID");
join.setJoinStrategy(JoinStrategy.SORT_MERGE_JOIN);
join.alias("S").select("TABLE1.ID AS AID , TABLE1.NAME AS ANAME , TABLE1.SCHOOL AS ASCHOOL");
join.build();
QueryNode queryA = new QueryNode(join);
queryA.alias("B");
queryA.select("S.AID AS BID,S.ANAME AS BNAME,S.ASCHOOL AS BSCHOOL");
queryA.build();
QueryNode queryB = queryA.deepCopy();
queryB.alias("C");
queryB.select("S.AID AS CID,S.ANAME AS CNAME,S.ASCHOOL AS CSCHOOL");
queryB.build();
JoinNode nextJoin = queryA.join(queryB).addJoinKeys("BID", "CID").addJoinKeys("BNAME", "CNAME");
nextJoin.setJoinStrategy(JoinStrategy.SORT_MERGE_JOIN);
nextJoin.select("C.CID AS ID , C.CNAME AS NAME , C.CSCHOOL AS SCHOOL");
// group by順序可調整
nextJoin.groupBy("NAME").groupBy("SCHOOL").groupBy("ID");
nextJoin.orderBy("SCHOOL", false);
nextJoin.build();
OrderByPusher.optimize(nextJoin);
// 推導結果有點深,就不枚舉了
// 左子樹,ID , NAME
Assert.assertEquals(2, ((TableNode) queryA.getChild().getChildren().get(0)).getOrderBys().size());
// 隻是id join列
Assert.assertEquals(1, ((TableNode) queryA.getChild().getChildren().get(1)).getOrderBys().size());
// ID , NAME
Assert.assertEquals(2, queryA.getOrderBys().size());
// 右子樹,ID , NAME , SCHOOL
Assert.assertEquals(3, ((TableNode) queryB.getChild().getChildren().get(0)).getOrderBys().size());
// 隻是id join列
Assert.assertEquals(1, ((TableNode) queryB.getChild().getChildren().get(1)).getOrderBys().size());
// ID , NAME , SCHOOL
Assert.assertEquals(3, queryB.getOrderBys().size());
// ID
Assert.assertEquals(1, nextJoin.getOrderBys().size());
// ID , NAME , SCHOOL
Assert.assertEquals(3, nextJoin.getGroupBys().size());
}