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);
}
}
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;
}
}
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;
}
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);
}
}
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);
}
}
Aggregations