use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class SymbolNullQueryTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
int tradeCount = 100;
int quoteCount = 300;
JournalWriter trades = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("trades").$int("quoteId").$sym("tag1").$double("amount").recordCountHint(tradeCount).$ts());
JournalWriter quotes = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("quotes").$int("quoteId").$sym("tag").$double("rate").recordCountHint(quoteCount).$ts());
int tsIncrementMax = 10000;
long timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
Rnd rnd = new Rnd();
ObjList<String> tags = new ObjList<>();
for (int i = 0; i < 500; i++) {
tags.add(rnd.nextBoolean() ? rnd.nextString(rnd.nextInt() & 15) : null);
}
for (int i = 0; i < quoteCount; i++) {
JournalEntryWriter w = quotes.entryWriter();
w.putInt(0, i);
w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
w.putDouble(2, rnd.nextDouble());
w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
w.append();
}
quotes.commit();
timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
for (int i = 0; i < tradeCount; i++) {
JournalEntryWriter w = trades.entryWriter();
w.putInt(0, rnd.nextPositiveInt() % quoteCount);
w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
w.putDouble(2, rnd.nextDouble());
w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
w.append();
}
quotes.close();
trades.close();
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class GenericInteropTest method testInvalidColumnName.
@Test
public void testInvalidColumnName() throws Exception {
File location = null;
try (JournalWriter w = getFactory().writer(new JournalStructure("test") {
{
$int("id").index();
$str("status?\0x");
}
})) {
location = w.getLocation();
w.entryWriter();
} catch (JournalException ignore) {
// ignore
}
Assert.assertNotNull(location);
Files.deleteOrException(location);
try (JournalWriter w = getFactory().writer(new JournalStructure("test") {
{
$int("id").index();
$str("status");
}
})) {
w.entryWriter();
}
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class GenericInteropTest method testGenericStructureMismatch.
@Test
public void testGenericStructureMismatch() throws Exception {
try (JournalWriter writer = makeGenericWriter()) {
JournalEntryWriter w = writer.entryWriter();
w.putSym(0, "EURUSD");
w.putDate(1, 19999);
w.putDouble(2, 1.24);
w.putDouble(3, 1.25);
w.putInt(4, 10000);
w.putInt(5, 12000);
w.putInt(6, 1);
w.putStr(7, "OK");
w.putStr(8, "system");
w.putStr(9, "EURUSD:GLOBAL");
w.putBool(10, true);
w.putNull(11);
w.putLong(12, 13141516);
w.putShort(13, (short) 25000);
w.append();
writer.commit();
writer.close();
}
try {
getFactory().writer(new JournalStructure("test") {
{
$str("sym");
$date("created");
}
});
Assert.fail("Expected exception");
} catch (JournalMetadataException ignore) {
// expected
}
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class ComparatorCompilerTest method testAllGetters.
@Test
public void testAllGetters() throws Exception {
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$bool("bool").$byte("byte").$double("double").$float("float").$int("int").$long("long").$date("date").$short("short").$str("str").$sym("sym").$())) {
JournalEntryWriter ew = w.entryWriter();
ew.putBool(0, true);
ew.put(1, (byte) 13);
ew.putDouble(2, 20.12);
ew.putFloat(3, 10.15f);
ew.putInt(4, 4);
ew.putLong(5, 9988908080988890L);
ew.putDate(6, 88979879L);
ew.putShort(7, (short) 902);
ew.putStr(8, "complexity made simple");
ew.putSym(9, "questdb");
ew.append();
ew = w.entryWriter();
ew.put(1, (byte) 13);
ew.putDouble(2, 20.12);
ew.putFloat(3, 10.15f);
ew.putInt(4, 4);
ew.putLong(5, 9988908080988890L);
ew.putDate(6, 88979879L);
ew.putShort(7, (short) 902);
ew.putStr(8, "complexity made simple");
ew.putSym(9, "appsicle");
ew.append();
w.commit();
IntList indices = new IntList();
for (int i = 0, n = w.getMetadata().getColumnCount(); i < n; i++) {
indices.add(i + 1);
}
RecordSource rs = compileSource("xyz");
RecordComparator rc = cc.compile(rs.getMetadata(), indices);
RBTreeSortedRecordSource map = new RBTreeSortedRecordSource(rs, rc, 1024 * 1024, 4 * 1024 * 1024);
sink.clear();
printer.print(map, FACTORY_CONTAINER.getFactory());
}
TestUtils.assertEquals("false\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tappsicle\n" + "true\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tquestdb\n", sink);
}
use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.
the class RBTreeSortedRecordSourceTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$int("i").$str("str").$())) {
int n = 100;
Rnd rnd = new Rnd();
for (int i = 0; i < n; i++) {
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, rnd.nextInt());
ew.putStr(1, rnd.nextChars(2));
ew.append();
}
w.commit();
}
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("dupes").$int("x").$())) {
for (int i = 0; i < 10; i++) {
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, i % 2 == 0 ? 10 : 20);
ew.append();
}
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, 30);
ew.append();
w.commit();
}
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("timeseries").$double("d").$ts().$())) {
Rnd rnd = new Rnd();
long ts = Dates.toMillis(2016, 3, 12, 0, 0);
for (int i = 0; i < 1000; i++) {
JournalEntryWriter ew = w.entryWriter();
ew.putDouble(0, rnd.nextDouble());
ew.putDate(1, ts + (rnd.nextPositiveInt() % Dates.DAY_MILLIS));
ew.append();
}
w.commit();
}
}
Aggregations