Search in sources :

Example 96 with Item

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

the class ItemFuncIf method valStr.

@Override
public String valStr() {
    if (fieldType() == FieldTypes.MYSQL_TYPE_DATETIME || fieldType() == FieldTypes.MYSQL_TYPE_TIMESTAMP) {
        return valStringFromDatetime();
    } else if (fieldType() == FieldTypes.MYSQL_TYPE_DATE) {
        return valStringFromDate();
    } else if (fieldType() == FieldTypes.MYSQL_TYPE_TIME) {
        return valStringFromTime();
    } else {
        Item item = args.get(0).valBool() ? args.get(1) : args.get(2);
        String res;
        if ((res = item.valStr()) != null) {
            nullValue = false;
            return res;
        }
    }
    nullValue = true;
    return null;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 97 with Item

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

the class ItemFuncIf method valDecimal.

@Override
public BigDecimal valDecimal() {
    Item arg = args.get(0).valBool() ? args.get(1) : args.get(2);
    BigDecimal value = arg.valDecimal();
    nullValue = arg.isNullValue();
    return value;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) BigDecimal(java.math.BigDecimal)

Example 98 with Item

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

the class ItemFuncGroupConcat method add.

@Override
public boolean add(RowDataPacket row, Object tranObject) {
    if (alwaysNull)
        return false;
    StringBuilder rowStr = new StringBuilder();
    for (int i = 0; i < getArgCount(); i++) {
        Item item = args.get(i);
        String s = item.valStr();
        if (item.isNull())
            return false;
        rowStr.append(s);
    }
    nullValue = false;
    if (resultSb.length() > 0)
        resultSb.append(seperator);
    resultSb.append(rowStr);
    return false;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 99 with Item

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

the class ItemSum method fixFields.

@Override
public final ItemSum fixFields(NameResolutionContext context) {
    getReferTables().clear();
    for (int index = 0; index < getArgCount(); index++) {
        Item arg = args.get(index);
        Item fixedArg = arg.fixFields(context);
        if (fixedArg == null)
            return null;
        args.set(index, fixedArg);
        getReferTables().addAll(fixedArg.getReferTables());
        withIsNull = withIsNull || fixedArg.isWithIsNull();
        withSubQuery = withSubQuery || fixedArg.isWithSubQuery();
    }
    return this;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 100 with Item

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

the class ItemSumAvg method toExpression.

@Override
public SQLExpr toExpression() {
    Item arg0 = args.get(0);
    SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName());
    aggregate.addArgument(arg0.toExpression());
    if (hasWithDistinct()) {
        aggregate.setOption(SQLAggregateOption.DISTINCT);
    }
    return aggregate;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) SQLAggregateExpr(com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)

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