use of com.questdb.store.factory.configuration.JournalMetadata 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;
}
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class DDLTests method testCreateDefaultPartitionBy.
@Test
public void testCreateDefaultPartitionBy() throws Exception {
exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100");
// validate journal
try (Journal r = getFactory().reader("x")) {
Assert.assertNotNull(r);
JournalMetadata m = r.getMetadata();
Assert.assertEquals(5, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(1, m.getColumn("a").getBucketCount());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertTrue(m.getColumn("z").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(63, m.getColumn("z").getBucketCount());
Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType());
Assert.assertTrue(m.getColumn("l").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(511, m.getColumn("l").getBucketCount());
Assert.assertEquals(-1, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
}
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class DDLTests method testCreateIndexedIntDefaultBuckets.
@Test
public void testCreateIndexedIntDefaultBuckets() throws Exception {
exec("create table x (a INT index, b BYTE, t DATE, x SYMBOL) timestamp(t) partition by MONTH record hint 100");
// validate journal
try (Journal r = getFactory().reader("x")) {
Assert.assertNotNull(r);
JournalMetadata m = r.getMetadata();
Assert.assertEquals(4, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(1, m.getColumn("a").getBucketCount());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
Assert.assertEquals(2, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy());
}
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class DDLTests method testCreateIndexedString.
@Test
public void testCreateIndexedString() throws Exception {
exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40) timestamp(t) partition by MONTH record hint 100");
// validate journal
try (Journal r = getFactory().reader("x")) {
Assert.assertNotNull(r);
JournalMetadata m = r.getMetadata();
Assert.assertEquals(4, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(1, m.getColumn("a").getBucketCount());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertTrue(m.getColumn("z").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(63, m.getColumn("z").getBucketCount());
Assert.assertEquals(2, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy());
}
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class DDLTests method testCreateQuotedName.
@Test
public void testCreateQuotedName() throws Exception {
exec("create table 'a b' (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100");
// validate journal
try (Journal r = getFactory().reader("a b")) {
Assert.assertNotNull(r);
JournalMetadata m = r.getMetadata();
Assert.assertEquals(5, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(1, m.getColumn("a").getBucketCount());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertTrue(m.getColumn("z").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(63, m.getColumn("z").getBucketCount());
Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType());
Assert.assertTrue(m.getColumn("l").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(511, m.getColumn("l").getBucketCount());
Assert.assertEquals(-1, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
}
}
Aggregations