use of com.questdb.store.factory.Factory in project questdb by bluestreak01.
the class AppendObjectTimeSeries method main.
/**
* Appends 1 million quotes to journal. Timestamp values are in chronological order.
*/
public static void main(String[] args) throws JournalException {
if (args.length != 1) {
System.out.println("Usage: " + AppendObjectTimeSeries.class.getName() + " <path>");
System.exit(1);
}
String journalLocation = args[0];
JournalConfiguration configuration = new JournalConfigurationBuilder() {
{
$(Quote.class, "quote").$ts();
}
}.build(journalLocation);
try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
// delete existing quote journal
Files.delete(new File(configuration.getJournalBase(), "quote"));
try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
final int count = 1000000;
final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
final Random r = new Random(System.currentTimeMillis());
// reuse same same instance of Quote class to keep GC under control
final Quote q = new Quote();
long t = System.nanoTime();
for (int i = 0; i < count; i++) {
// prepare object for new set of data
q.clear();
// generate some data
q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
q.setAsk(Math.abs(r.nextDouble()));
q.setBid(Math.abs(r.nextDouble()));
q.setAskSize(Math.abs(r.nextInt() % 10000));
q.setBidSize(Math.abs(r.nextInt() % 10000));
q.setEx("LXE");
q.setMode("Fast trading");
q.setTimestamp(System.currentTimeMillis());
writer.append(q);
}
// commit is necessary
writer.commit();
System.out.println("Journal size: " + writer.size());
System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
}
}
}
use of com.questdb.store.factory.Factory in project questdb by bluestreak01.
the class AppendObjectUnordered method main.
/**
* Appends 1 million quotes with random timestamp values. Journal doesn't enforce order.
*/
public static void main(String[] args) throws JournalException {
if (args.length != 1) {
System.out.println("Usage: " + AppendObjectTimeSeries.class.getName() + " <path>");
System.exit(1);
}
String journalLocation = args[0];
try (Factory factory = new Factory(journalLocation, 1000, 1, 0)) {
// delete existing quote journal
Files.delete(new File(factory.getConfiguration().getJournalBase(), "quote-unordered"));
try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
final int count = 1000000;
final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
final Random r = new Random(System.currentTimeMillis());
// reuse same same instance of Quote class to keep GC under control
final Quote q = new Quote();
long t = System.nanoTime();
for (int i = 0; i < count; i++) {
// prepare object for new set of data
q.clear();
// generate some data
q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
q.setAsk(Math.abs(r.nextDouble()));
q.setBid(Math.abs(r.nextDouble()));
q.setAskSize(Math.abs(r.nextInt() % 10000));
q.setBidSize(Math.abs(r.nextInt() % 10000));
q.setEx("LXE");
q.setMode("Fast trading");
q.setTimestamp(r.nextLong());
//
writer.append(q);
}
// commit is necessary
writer.commit();
System.out.println("Journal size: " + writer.size());
System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
}
}
}
use of com.questdb.store.factory.Factory 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.factory.Factory 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.factory.Factory in project questdb by bluestreak01.
the class SQLErrorHandling method main.
public static void main(String[] args) throws JournalException, ParserException, IOException {
if (args.length < 1) {
System.out.println("Usage: SQLErrorHandling <path>");
System.exit(1);
}
try (Factory factory = new Factory(args[0], 1000, 1, 0)) {
// import movies data to query
ImportManager.importFile(factory, SQLErrorHandling.class.getResource("/movies.csv").getFile(), ',', null, false);
// Create SQL engine instance.
QueryCompiler compiler = new QueryCompiler();
try {
// in case of exception all allocated resources are freed automatically
compiler.compile(factory, "'movies.csv' where movieIds = :id");
} catch (ParserException e) {
LOG.error().$("At (").$(QueryError.getPosition()).$(") : ").$(QueryError.getMessage()).$();
}
}
}
Aggregations