use of com.questdb.store.JournalEntryWriter 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.JournalEntryWriter 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();
}
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class $TabsRecordSourceTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
try (JournalWriter w = compiler.createWriter(FACTORY_CONTAINER.getFactory(), "create table xyz(x int, y string, timestamp date) timestamp(timestamp) partition by MONTH")) {
JournalEntryWriter ew;
ew = w.entryWriter(DateFormatUtils.parseDateTime("2016-01-02T00:00:00.000Z"));
ew.putInt(0, 0);
ew.append();
ew = w.entryWriter(DateFormatUtils.parseDateTime("2016-02-02T00:00:00.000Z"));
ew.putInt(0, 1);
ew.append();
w.commit();
}
$TabsRecordSource.init();
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class AppendRawPartitioned method main.
public static void main(String[] args) throws JournalException, ParserException {
if (args.length < 1) {
System.out.println("Usage: AppendRawPartitioned <path>");
System.exit(1);
}
final String location = args[0];
// factory can be reused in application and must be explicitly closed when no longer needed.
try (Factory factory = new Factory(location, 1000, 1, 0)) {
// to populate it.
try (JournalWriter writer = factory.writer(new JournalStructure("customers").$int("id").$str("name").$ts("updateDate").partitionBy(PartitionBy.DAY).$())) {
Rnd rnd = new Rnd();
long timestamp = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
// enforce timestamp order
JournalEntryWriter ew = writer.entryWriter(timestamp);
// columns accessed by index
ew.putInt(0, rnd.nextPositiveInt());
ew.putStr(1, rnd.nextChars(25));
// increment timestamp by 30 seconds
timestamp += 30000;
// append record to journal
ew.append();
}
// commit all records at once
// there is no limit on how many records can be in the same transaction
writer.commit();
}
}
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class AppendRawUnordered method main.
public static void main(String[] args) throws JournalException, ParserException {
if (args.length < 1) {
System.out.println("Usage: AppendRawUnordered <path>");
System.exit(1);
}
final String location = args[0];
// factory can be reused in application and must be explicitly closed when no longer needed.
try (Factory factory = new Factory(location, 1000, 1, 0)) {
// to populate it.
try (JournalWriter writer = factory.writer(new JournalStructure("customers").$int("id").$str("name").$ts("updateDate").$())) {
Rnd rnd = new Rnd();
int updateDateIndex = writer.getMetadata().getColumnIndex("updateDate");
long timestamp = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
// timestamp order is enforced by passing value to entryWriter() call
// in this example we don't pass timestamp and ordering is not enforced
JournalEntryWriter ew = writer.entryWriter();
// columns accessed by index
ew.putInt(0, rnd.nextPositiveInt());
ew.putStr(1, rnd.nextChars(25));
// you can use column index we looked up earlier
ew.putDate(updateDateIndex, timestamp);
// increment timestamp by 30 seconds
timestamp += 30000;
// append record to journal
ew.append();
}
// commit all records at once
// there is no limit on how many records can be in the same transaction
writer.commit();
}
}
}
Aggregations