Search in sources :

Example 1 with ByteArrayCursor

use of herddb.utils.ByteArrayCursor in project herddb by diennea.

the class RecordSerializer method deserializeMultiColumnPrimaryKey.

private static void deserializeMultiColumnPrimaryKey(Bytes data, Table table, Map<String, Object> res) {
    try (ByteArrayCursor din = data.newCursor()) {
        for (String primaryKeyColumn : table.primaryKey) {
            Bytes value = din.readBytesNoCopy();
            res.put(primaryKeyColumn, deserialize(value, table.getColumn(primaryKeyColumn).type));
        }
    } catch (IOException err) {
        throw new IllegalArgumentException("malformed record", err);
    }
}
Also used : Bytes(herddb.utils.Bytes) RawString(herddb.utils.RawString) IOException(java.io.IOException) ByteArrayCursor(herddb.utils.ByteArrayCursor)

Example 2 with ByteArrayCursor

use of herddb.utils.ByteArrayCursor in project herddb by diennea.

the class RecordSerializer method accessRawDataFromValue.

static Object accessRawDataFromValue(String property, Bytes value, Table table) throws IOException {
    if (table.getColumn(property) == null) {
        throw new herddb.utils.IllegalDataAccessException("table " + table.tablespace + "." + table.name + " does not define column " + property);
    }
    try (ByteArrayCursor din = value.newCursor()) {
        while (!din.isEof()) {
            int serialPosition;
            serialPosition = din.readVIntNoEOFException();
            if (din.isEof()) {
                return null;
            }
            Column col = table.getColumnBySerialPosition(serialPosition);
            if (col != null && col.name.equals(property)) {
                return deserializeTypeAndValue(din);
            } else {
                // we have to deserialize always the value, even the column is no more present
                skipTypeAndValue(din);
            }
        }
        return null;
    }
}
Also used : Column(herddb.model.Column) ByteArrayCursor(herddb.utils.ByteArrayCursor)

Example 3 with ByteArrayCursor

use of herddb.utils.ByteArrayCursor in project herddb by diennea.

the class RecordSerializer method compareRawDataFromValue.

static SQLRecordPredicateFunctions.CompareResult compareRawDataFromValue(int index, Bytes value, Table table, Object cvalue) throws IOException {
    Column column = table.getColumn(index);
    try (ByteArrayCursor din = value.newCursor()) {
        while (!din.isEof()) {
            int serialPosition;
            serialPosition = din.readVIntNoEOFException();
            if (din.isEof()) {
                return CompareResult.NULL;
            }
            Column col = table.getColumnBySerialPosition(serialPosition);
            if (col != null && col.serialPosition == column.serialPosition) {
                return compareDeserializeTypeAndValue(din, cvalue);
            } else {
                // we have to deserialize always the value, even the column is no more present
                skipTypeAndValue(din);
            }
        }
    }
    return CompareResult.NULL;
}
Also used : Column(herddb.model.Column) ByteArrayCursor(herddb.utils.ByteArrayCursor)

Example 4 with ByteArrayCursor

use of herddb.utils.ByteArrayCursor in project herddb by diennea.

the class RecordSerializer method toBean.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public static Map<String, Object> toBean(Record record, Table table) {
    try {
        ImmutableMap.Builder<String, Object> res = new ImmutableMap.Builder<>();
        if (table.primaryKey.length == 1) {
            Object key = deserializeSingleColumnPrimaryKey(record.key, table);
            res.put(table.primaryKey[0], key);
        } else {
            deserializeMultiColumnPrimaryKey(record.key, table, res);
        }
        if (record.value != null && record.value.getLength() > 0) {
            try (ByteArrayCursor din = record.value.newCursor()) {
                while (true) {
                    int serialPosition;
                    serialPosition = din.readVIntNoEOFException();
                    if (din.isEof()) {
                        break;
                    }
                    Column col = table.getColumnBySerialPosition(serialPosition);
                    // we have to deserialize or skip always the value, even the column is no more present
                    if (col != null) {
                        Object v = deserializeTypeAndValue(din);
                        res.put(col.name, v);
                    } else {
                        skipTypeAndValue(din);
                    }
                }
            }
        }
        return res.build();
    } catch (IOException err) {
        throw new IllegalArgumentException("malformed record", err);
    }
}
Also used : Column(herddb.model.Column) RawString(herddb.utils.RawString) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) ByteArrayCursor(herddb.utils.ByteArrayCursor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with ByteArrayCursor

use of herddb.utils.ByteArrayCursor in project herddb by diennea.

the class RecordSerializer method deserializeMultiColumnPrimaryKey.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
private static void deserializeMultiColumnPrimaryKey(Bytes data, Table table, ImmutableMap.Builder<String, Object> res) {
    try (ByteArrayCursor din = data.newCursor()) {
        for (String primaryKeyColumn : table.primaryKey) {
            Bytes value = din.readBytesNoCopy();
            res.put(primaryKeyColumn, deserialize(value, table.getColumn(primaryKeyColumn).type));
        }
    } catch (IOException err) {
        throw new IllegalArgumentException("malformed record", err);
    }
}
Also used : Bytes(herddb.utils.Bytes) RawString(herddb.utils.RawString) IOException(java.io.IOException) ByteArrayCursor(herddb.utils.ByteArrayCursor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ByteArrayCursor (herddb.utils.ByteArrayCursor)12 IOException (java.io.IOException)6 Column (herddb.model.Column)5 Bytes (herddb.utils.Bytes)5 DataStorageManagerException (herddb.storage.DataStorageManagerException)4 RawString (herddb.utils.RawString)4 ArrayList (java.util.ArrayList)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Record (herddb.model.Record)2 ImmutableMap (com.google.common.collect.ImmutableMap)1