Search in sources :

Example 11 with Item

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

the class PushDownVisitor method getJoinOn.

private StringBuilder getJoinOn(JoinNode join, MysqlVisitor leftVisitor, MysqlVisitor rightVisitor) {
    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());
    }
    // is not left join
    if (leftVisitor.getWhereFilter() != null && !join.getLeftOuter()) {
        if (!first) {
            joinOnFilterStr.append(" and ");
        }
        joinOnFilterStr.append("(");
        joinOnFilterStr.append(leftVisitor.getWhereFilter());
        joinOnFilterStr.append(")");
    }
    // is not right join
    if (rightVisitor.getWhereFilter() != null && !join.getRightOuter()) {
        if (!first) {
            joinOnFilterStr.append(" and ");
        }
        joinOnFilterStr.append("(");
        joinOnFilterStr.append(rightVisitor.getWhereFilter());
        joinOnFilterStr.append(")");
    }
    return joinOnFilterStr;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 12 with Item

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

the class PushDownVisitor method visitPushDownNameSel.

@Override
protected String visitPushDownNameSel(Item item) {
    String orgPushDownName = null;
    if (item.isWithSubQuery()) {
        Item tmpItem = PlanUtil.rebuildSubQueryItem(item);
        orgPushDownName = tmpItem.getItemName();
    } else {
        orgPushDownName = item.getItemName();
    }
    if (item.type().equals(Item.ItemType.FIELD_ITEM)) {
        orgPushDownName = "`" + item.getTableName() + "`.`" + orgPushDownName + "`";
    }
    String pushAlias = null;
    if (pushNameMap.containsKey(orgPushDownName)) {
        // duplicate column
        item.setPushDownName(pushNameMap.get(orgPushDownName));
        return null;
    }
    if (item.type().equals(Item.ItemType.SUM_FUNC_ITEM)) {
        // generate alias for aggregate function,it must contain the real name
        String aggName = ((ItemSum) item).funcName().toUpperCase();
        pushAlias = getMadeAggAlias(aggName) + getRandomAliasName();
    } else if (item.getAlias() != null) {
        pushAlias = item.getAlias();
        if (pushAlias.startsWith(Item.FNAF))
            pushAlias = getRandomAliasName();
    } else if (orgPushDownName.length() > MAX_COL_LENGTH) {
        pushAlias = getRandomAliasName();
    } else if (isTopQuery && !item.type().equals(Item.ItemType.FIELD_ITEM)) {
        pushAlias = getRandomAliasName();
    }
    if (pushAlias == null) {
        if (item.type().equals(Item.ItemType.FIELD_ITEM)) {
            pushNameMap.put(orgPushDownName, null);
        } else {
            item.setPushDownName(orgPushDownName);
            pushNameMap.put(orgPushDownName, orgPushDownName);
        }
    } else {
        item.setPushDownName(pushAlias);
        pushNameMap.put(orgPushDownName, pushAlias);
    }
    if (pushAlias == null)
        return orgPushDownName;
    else
        return orgPushDownName + " as `" + pushAlias + "`";
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 13 with Item

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

the class DistinctHandler method fieldEofResponse.

/**
 * treat all the data from parent as Field Type
 */
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, final List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
    if (terminate.get())
        return;
    if (this.pool == null)
        this.pool = DbleServer.getInstance().getBufferPool();
    this.fieldPackets = fieldPackets;
    List<Field> sourceFields = HandlerTool.createFields(this.fieldPackets);
    if (this.distinctCols == null) {
        // eg:show tables
        this.distinctCols = new ArrayList<>();
        for (FieldPacket fp : this.fieldPackets) {
            Item sel = HandlerTool.createItemField(fp);
            this.distinctCols.add(sel);
        }
    }
    List<Order> orders = this.fixedOrders;
    if (orders == null)
        orders = HandlerTool.makeOrder(this.distinctCols);
    RowDataComparator comparator = new RowDataComparator(this.fieldPackets, orders, this.isAllPushDown(), type());
    localResult = new DistinctLocalResult(pool, sourceFields.size(), comparator, CharsetUtil.getJavaCharset(conn.getCharset().getResults())).setMemSizeController(session.getOtherBufferMC());
    nextHandler.fieldEofResponse(null, null, this.fieldPackets, null, this.isLeft, conn);
}
Also used : Order(com.actiontech.dble.plan.Order) Field(com.actiontech.dble.plan.common.field.Field) Item(com.actiontech.dble.plan.common.item.Item) DistinctLocalResult(com.actiontech.dble.backend.mysql.store.DistinctLocalResult) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Example 14 with Item

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

the class HandlerTool method makeOrder.

/**
 * make order by from distinct
 *
 * @param selects
 * @return
 */
public static List<Order> makeOrder(List<Item> selects) {
    List<Order> orders = new ArrayList<>();
    for (Item sel : selects) {
        Order order = new Order(sel, SQLOrderingSpecification.ASC);
        orders.add(order);
    }
    return orders;
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) ArrayList(java.util.ArrayList)

Example 15 with Item

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

the class HandlerTool method createFunctionItem.

protected static ItemFunc createFunctionItem(ItemFunc f, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
    ItemFunc ret = null;
    List<Item> args = new ArrayList<>();
    for (int index = 0; index < f.getArgCount(); index++) {
        Item arg = f.arguments().get(index);
        Item newArg = null;
        if (arg.isWild())
            newArg = new ItemInt(0);
        else
            newArg = createItem(arg, fields, startIndex, allPushDown, type);
        if (newArg == null)
            throw new RuntimeException("Function argument not found:" + arg);
        args.add(newArg);
    }
    ret = (ItemFunc) f.reStruct(args, allPushDown, fields);
    ret.setItemName(f.getPushDownName() == null ? f.getItemName() : f.getPushDownName());
    return ret;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ArrayList(java.util.ArrayList)

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