Search in sources :

Example 1 with ItemField

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

the class GetYearValue method get.

@Override
public long get(Item item, Item warnitem, BoolPtr isNull) {
    long value = 0;
    value = item.valInt().longValue();
    isNull.set(item.isNullValue());
    if (isNull.get())
        return 0;
    /*
         * Coerce value to the 19XX form in order to correctly compare YEAR(2) &
         * YEAR(4) types. Here we are converting all item values but YEAR(4)
         * fields since 1) YEAR(4) already has a regular YYYY form and 2) we
         * don't want to convert zero/bad YEAR(4) values to the value of 2000.
         */
    if (item.type() == Item.ItemType.FIELD_ITEM) {
        Field field = ((ItemField) item).getField();
        if (field.fieldType() == FieldTypes.MYSQL_TYPE_YEAR && field.getFieldLength() == 4) {
            if (value < 70)
                value += 100;
            if (value <= 1900)
                value += 1900;
        }
    }
    /* Convert year to DATETIME packed format */
    return MyTime.yearToLonglongDatetimePacked(value);
}
Also used : ItemField(com.actiontech.dble.plan.common.item.ItemField) Field(com.actiontech.dble.plan.common.field.Field) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 2 with ItemField

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

the class SelectedProcessor method mergePushOrderBy.

private static void mergePushOrderBy(Item orderSel, List<Item> mergeSelects) {
    if (orderSel instanceof ItemField) {
        if (!mergeSelects.contains(orderSel))
            mergeSelects.add(orderSel);
    } else if (orderSel instanceof ItemFunc) {
        ItemFunc func = (ItemFunc) orderSel;
        if (func.isWithSumFunc()) {
            for (int index = 0; index < func.getArgCount(); index++) {
                Item arg = func.arguments().get(index);
                mergePushOrderBy(arg, mergeSelects);
            }
        } else {
            if (!mergeSelects.contains(func)) {
                mergeSelects.add(func);
            }
            // union's order by must be found from selects
            func.setPushDownName(func.getItemName());
        }
    } else if (orderSel instanceof ItemSum) {
        ItemSum func = (ItemSum) orderSel;
        for (int index = 0; index < func.getArgCount(); index++) {
            Item arg = func.arguments().get(index);
            mergePushOrderBy(arg, mergeSelects);
        }
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 3 with ItemField

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

the class SubQueryPreProcessor method transformInSubQuery.

private static SubQueryFilter transformInSubQuery(SubQueryFilter qtn, ItemInSubQuery filter, BoolPtr childTransform) {
    Item leftColumn = filter.getLeftOperand();
    PlanNode query = filter.getPlanNode();
    query = findComparisonsSubQueryToJoinNode(query, childTransform);
    QueryNode changeQuery = new QueryNode(query);
    String alias = AUTOALIAS + query.getPureName();
    changeQuery.setAlias(alias);
    if (query.getColumnsSelected().size() != 1)
        throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "only support subquery of one column");
    query.setSubQuery(true).setDistinct(true);
    final List<Item> newSelects = qtn.query.getColumnsSelected();
    SubQueryFilter result = new SubQueryFilter();
    Item rightColumn = query.getColumnsSelected().get(0);
    qtn.query.setColumnsSelected(new ArrayList<Item>());
    String rightJoinName = rightColumn.getAlias();
    if (StringUtils.isEmpty(rightJoinName)) {
        if (rightColumn instanceof ItemField) {
            rightJoinName = rightColumn.getItemName();
        } else {
            rightColumn.setAlias(AUTONAME);
            rightJoinName = AUTONAME;
        }
    }
    ItemField rightJoinColumn = new ItemField(null, alias, rightJoinName);
    // rename the left column's table name
    result.query = new JoinNode(qtn.query, changeQuery);
    // leave origin sql to new join node
    result.query.setSql(qtn.query.getSql());
    qtn.query.setSql(null);
    result.query.select(newSelects);
    qtn.query.setSubQuery(false);
    if (!qtn.query.getOrderBys().isEmpty()) {
        List<Order> orderBys = new ArrayList<>();
        orderBys.addAll(qtn.query.getOrderBys());
        result.query.setOrderBys(orderBys);
        qtn.query.getOrderBys().clear();
    }
    if (!qtn.query.getGroupBys().isEmpty()) {
        List<Order> groupBys = new ArrayList<>();
        groupBys.addAll(qtn.query.getGroupBys());
        result.query.setGroupBys(groupBys);
        qtn.query.getGroupBys().clear();
        result.query.having(qtn.query.getHavingFilter());
        qtn.query.having(null);
    }
    if (qtn.query.getLimitFrom() != -1) {
        result.query.setLimitFrom(qtn.query.getLimitFrom());
        qtn.query.setLimitFrom(-1);
    }
    if (qtn.query.getLimitTo() != -1) {
        result.query.setLimitTo(qtn.query.getLimitTo());
        qtn.query.setLimitTo(-1);
    }
    if (filter.isNeg()) {
        ((JoinNode) result.query).setLeftOuterJoin().setNotIn(true);
        ItemFuncEqual joinFilter = FilterUtils.equal(leftColumn, rightJoinColumn);
        ((JoinNode) result.query).addJoinFilter(joinFilter);
        result.filter = null;
    } else {
        Item joinFilter = FilterUtils.equal(leftColumn, rightJoinColumn);
        result.query.query(joinFilter);
        result.filter = joinFilter;
    }
    result.query.setUpFields();
    return result;
}
Also used : Order(com.actiontech.dble.plan.Order) JoinNode(com.actiontech.dble.plan.node.JoinNode) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual) ArrayList(java.util.ArrayList) ItemField(com.actiontech.dble.plan.common.item.ItemField) Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) QueryNode(com.actiontech.dble.plan.node.QueryNode) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 4 with ItemField

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

the class PlanNode method dealSingleStarColumn.

protected void dealSingleStarColumn(List<Item> newSels) {
    for (NamedField field : innerFields.keySet()) {
        ItemField col = new ItemField(null, field.getTable(), field.getName());
        newSels.add(col);
    }
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 5 with ItemField

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

the class PlanNode method setUpSelects.

protected void setUpSelects() {
    if (columnsSelected.isEmpty()) {
        columnsSelected.add(new ItemField(null, null, "*"));
    }
    boolean withWild = false;
    for (Item sel : columnsSelected) {
        if (sel.isWild())
            withWild = true;
    }
    if (withWild)
        dealStarColumn();
    outerFields.clear();
    nameContext.setFindInSelect(false);
    nameContext.setSelectFirst(false);
    for (Item sel : columnsSelected) {
        setUpItem(sel);
        NamedField field = makeOutNamedField(sel);
        if (outerFields.containsKey(field) && getParent() != null)
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "duplicate field");
        outerFields.put(field, sel);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) NamedField(com.actiontech.dble.plan.NamedField) ItemField(com.actiontech.dble.plan.common.item.ItemField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Aggregations

ItemField (com.actiontech.dble.plan.common.item.ItemField)20 Item (com.actiontech.dble.plan.common.item.Item)10 NamedField (com.actiontech.dble.plan.NamedField)6 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)4 ArrayList (java.util.ArrayList)4 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)3 JoinNode (com.actiontech.dble.plan.node.JoinNode)3 TableNode (com.actiontech.dble.plan.node.TableNode)3 ERTable (com.actiontech.dble.config.model.ERTable)2 Order (com.actiontech.dble.plan.Order)2 Field (com.actiontech.dble.plan.common.field.Field)2 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 QueryNode (com.actiontech.dble.plan.node.QueryNode)1 List (java.util.List)1