Search in sources :

Example 46 with Value

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

the class ConditionNot method optimize.

@Override
public Expression optimize(Session session) {
    Expression e2 = condition.getNotIfPossible(session);
    if (e2 != null) {
        return e2.optimize(session);
    }
    Expression expr = condition.optimize(session);
    if (expr.isConstant()) {
        Value v = expr.getValue(session);
        if (v == ValueNull.INSTANCE) {
            return ValueExpression.getNull();
        }
        return ValueExpression.get(v.convertTo(Value.BOOLEAN).negate());
    }
    condition = expr;
    return this;
}
Also used : Value(com.wplatform.ddal.value.Value)

Example 47 with Value

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

the class ResultDiskBuffer method readRow.

private void readRow(ResultDiskTape tape) {
    int min = Constants.FILE_BLOCK_SIZE;
    Data buff = rowBuff;
    buff.reset();
    readFully(buff.getBytes(), 0, min);
    int len = buff.readInt();
    buff.checkCapacity(len);
    if (len - min > 0) {
        readFully(buff.getBytes(), min, len - min);
    }
    tape.pos += len;
    Value[] row = new Value[columnCount];
    for (int k = 0; k < columnCount; k++) {
        row[k] = buff.readValue();
    }
    tape.buffer.add(row);
}
Also used : Value(com.wplatform.ddal.value.Value) Data(com.wplatform.ddal.util.Data)

Example 48 with Value

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

the class ResultDiskBuffer method addRows.

public int addRows(ArrayList<Value[]> rows) {
    if (sort != null) {
        sort.sort(rows);
    }
    Data buff = rowBuff;
    long start = getFilePointer();
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    int bufferLen = 0;
    for (Value[] row : rows) {
        buff.reset();
        buff.writeInt(0);
        for (int j = 0; j < columnCount; j++) {
            Value v = row[j];
            buff.checkCapacity(Data.getValueLen(v));
            buff.writeValue(v);
        }
        buff.fillAligned();
        int len = buff.length();
        buff.setInt(0, len);
        if (maxBufferSize > 0) {
            buffer.write(buff.getBytes(), 0, len);
            bufferLen += len;
            if (bufferLen > maxBufferSize) {
                byte[] data = buffer.toByteArray();
                buffer.reset();
                write(data, 0, data.length);
                bufferLen = 0;
            }
        } else {
            write(buff.getBytes(), 0, len);
        }
    }
    if (bufferLen > 0) {
        byte[] data = buffer.toByteArray();
        write(data, 0, data.length);
    }
    if (sort != null) {
        ResultDiskTape tape = new ResultDiskTape();
        tape.start = start;
        tape.end = getFilePointer();
        tapes.add(tape);
    } else {
        mainTape.end = getFilePointer();
    }
    rowCount += rows.size();
    return rowCount;
}
Also used : Value(com.wplatform.ddal.value.Value) Data(com.wplatform.ddal.util.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 49 with Value

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

the class Row method toString.

@Override
public String toString() {
    StatementBuilder buff = new StatementBuilder("( /* key:");
    buff.append(getKey());
    if (version != 0) {
        buff.append(" v:" + version);
    }
    if (isDeleted()) {
        buff.append(" deleted");
    }
    buff.append(" */ ");
    if (data != null) {
        for (Value v : data) {
            buff.appendExceptFirst(", ");
            buff.append(v == null ? "null" : v.getTraceSQL());
        }
    }
    return buff.append(')').toString();
}
Also used : StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Value(com.wplatform.ddal.value.Value)

Example 50 with Value

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

the class Row method getMemory.

@Override
public int getMemory() {
    if (memory != MEMORY_CALCULATE) {
        return memory;
    }
    int m = Constants.MEMORY_ROW;
    if (data != null) {
        int len = data.length;
        m += Constants.MEMORY_OBJECT + len * Constants.MEMORY_POINTER;
        for (int i = 0; i < len; i++) {
            Value v = data[i];
            if (v != null) {
                m += v.getMemory();
            }
        }
    }
    this.memory = m;
    return m;
}
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