use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class DDLTests method testCreateAsSelectPartitionedMixedCase.
@Test
public void testCreateAsSelectPartitionedMixedCase() throws Exception {
exec("create table y (a INT, b byte, c Short, d long, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100");
try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t) partition by MONTH record hint 100")) {
JournalMetadata m = w.getMetadata();
Assert.assertEquals(11, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType());
Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType());
Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType());
Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType());
Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertEquals(8, 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 testCreateIndexWithSuffixDefaultPartition.
@Test
public void testCreateIndexWithSuffixDefaultPartition() throws Exception {
exec("create table x (a INT, b BYTE, t DATE, x SYMBOL), index(a buckets 25), index(x) timestamp(t) 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(31, 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.assertTrue(m.getColumn("x").isIndexed());
Assert.assertEquals(2, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
}
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class TableUtilsTest method testCreateFailure.
@Test
public void testCreateFailure() throws Exception {
TestUtils.assertMemoryLeak(() -> {
class X extends FilesFacadeImpl {
@Override
public int mkdirs(LPSZ path, int mode) {
return -1;
}
}
X ff = new X();
JournalMetadata metadata = getJournalStructure().build();
try (AppendMemory appendMemory = new AppendMemory()) {
try (Path path = new Path()) {
TableUtils.create(ff, path, appendMemory, temp.getRoot().getAbsolutePath(), metadata, 509);
Assert.fail();
} catch (CairoException e) {
Assert.assertNotNull(e.getMessage());
}
}
});
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class CachingReaderFactoryTest method testConcurrentOpenAndClose.
@Test
public void testConcurrentOpenAndClose() throws Exception {
final int readerCount = 5;
int threadCount = 2;
final int iterations = 1000;
// create journals to read
final JournalMetadata<?>[] meta = new JournalMetadata[readerCount];
for (int i = 0; i < readerCount; i++) {
final JournalMetadata<?> m = new JournalStructure("x" + i).$date("ts").$().build();
((WriterFactory) getFactory()).writer(m).close();
meta[i] = m;
}
try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
final CyclicBarrier barrier = new CyclicBarrier(threadCount);
final CountDownLatch halt = new CountDownLatch(threadCount);
final AtomicInteger errors = new AtomicInteger();
for (int i = 0; i < threadCount; i++) {
final int x = i;
new Thread(() -> {
Rnd rnd = new Rnd(x, -x);
try {
barrier.await();
for (int i1 = 0; i1 < iterations; i1++) {
JournalMetadata<?> m = meta[rnd.nextPositiveInt() % readerCount];
try (Journal ignored = rf.reader(m)) {
LockSupport.parkNanos(100);
}
}
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
} finally {
halt.countDown();
}
}).start();
}
halt.await();
Assert.assertEquals(0, errors.get());
}
}
use of com.questdb.store.factory.configuration.JournalMetadata in project questdb by bluestreak01.
the class PlainTextLexerTest method testImportSchema.
@Test
public void testImportSchema() throws Exception {
String file = this.getClass().getResource("/csv/test-import.csv").getFile();
String schema = "[{\"name\":\"IntSym\", \"type\":\"SYMBOL\"}, {\"name\":\"Fmt2Date\", \"type\":\"STRING\"}]";
ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, schema, false);
String location = "test-import.csv";
Assert.assertEquals(JournalConfiguration.EXISTS, getFactory().getConfiguration().exists(location));
try (Journal r = getFactory().reader(location)) {
JournalMetadata m = r.getMetadata();
Assert.assertEquals(ColumnType.SYMBOL, m.getColumnQuick(1).type);
Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(6).type);
}
}
Aggregations