use of com.questdb.std.str.FlexBufferSink in project questdb by bluestreak01.
the class JournalWriter method writeDiscardFile.
private void writeDiscardFile(long rowid) throws JournalException {
if (discardTxtRaf == null) {
try {
discardTxtRaf = new RandomAccessFile(discardTxt, "rw");
FileChannel ch = discardTxtRaf.getChannel();
discardSink = new FlexBufferSink(ch.position(ch.size()), 1024 * 1024);
} catch (IOException e) {
LOG.error().$(e).$();
throw JournalIOException.INSTANCE;
}
}
JournalMetadata m = getMetadata();
int p = Rows.toPartitionIndex(rowid);
long row = Rows.toLocalRowID(rowid);
long rowCount = 0;
try {
try {
// partitions
for (int n = getPartitionCount() - 1; p < n; p++) {
final Partition partition = getPartition(n, true);
// partition rows
for (long r = row, psz = partition.size(); r < psz; r++) {
// partition columns
for (int c = 0, cc = m.getColumnCount(); c < cc; c++) {
switch(m.getColumnQuick(c).type) {
case ColumnType.DATE:
DateFormatUtils.appendDateTime(discardSink, partition.getLong(r, c));
break;
case ColumnType.DOUBLE:
Numbers.append(discardSink, partition.getDouble(r, c), 12);
break;
case ColumnType.FLOAT:
Numbers.append(discardSink, partition.getFloat(r, c), 4);
break;
case ColumnType.INT:
Numbers.append(discardSink, partition.getInt(r, c));
break;
case ColumnType.STRING:
partition.getStr(r, c, discardSink);
break;
case ColumnType.SYMBOL:
discardSink.put(partition.getSym(r, c));
break;
case ColumnType.SHORT:
Numbers.append(discardSink, partition.getShort(r, c));
break;
case ColumnType.LONG:
Numbers.append(discardSink, partition.getLong(r, c));
break;
case ColumnType.BYTE:
Numbers.append(discardSink, partition.getByte(r, c));
break;
case ColumnType.BOOLEAN:
discardSink.put(partition.getBool(r, c) ? "true" : "false");
break;
default:
break;
}
if (((++rowCount) & 7) == 0) {
discardSink.flush();
}
}
}
}
} finally {
discardSink.flush();
}
} catch (IOException e) {
LOG.error().$(e).$();
throw JournalIOException.INSTANCE;
}
}
Aggregations