當前位置: 首頁>>代碼示例>>Java>>正文


Java JoinNode類代碼示例

本文整理匯總了Java中com.taobao.tddl.optimizer.core.ast.query.JoinNode的典型用法代碼示例。如果您正苦於以下問題:Java JoinNode類的具體用法?Java JoinNode怎麽用?Java JoinNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JoinNode類屬於com.taobao.tddl.optimizer.core.ast.query包,在下文中一共展示了JoinNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visit

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Override
public void visit(StraightJoin node) {// inner join
    TableReference ltable = node.getLeftTableRef();
    TableReference rtable = node.getRightTableRef();
    JoinNode joinNode = commonJoin(ltable, rtable);
    Expression cond = node.getOnCond();
    if (cond != null) {
        MySqlExprVisitor ev = new MySqlExprVisitor(parent);
        cond.accept(ev);
        IFilter ifilter = ev.getFilter();
        joinNode.setInnerJoin();
        addJoinOnColumns(ifilter, joinNode);
    }

    this.tableNode = joinNode;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:17,代碼來源:MySqlExprVisitor.java

示例2: 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;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:29,代碼來源:JoinPreProcessor.java

示例3: optimizeSubQuery

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
/**
 * <pre>
 * 由於優化過程中需要將QueryTree轉換為執行計劃樹,而外部查詢轉換為執行計劃樹是依賴於子查詢的
 * 所以需要先對子查詢進行優化,再對外層查詢進行優化,回溯完成
 * </pre>
 */
private static void optimizeSubQuery(QueryTreeNode qtn, Map<String, Object> extraCmd) {
    if (qtn instanceof QueryNode) {
        QueryNode qn = (QueryNode) qtn;
        if (qn.getChild() != null) {
            optimizeSubQuery(qn.getChild(), extraCmd);
            qn.setChild(optimizeJoin(qn.getChild(), extraCmd));
        }

        // 複製當前queryNode的where條件
        qn.setResultFilter(qn.getWhereFilter());
        qn.query((IFilter) null);
    } else if (qtn instanceof JoinNode) {
        JoinNode jn = (JoinNode) qtn;
        optimizeSubQuery(jn.getLeftNode(), extraCmd);
        optimizeSubQuery(jn.getRightNode(), extraCmd);
    } else {
        // 不會出現mergeNode
        // 不單獨處理tableNode
    }

}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:28,代碼來源:JoinChooser.java

示例4: needReChooseJoinOrder

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的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

示例5: TableNode

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void test_join條件下推_子表_case3_不下推() {
    TableNode table1 = new TableNode("TABLE1");
    TableNode table2 = new TableNode("TABLE2");
    table1.alias("A");
    QueryNode query = new QueryNode(table1);
    query.orderBy("ID");
    query.orderBy("NAME");
    query.limit(0, 10);

    table2.alias("B");

    JoinNode join = query.join(table2);
    join.setJoinStrategy(JoinStrategy.INDEX_NEST_LOOP);
    join.orderBy("A.NAME");
    join.orderBy("A.SCHOOL");
    join.build();

    OrderByPusher.optimize(join);

    Assert.assertEquals(2, query.getOrderBys().size());
    Assert.assertEquals("A.ID", query.getOrderBys().get(0).getColumn().toString());
    Assert.assertEquals("A.NAME", query.getOrderBys().get(1).getColumn().toString());
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:25,代碼來源:OrderByPusherTest.java

示例6: isJoinOnPartition

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
/**
 * 找到join條件完全是分區鍵的filter,返回null代表沒找到,否則返回join條件
 */
private static PartitionJoinResult isJoinOnPartition(JoinNode join) {
    QueryTreeNode left = join.getLeftNode();
    QueryTreeNode right = join.getRightNode();

    PartitionJoinResult leftResult = isJoinOnPartitionOneSide(join.getLeftKeys(), left);
    PartitionJoinResult rightResult = isJoinOnPartitionOneSide(join.getRightKeys(), right);
    // 允許一張單表和一張廣播表的組合
    if (!leftResult.flag && !rightResult.broadcast) {
        return leftResult;
    }

    if (!rightResult.flag && !leftResult.broadcast) {
        return rightResult;
    }

    PartitionJoinResult result = new PartitionJoinResult();
    result.broadcast = leftResult.broadcast || rightResult.broadcast;
    result.flag = StringUtils.equalsIgnoreCase(leftResult.joinGroup, rightResult.joinGroup) || result.broadcast;
    result.joinGroup = leftResult.joinGroup;
    result.joinFilters = join.getJoinFilter();
    return result;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:26,代碼來源:DataNodeChooser.java

示例7: 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)");
    QueryNode query = new QueryNode(table2);
    query.setSubQuery(true); // 是個子查詢,會進行BLOCK_NEST_LOOP處理,就不需要未決節點進行mget處理

    JoinNode join = table1.join(query, "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.assertTrue(((JoinNode) qtn).getRightNode().getChild() instanceof QueryNode);
    Assert.assertEquals(3, ((JoinNode) qtn).getRightNode().getChildren().size());// 是個子查詢的Merge
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:20,代碼來源:DataNodeChooserTest.java

示例8: FROM

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void testQuery_join_子查詢_多級組合() throws SqlParserException {
    String joinSql = "SELECT TABLE1.ID,TABLE1.NAME FROM TABLE1 JOIN TABLE2 ON TABLE1.ID=TABLE1.ID WHERE TABLE1.NAME=1";
    String subsql = "SELECT * FROM (" + joinSql + " ) S WHERE S.NAME = 1";
    String sql = "SELECT * FROM (" + subsql + ") B , (" + subsql + ") C WHERE B.NAME = 6 AND B.ID = C.ID";
    QueryTreeNode qn = query(sql);
    qn.build();

    // System.out.println(qn);
    // 第一級是JoinNode
    // 第二級是QuerNode / QueryNode
    // 第三級是JoinNode / JoinNode
    Assert.assertTrue(qn instanceof JoinNode);
    Assert.assertTrue(((JoinNode) qn).getLeftNode() instanceof QueryNode);
    Assert.assertTrue(((JoinNode) qn).getRightNode() instanceof QueryNode);
    Assert.assertTrue(((QueryNode) ((JoinNode) qn).getLeftNode()).getChild() instanceof JoinNode);
    Assert.assertTrue(((QueryNode) ((JoinNode) qn).getRightNode()).getChild() instanceof JoinNode);
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:19,代碼來源:SqlParserTest.java

示例9: KVIndexNode

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void test_join查詢_不生成merge() {
    KVIndexNode table1 = new KVIndexNode("TABLE1");
    table1.keyQuery("ID = 1");
    KVIndexNode table2 = new KVIndexNode("TABLE2");
    table2.keyQuery("ID = 1");

    JoinNode join = table1.join(table2, "ID", "ID");
    join.build();
    QueryTreeNode qtn = shard(join, false, false);

    Assert.assertTrue(qtn instanceof JoinNode);
    Assert.assertEquals("andor_group_0", ((JoinNode) qtn).getLeftNode().getDataNode());
    Assert.assertEquals("andor_group_0", ((JoinNode) qtn).getRightNode().getDataNode());
    Assert.assertEquals("table1_01", ((KVIndexNode) ((JoinNode) qtn).getLeftNode()).getActualTableName());
    Assert.assertEquals("table2_01", ((KVIndexNode) ((JoinNode) qtn).getRightNode()).getActualTableName());
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:18,代碼來源:DataNodeChooserTest.java

示例10: FROM

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void testQuery_join_子查詢_多級組合() throws SqlParserException, QueryException {
    String joinSql = "SELECT TABLE1.ID,TABLE1.NAME FROM TABLE1 JOIN TABLE2 ON TABLE1.ID=TABLE1.ID WHERE TABLE1.NAME=1";
    String subsql = "SELECT * FROM (" + joinSql + " ) S WHERE S.NAME = 1";
    String sql = "SELECT * FROM (" + subsql + ") B , (" + subsql + ") C WHERE B.NAME = 6 AND B.ID = C.ID";
    QueryTreeNode qn = query(sql);
    qn.build();

    // System.out.println(qn);
    // 第一級是JoinNode
    // 第二級是QuerNode / QueryNode
    // 第三級是JoinNode / JoinNode
    Assert.assertTrue(qn instanceof JoinNode);
    Assert.assertTrue(((JoinNode) qn).getLeftNode() instanceof QueryNode);
    Assert.assertTrue(((JoinNode) qn).getRightNode() instanceof QueryNode);
    Assert.assertTrue(((QueryNode) ((JoinNode) qn).getLeftNode()).getChild() instanceof JoinNode);
    Assert.assertTrue(((QueryNode) ((JoinNode) qn).getRightNode()).getChild() instanceof JoinNode);
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:19,代碼來源:SqlParserTest.java

示例11: TableNode

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void test_where條件下推_多級join() {
    TableNode table1 = new TableNode("TABLE1");
    TableNode table2 = new TableNode("TABLE2");
    TableNode table3 = new TableNode("TABLE3");

    JoinNode join = table1.join(table2);
    join.select("TABLE1.ID AS ID , TABLE1.NAME AS NAME");
    join.query("TABLE1.ID>5 AND TABLE2.ID<10 AND TABLE1.NAME = TABLE2.NAME");
    join.build();

    JoinNode nextJoin = join.join(table3);
    nextJoin.query("TABLE1.NAME = 6 AND TABLE1.ID = TABLE3.ID");
    nextJoin.build();
    FilterPusher.optimize(nextJoin);

    Assert.assertEquals("(TABLE1.NAME = 6 AND TABLE1.ID > 5)", ((JoinNode) nextJoin.getLeftNode()).getLeftNode()
        .getWhereFilter()
        .toString());
    Assert.assertEquals("(TABLE2.ID < 10 AND TABLE2.NAME = 6)", ((JoinNode) nextJoin.getLeftNode()).getRightNode()
        .getWhereFilter()
        .toString());
    Assert.assertEquals("TABLE1.ID = TABLE3.ID", nextJoin.getJoinFilter().get(0).toString());
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:25,代碼來源:FilterPusherTest.java

示例12: visit

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Override
public void visit(StraightJoin node) {// inner join
    TableReference ltable = node.getLeftTableRef();
    TableReference rtable = node.getRightTableRef();
    JoinNode joinNode = commonJoin(ltable, rtable);
    Expression cond = node.getOnCond();
    if (cond != null) {
        MySqlExprVisitor ev = new MySqlExprVisitor();
        cond.accept(ev);
        IFilter ifilter = ev.getFilter();
        joinNode.setInnerJoin();
        addJoinOnColumns(ifilter, joinNode);
    }

    this.tableNode = joinNode;
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:17,代碼來源:MySqlExprVisitor.java

示例13: testJoin

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void testJoin() {
    KVIndexNode studentID = new KVIndexNode("TABLE1");
    studentID.alias("TABLE1");
    studentID.select("ID,NAME,SCHOOL");

    KVIndexNode studentName = new KVIndexNode("TABLE1._NAME");
    studentName.alias("TABLE1._NAME");
    studentName.select("ID,NAME");
    studentName.keyQuery("NAME=1");

    studentID.valueQuery("SCHOOL=1");

    JoinNode join = studentName.join(studentID).addJoinKeys("ID", "ID");
    // build之前的操作順序可以任意
    join.build();

    System.out.println(join);
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:20,代碼來源:KVIndexNodeTest.java

示例14: TableNode

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void test_TableNode轉化為index到kv_複雜條件查詢() {
    TableNode table = new TableNode("TABLE1");
    table.select("(ID + NAME) AS NEWNAME"); // 設置為函數
    table.query("NAME = 1 AND ID > 3 AND SCHOOL = 1");
    table.orderBy("SCHOOL", false);// 增加一個隱藏列
    table.groupBy("NEWNAME");
    build(table);

    QueryTreeNode qn = table.convertToJoinIfNeed();

    Assert.assertTrue(qn instanceof JoinNode);
    Assert.assertEquals("TABLE1._NAME.NAME = 1", ((JoinNode) qn).getLeftNode().getKeyFilter().toString());
    Assert.assertEquals("TABLE1._NAME.ID > 3", ((JoinNode) qn).getLeftNode().getResultFilter().toString());
    Assert.assertEquals("TABLE1.SCHOOL = 1", ((JoinNode) qn).getRightNode().getResultFilter().toString());
    Assert.assertEquals("TABLE1._NAME.ID = TABLE1.ID", ((JoinNode) qn).getJoinFilter().get(0).toString());
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:18,代碼來源:JoinChooserTest.java

示例15: TableNode

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入依賴的package包/類
@Test
public void test_join條件下推_子表_case1_下推NAME() {
    TableNode table1 = new TableNode("TABLE1");
    TableNode table2 = new TableNode("TABLE2");
    table1.alias("A");
    table1.orderBy("ID");
    table2.alias("B");

    JoinNode join = table1.join(table2);
    join.setJoinStrategy(JoinStrategy.INDEX_NEST_LOOP);
    join.orderBy("A.ID");
    join.orderBy("A.NAME");
    join.build();

    OrderByPusher.optimize(join);

    Assert.assertEquals(2, table1.getOrderBys().size());
    Assert.assertEquals("TABLE1.ID", table1.getOrderBys().get(0).getColumn().toString());
    Assert.assertEquals("TABLE1.NAME", table1.getOrderBys().get(1).getColumn().toString());
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:21,代碼來源:OrderByPusherTest.java


注:本文中的com.taobao.tddl.optimizer.core.ast.query.JoinNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。