use of com.questdb.store.JournalWriter 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.JournalWriter 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();
}
}
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class Generator method createCustomers.
public static void createCustomers(WriterFactory factory) throws JournalException {
// 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