use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class HttpServerTest method testImportIntoBusyJournal2.
@Test
public void testImportIntoBusyJournal2() throws Exception {
WriterFactory f = getFactory();
try (JournalWriter w = f.writer(new JournalStructure("small.csv").$int("X").$int("Y").$())) {
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, 3);
ew.putInt(1, 30);
ew.append();
w.commit();
BootstrapEnv env = new BootstrapEnv();
env.configuration = new ServerConfiguration();
env.factory = getFactory();
env.typeProbeCollection = TYPE_PROBE_COLLECTION;
env.matcher = new SimpleUrlMatcher() {
{
put("/imp", new ImportHandler(env));
}
};
HttpServer server = new HttpServer(env);
server.start();
StringBuilder response = new StringBuilder();
try {
Assert.assertEquals(200, HttpTestUtils.upload("/csv/small.csv", "http://localhost:9000/imp?fmt=json", null, response));
Assert.assertTrue(Chars.startsWith(response, "{\"status\":\"com.questdb.ex.WriterBusyException\"}"));
} catch (IOException e) {
Assert.assertTrue(e.getMessage().contains("Connection reset"));
} finally {
server.halt();
}
}
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class QueryHandlerTest method generateJournal.
private static void generateJournal(String name, QueryResponse.Tab[] recs, int count) throws JournalException, NumericException {
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure(name).$sym("id").$double("x").$double("y").$long("z").$int("w").$ts())) {
Rnd rnd = new Rnd();
long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
for (int i = 0; i < count; i++) {
JournalEntryWriter ew = w.entryWriter();
ew.putSym(0, recs.length > i ? recs[i].id : "id" + i);
ew.putDouble(1, recs.length > i ? recs[i].x : rnd.nextDouble());
if (recs.length > i) {
ew.putDouble(2, recs[i].y);
ew.putLong(3, recs[i].z);
} else {
if (rnd.nextPositiveInt() % 10 == 0) {
ew.putNull(2);
} else {
ew.putDouble(2, rnd.nextDouble());
}
if (rnd.nextPositiveInt() % 10 == 0) {
ew.putNull(3);
} else {
ew.putLong(3, rnd.nextLong() % 500);
}
}
ew.putInt(4, recs.length > i ? recs[i].w : rnd.nextInt() % 500);
ew.putDate(5, recs.length > i ? recs[i].timestamp.getTime() : t);
t += 10;
ew.append();
}
w.commit();
}
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class AggregationTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
int recordCount = 10000;
int employeeCount = 10;
try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").$int("productId").$str("employeeId").$ts("orderDate").$int("quantity").$double("price").$float("rate").recordCountHint(recordCount).$())) {
Rnd rnd = new Rnd();
String[] employees = new String[employeeCount];
for (int i = 0; i < employees.length; i++) {
employees[i] = rnd.nextString(9);
}
long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
int tsIncrement = 10000;
int orderId = 0;
for (int i = 0; i < recordCount; i++) {
JournalEntryWriter w = orders.entryWriter();
w.putInt(0, ++orderId);
w.putInt(1, rnd.nextPositiveInt() % 500);
w.putInt(2, rnd.nextPositiveInt() % 200);
w.putStr(3, employees[rnd.nextPositiveInt() % employeeCount]);
w.putDate(4, timestamp += tsIncrement);
w.putInt(5, rnd.nextPositiveInt());
w.putDouble(6, rnd.nextDouble());
w.putFloat(7, rnd.nextFloat());
w.append();
}
orders.commit();
}
try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("stars").$int("galaxy").$int("star").$double("diameter").$())) {
Rnd rnd = new Rnd();
long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
int tsIncrement = 10000;
for (int i = 0; i < recordCount; i++) {
JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement);
w.putInt(0, rnd.nextPositiveInt() % 10);
w.putInt(1, rnd.nextPositiveInt());
int dividend = (rnd.nextPositiveInt() % 10);
w.putDouble(2, Double.MAX_VALUE / (double) (dividend == 0 ? 1 : dividend));
w.append();
}
stars.commit();
}
try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("stars2").$int("galaxy").$int("star").$double("diameter").$())) {
Rnd rnd = new Rnd();
double r = Math.sqrt(Double.MAX_VALUE);
long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
int tsIncrement = 10000;
for (int i = 0; i < recordCount; i++) {
JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement);
w.putInt(0, rnd.nextPositiveInt() % 10);
w.putInt(1, rnd.nextPositiveInt());
int dividend = (rnd.nextPositiveInt() % 10);
w.putDouble(2, r / (double) (dividend == 0 ? 1 : dividend));
w.append();
}
stars.commit();
}
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class NullAggregationTest method createTabWithNaNs2.
private static void createTabWithNaNs2() throws JournalException, NumericException {
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("tab").$str("id").$double("x").$double("y").$long("z").$int("w").$str("a").$ts())) {
Rnd rnd = new Rnd();
int n = 128;
ObjHashSet<String> names = getNames(rnd, n);
int mask = n - 1;
long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
for (int i = 0; i < 10000; i++) {
JournalEntryWriter ew = w.entryWriter();
ew.putStr(0, names.get(rnd.nextInt() & mask));
ew.putDouble(1, rnd.nextDouble());
if (rnd.nextPositiveInt() % 10 == 0) {
ew.putNull(2);
} else {
ew.putDouble(2, rnd.nextDouble());
}
if (rnd.nextPositiveInt() % 10 == 0) {
ew.putNull(3);
} else {
ew.putLong(3, rnd.nextLong() % 500);
}
if (rnd.nextPositiveInt() % 10 == 0) {
ew.putNull(4);
} else {
ew.putInt(4, rnd.nextInt() % 500);
}
if (rnd.nextPositiveInt() % 10 == 0) {
ew.putNull(5);
} else {
ew.putStr(5, names.get(rnd.nextInt() & mask));
}
ew.putDate(6, t += (60 * 60 * 1000));
ew.append();
}
w.commit();
}
}
use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class NullCountingTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
int recordCount = 10000;
int productCount = 200;
int employeeCount = 10;
try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").$str("productId").$sym("employeeId").$ts("orderDate").$int("quantity").$double("price").$float("rate").$long("x").recordCountHint(recordCount).$())) {
Rnd rnd = new Rnd();
String[] employees = new String[employeeCount];
for (int i = 0; i < employees.length; i++) {
if (rnd.nextPositiveInt() % 10 == 0) {
employees[i] = null;
} else {
employees[i] = rnd.nextString(9);
}
}
String[] productId = new String[productCount];
for (int i = 0; i < productId.length; i++) {
if (rnd.nextPositiveInt() % 30 == 0) {
productId[i] = null;
} else {
productId[i] = rnd.nextString(9);
}
}
long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
int tsIncrement = 10000;
int orderId = 0;
for (int i = 0; i < recordCount; i++) {
JournalEntryWriter w = orders.entryWriter();
w.putInt(0, ++orderId);
w.putInt(1, rnd.nextPositiveInt() % 500);
w.putStr(2, productId[rnd.nextPositiveInt() % productCount]);
w.putSym(3, employees[rnd.nextPositiveInt() % employeeCount]);
w.putDate(4, timestamp += tsIncrement);
w.putInt(5, rnd.nextPositiveInt() % 10 == 0 ? Numbers.INT_NaN : rnd.nextPositiveInt());
w.putDouble(6, rnd.nextPositiveInt() % 10 == 0 ? Double.NaN : rnd.nextDouble());
w.putFloat(7, rnd.nextPositiveInt() % 10 == 0 ? Float.NaN : rnd.nextFloat());
w.putLong(8, rnd.nextPositiveInt() % 10 == 0 ? Numbers.LONG_NaN : rnd.nextLong());
w.append();
}
orders.commit();
}
}
Aggregations