Search in sources :

Example 1 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class JoinNodeHandlerBuilder method buildNestFiltersForExplain.

private void buildNestFiltersForExplain(PlanNode tnBig, Item keyToPass) {
    Item keyInBig = PlanUtil.pushDownItem(node, keyToPass);
    List<Item> strategyFilters = tnBig.getNestLoopFilters();
    List<Item> argList = new ArrayList<>();
    argList.add(keyInBig);
    argList.add(new ItemString(NEED_REPLACE));
    ItemFuncIn filter = new ItemFuncIn(argList, false);
    strategyFilters.add(filter);
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncIn(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncIn) ArrayList(java.util.ArrayList) ItemString(com.actiontech.dble.plan.common.item.ItemString)

Example 2 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class JoinNodeHandlerBuilder method buildNestFilters.

/**
 * generate filter for big table according to tmp(small) table's result
 *
 * @param tnBig
 * @param keyToPass
 * @param valueSet
 */
protected void buildNestFilters(PlanNode tnBig, Item keyToPass, Set<String> valueSet, int maxPartSize) {
    List<Item> strategyFilters = tnBig.getNestLoopFilters();
    List<Item> partList = null;
    Item keyInBig = PlanUtil.pushDownItem(node, keyToPass);
    int partSize = 0;
    for (String value : valueSet) {
        if (partList == null)
            partList = new ArrayList<>();
        if (value == null) {
            // is null will never join
            continue;
        } else {
            partList.add(new ItemString(value));
            if (++partSize >= maxPartSize) {
                List<Item> argList = new ArrayList<>();
                argList.add(keyInBig);
                argList.addAll(partList);
                ItemFuncIn inFilter = new ItemFuncIn(argList, false);
                strategyFilters.add(inFilter);
                partList = null;
                partSize = 0;
            }
        }
    }
    if (partSize > 0) {
        List<Item> argList = new ArrayList<>();
        argList.add(keyInBig);
        argList.addAll(partList);
        ItemFuncIn inFilter = new ItemFuncIn(argList, false);
        strategyFilters.add(inFilter);
    }
    // if no data
    if (strategyFilters.isEmpty()) {
        strategyFilters.add(new ItemInt(0));
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncIn(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncIn) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ArrayList(java.util.ArrayList) ItemString(com.actiontech.dble.plan.common.item.ItemString) ItemString(com.actiontech.dble.plan.common.item.ItemString)

Example 3 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class GlobalVisitor method visit.

protected void visit(JoinNode join) {
    if (!isTopQuery) {
        sqlBuilder.append(" ( ");
    }
    if (join.isSubQuery() || isTopQuery) {
        buildSelect(join);
        sqlBuilder.append(" from ");
    }
    PlanNode left = join.getLeftNode();
    MysqlVisitor leftVisitor = new GlobalVisitor(left, false);
    leftVisitor.visit();
    sqlBuilder.append(leftVisitor.getSql());
    if (join.getLeftOuter() && join.getRightOuter()) {
        throw new RuntimeException("not supported for full outer join");
    } else if (join.getLeftOuter() && !join.getRightOuter()) {
        sqlBuilder.append(" left");
    } else if (join.getRightOuter() && !join.getLeftOuter()) {
        sqlBuilder.append(" right");
    }
    sqlBuilder.append(" join ");
    PlanNode right = join.getRightNode();
    MysqlVisitor rightVisitor = new GlobalVisitor(right, false);
    rightVisitor.visit();
    sqlBuilder.append(rightVisitor.getSql());
    StringBuilder joinOnFilterStr = new StringBuilder();
    boolean first = true;
    for (int i = 0; i < join.getJoinFilter().size(); i++) {
        Item filter = join.getJoinFilter().get(i);
        if (first) {
            sqlBuilder.append(" on ");
            first = false;
        } else
            joinOnFilterStr.append(" and ");
        joinOnFilterStr.append(filter);
    }
    if (join.getOtherJoinOnFilter() != null) {
        if (!first) {
            joinOnFilterStr.append(" and ");
        }
        joinOnFilterStr.append(join.getOtherJoinOnFilter());
    }
    sqlBuilder.append(joinOnFilterStr.toString());
    if (join.isSubQuery() || isTopQuery) {
        buildWhere(join);
        buildGroupBy(join);
        buildHaving(join);
        buildOrderBy(join);
        buildLimit(join);
    } else {
        whereFilter = query.getWhereFilter();
    }
    if (!isTopQuery) {
        sqlBuilder.append(" ) ");
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 4 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class GlobalVisitor method buildHaving.

protected void buildHaving(PlanNode query) {
    if (query.getHavingFilter() != null) {
        Item filter = query.getHavingFilter();
        String pdName = visitUnSelPushDownName(filter, true);
        sqlBuilder.append(" having ").append(pdName);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 5 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class GlobalVisitor method buildOrderBy.

protected void buildOrderBy(PlanNode query) {
    boolean first = true;
    if (query.getOrderBys() != null && !query.getOrderBys().isEmpty()) {
        sqlBuilder.append(" order by ");
        for (Order order : query.getOrderBys()) {
            if (first) {
                first = false;
            } else {
                sqlBuilder.append(",");
            }
            Item orderByCol = order.getItem();
            String pdName = "";
            if (orderByCol.basicConstItem())
                pdName = "'" + orderByCol.toString() + "'";
            if (pdName.isEmpty())
                pdName = visitUnSelPushDownName(orderByCol, true);
            sqlBuilder.append(pdName).append(" ").append(order.getSortOrder());
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Aggregations

Item (com.actiontech.dble.plan.common.item.Item)122 ArrayList (java.util.ArrayList)26 Order (com.actiontech.dble.plan.Order)16 PlanNode (com.actiontech.dble.plan.node.PlanNode)14 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)10 ItemField (com.actiontech.dble.plan.common.item.ItemField)10 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)7 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)7 Test (org.junit.Test)7 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)6 JoinNode (com.actiontech.dble.plan.node.JoinNode)6 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)6 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)5 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)4 ItemString (com.actiontech.dble.plan.common.item.ItemString)4 BigDecimal (java.math.BigDecimal)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 NamedField (com.actiontech.dble.plan.NamedField)3