Search in sources :

Example 11 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class ExpressionColumn method getValue.

@Override
public Value getValue(Session session) {
    Select select = columnResolver.getSelect();
    if (select != null) {
        HashMap<Expression, Object> values = select.getCurrentGroup();
        if (values != null) {
            Value v = (Value) values.get(this);
            if (v != null) {
                return v;
            }
        }
    }
    Value value = columnResolver.getValue(column);
    if (value == null) {
        columnResolver.getValue(column);
        throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
    }
    return value;
}
Also used : Select(com.wplatform.ddal.command.dml.Select) Value(com.wplatform.ddal.value.Value)

Example 12 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class AggregateDataHistogram method getValue.

@Override
Value getValue(Database database, int dataType, boolean distinct) {
    if (distinct) {
        count = 0;
        groupDistinct(database, dataType);
    }
    ValueArray[] values = new ValueArray[distinctValues.size()];
    int i = 0;
    for (Value dv : distinctValues.keys()) {
        AggregateDataHistogram d = distinctValues.get(dv);
        values[i] = ValueArray.get(new Value[] { dv, ValueLong.get(d.count) });
        i++;
    }
    final CompareMode compareMode = database.getCompareMode();
    Arrays.sort(values, new Comparator<ValueArray>() {

        @Override
        public int compare(ValueArray v1, ValueArray v2) {
            Value a1 = v1.getList()[0];
            Value a2 = v2.getList()[0];
            return a1.compareTo(a2, compareMode);
        }
    });
    Value v = ValueArray.get(values);
    return v.convertTo(dataType);
}
Also used : Value(com.wplatform.ddal.value.Value) CompareMode(com.wplatform.ddal.value.CompareMode) ValueArray(com.wplatform.ddal.value.ValueArray)

Example 13 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class AggregateDataSelectivity method getValue.

@Override
Value getValue(Database database, int dataType, boolean distinct) {
    if (distinct) {
        count = 0;
    }
    Value v = null;
    int s = 0;
    if (count == 0) {
        s = 0;
    } else {
        m2 += distinctHashes.size();
        m2 = 100 * m2 / count;
        s = (int) m2;
        s = s <= 0 ? 1 : s > 100 ? 100 : s;
    }
    v = ValueInt.get(s);
    return v.convertTo(dataType);
}
Also used : Value(com.wplatform.ddal.value.Value)

Example 14 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class Comparison method getValue.

@Override
public Value getValue(Session session) {
    Value l = left.getValue(session);
    if (right == null) {
        boolean result;
        switch(compareType) {
            case IS_NULL:
                result = l == ValueNull.INSTANCE;
                break;
            case IS_NOT_NULL:
                result = !(l == ValueNull.INSTANCE);
                break;
            default:
                throw DbException.throwInternalError("type=" + compareType);
        }
        return ValueBoolean.get(result);
    }
    if (l == ValueNull.INSTANCE) {
        if ((compareType & NULL_SAFE) == 0) {
            return ValueNull.INSTANCE;
        }
    }
    Value r = right.getValue(session);
    if (r == ValueNull.INSTANCE) {
        if ((compareType & NULL_SAFE) == 0) {
            return ValueNull.INSTANCE;
        }
    }
    int dataType = Value.getHigherOrder(left.getType(), right.getType());
    l = l.convertTo(dataType);
    r = r.convertTo(dataType);
    boolean result = compareNotNull(database, l, r, compareType);
    return ValueBoolean.get(result);
}
Also used : Value(com.wplatform.ddal.value.Value)

Example 15 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class ConditionAndOr method getValue.

@Override
public Value getValue(Session session) {
    Value l = left.getValue(session);
    Value r;
    switch(andOrType) {
        case AND:
            {
                if (Boolean.FALSE.equals(l.getBoolean())) {
                    return l;
                }
                r = right.getValue(session);
                if (Boolean.FALSE.equals(r.getBoolean())) {
                    return r;
                }
                if (l == ValueNull.INSTANCE) {
                    return l;
                }
                if (r == ValueNull.INSTANCE) {
                    return r;
                }
                return ValueBoolean.get(true);
            }
        case OR:
            {
                if (Boolean.TRUE.equals(l.getBoolean())) {
                    return l;
                }
                r = right.getValue(session);
                if (Boolean.TRUE.equals(r.getBoolean())) {
                    return r;
                }
                if (l == ValueNull.INSTANCE) {
                    return l;
                }
                if (r == ValueNull.INSTANCE) {
                    return r;
                }
                return ValueBoolean.get(false);
            }
        default:
            throw DbException.throwInternalError("type=" + andOrType);
    }
}
Also used : Value(com.wplatform.ddal.value.Value)

Aggregations

Value (com.wplatform.ddal.value.Value)84 Expression (com.wplatform.ddal.command.expression.Expression)14 Column (com.wplatform.ddal.dbobject.table.Column)14 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)13 DbException (com.wplatform.ddal.message.DbException)9 SQLException (java.sql.SQLException)8 Row (com.wplatform.ddal.result.Row)7 SearchRow (com.wplatform.ddal.result.SearchRow)7 PreparedStatement (java.sql.PreparedStatement)7 TableMate (com.wplatform.ddal.dbobject.table.TableMate)6 LocalResult (com.wplatform.ddal.result.LocalResult)6 ResultInterface (com.wplatform.ddal.result.ResultInterface)5 Connection (java.sql.Connection)5 Parameter (com.wplatform.ddal.command.expression.Parameter)4 List (java.util.List)4 DataSource (javax.sql.DataSource)4 Query (com.wplatform.ddal.command.dml.Query)3 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)3 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)3 JdbcWorker (com.wplatform.ddal.excutor.JdbcWorker)3