Search in sources :

Example 1 with ExtendedDataInputStream

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

the class MemoryDataStorageManager method getIndexStatus.

@Override
public IndexStatus getIndexStatus(String tableSpace, String indexName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
    final String checkPoint = checkpointName(tableSpace, indexName, sequenceNumber);
    byte[] data = indexStatuses.get(checkPoint);
    if (data == null) {
        throw new DataStorageManagerException("no such index checkpoint: " + checkPoint);
    }
    try {
        try (InputStream input = new SimpleByteArrayInputStream(data);
            ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
            return IndexStatus.deserialize(dataIn);
        }
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 2 with ExtendedDataInputStream

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

the class MemoryDataStorageManager method getTableStatus.

@Override
public TableStatus getTableStatus(String tableSpace, String tableName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
    final String checkPoint = checkpointName(tableSpace, tableName, sequenceNumber);
    byte[] data = tableStatuses.get(checkPoint);
    if (data == null) {
        throw new DataStorageManagerException("no such tablee checkpoint: " + checkPoint);
    }
    try {
        try (InputStream input = new SimpleByteArrayInputStream(data);
            ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
            return TableStatus.deserialize(dataIn);
        }
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 3 with ExtendedDataInputStream

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

the class RecordSerializer method deserializeMultiColumnPrimaryKey.

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

Example 4 with ExtendedDataInputStream

use of herddb.utils.ExtendedDataInputStream 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);
    }
    SimpleByteArrayInputStream s = new SimpleByteArrayInputStream(value.data);
    ExtendedDataInputStream din = new ExtendedDataInputStream(s);
    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 : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) Column(herddb.model.Column) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream)

Example 5 with ExtendedDataInputStream

use of herddb.utils.ExtendedDataInputStream 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.data, table);
            res.put(table.primaryKey[0], key);
        } else {
            deserializeMultiColumnPrimaryKey(record.key.data, table, res);
        }
        if (record.value != null && record.value.data.length > 0) {
            SimpleByteArrayInputStream s = new SimpleByteArrayInputStream(record.value.data);
            ExtendedDataInputStream din = new ExtendedDataInputStream(s);
            while (true) {
                int serialPosition;
                serialPosition = din.readVIntNoEOFException();
                if (din.isEof()) {
                    break;
                }
                // we have to deserialize always the value, even the column is no more present
                Object v = deserializeTypeAndValue(din);
                Column col = table.getColumnBySerialPosition(serialPosition);
                if (col != null) {
                    res.put(col.name, v);
                }
            }
        }
        return res.build();
    } catch (IOException err) {
        throw new IllegalArgumentException("malformed record", err);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) Column(herddb.model.Column) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) RawString(herddb.utils.RawString) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)25 SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)25 IOException (java.io.IOException)18 InputStream (java.io.InputStream)15 DataStorageManagerException (herddb.storage.DataStorageManagerException)14 BufferedInputStream (java.io.BufferedInputStream)11 LogSequenceNumber (herddb.log.LogSequenceNumber)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 Column (herddb.model.Column)4 RawString (herddb.utils.RawString)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 XXHash64Utils (herddb.utils.XXHash64Utils)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 KeyToPageIndex (herddb.index.KeyToPageIndex)1 BLinkKeyToPageIndex (herddb.index.blink.BLinkKeyToPageIndex)1 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 Index (herddb.model.Index)1 Record (herddb.model.Record)1 Table (herddb.model.Table)1