use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class TrickTableReloadTest method testSymbolAddAndReaderReload.
@Test
public void testSymbolAddAndReaderReload() throws SqlException {
compiler.compile("create table x (a int, b int, ts timestamp) partition by DAY", sqlExecutionContext);
engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing").close();
engine.releaseAllWriters();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
compiler.compile("alter table x add column y symbol", sqlExecutionContext);
Assert.assertTrue(reader.reload());
}
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class PartitionDeleteTest method testBCSequence.
@Test
public void testBCSequence() throws SqlException, NumericException {
compiler.compile("create table events (sequence long, event binary, timestamp timestamp) timestamp(timestamp) partition by DAY", sqlExecutionContext);
engine.releaseAllWriters();
try (TableWriter w = new TableWriter(configuration, "events")) {
long ts = TimestampFormatUtils.parseTimestamp("2020-06-30T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow(ts);
r.putLong(0, i);
r.append();
}
ts = TimestampFormatUtils.parseTimestamp("2020-07-01T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow(ts);
r.putLong(0, 100 + i);
r.append();
}
ts = TimestampFormatUtils.parseTimestamp("2020-07-02T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow(ts);
r.putLong(0, 200 + i);
r.append();
}
w.commit();
}
try (TableReader r = new TableReader(configuration, "events")) {
RecordCursor cursor = r.getCursor();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
}
try (TableWriter w = new TableWriter(configuration, "events")) {
long ts = TimestampFormatUtils.parseTimestamp("2020-07-02T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 250 + i);
row.append();
}
w.commit();
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-06-30T00:00:00.000000Z")));
r.reload();
cursor.toTop();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
}
ts = TimestampFormatUtils.parseTimestamp("2020-07-03T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 300 + i);
row.append();
}
w.commit();
ts = TimestampFormatUtils.parseTimestamp("2020-07-04T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 400 + i);
row.append();
}
w.commit();
ts = TimestampFormatUtils.parseTimestamp("2020-07-05T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 500 + i);
row.append();
}
w.commit();
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-07-01T00:00:00.000000Z")));
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-07-02T00:00:00.000000Z")));
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-07-03T00:00:00.000000Z")));
Assert.assertTrue(r.reload());
sink.clear();
cursor.toTop();
printer.print(cursor, r.getMetadata(), true, sink);
String expected = "sequence\tevent\ttimestamp\n" + "400\t\t2020-07-04T00:00:00.000000Z\n" + "401\t\t2020-07-04T00:00:00.000000Z\n" + "402\t\t2020-07-04T00:00:00.000000Z\n" + "403\t\t2020-07-04T00:00:00.000000Z\n" + "404\t\t2020-07-04T00:00:00.000000Z\n" + "405\t\t2020-07-04T00:00:00.000000Z\n" + "406\t\t2020-07-04T00:00:00.000000Z\n" + "407\t\t2020-07-04T00:00:00.000000Z\n" + "408\t\t2020-07-04T00:00:00.000000Z\n" + "409\t\t2020-07-04T00:00:00.000000Z\n" + "500\t\t2020-07-05T00:00:00.000000Z\n" + "501\t\t2020-07-05T00:00:00.000000Z\n" + "502\t\t2020-07-05T00:00:00.000000Z\n" + "503\t\t2020-07-05T00:00:00.000000Z\n" + "504\t\t2020-07-05T00:00:00.000000Z\n" + "505\t\t2020-07-05T00:00:00.000000Z\n" + "506\t\t2020-07-05T00:00:00.000000Z\n" + "507\t\t2020-07-05T00:00:00.000000Z\n" + "508\t\t2020-07-05T00:00:00.000000Z\n" + "509\t\t2020-07-05T00:00:00.000000Z\n";
TestUtils.assertEquals(expected, sink);
}
}
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class RemovePartitionTest method testRemoveSeveralFromTop.
@Test
public void testRemoveSeveralFromTop() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 1000000000l) t from long_sequence(1000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "tst");
TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tst", "testing")) {
// utilise reader fully
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
double superSum = 0;
while (cursor.hasNext()) {
superSum = record.getInt(0) + record.getDouble(1) + record.getTimestamp(1);
}
Assert.assertEquals(4.6023174787925821E18, superSum, 0.00001);
reader.reload();
long timestampToDelete = 0;
for (int i = 0; i < 10; i++) {
writer.removePartition(timestampToDelete + (i * Timestamps.DAY_MICROS));
}
writer.commit();
reader.reload();
cursor.toTop();
String expectedAfterPartitionDelete = "a\tb\tt\n" + "1576838676\t0.08057877795249069\t1970-01-11T00:00:00.000000Z\n" + "-684086147\t0.3806487278648183\t1970-01-11T00:16:40.000000Z\n" + "-689922587\t0.2698247661309793\t1970-01-11T00:33:20.000000Z\n" + "-1918552401\t0.4531424919285716\t1970-01-11T00:50:00.000000Z\n" + "-1004453257\t0.6085797228669808\t1970-01-11T01:06:40.000000Z\n" + "-765083634\t0.4524050162454656\t1970-01-11T01:23:20.000000Z\n" + "316094146\t0.12003762630199555\t1970-01-11T01:40:00.000000Z\n" + "1068342573\t0.7082464127490494\t1970-01-11T01:56:40.000000Z\n" + "-864537248\t0.1040698566401328\t1970-01-11T02:13:20.000000Z\n" + "1543752250\t0.18600146920290805\t1970-01-11T02:30:00.000000Z\n" + "-890802851\t0.22928529042164025\t1970-01-11T02:46:40.000000Z\n" + "1672937587\t0.8520295549109822\t1970-01-11T03:03:20.000000Z\n" + "-98437117\t0.26682634958461626\t1970-01-11T03:20:00.000000Z\n" + "1278648509\t0.4121046775544003\t1970-01-11T03:36:40.000000Z\n" + "868935708\t0.05009031512448925\t1970-01-11T03:53:20.000000Z\n" + "1553180848\t0.7109170062462249\t1970-01-11T04:10:00.000000Z\n" + "1608930002\t0.9886838651440645\t1970-01-11T04:26:40.000000Z\n" + "848077524\t0.29684625166336664\t1970-01-11T04:43:20.000000Z\n" + "-872317779\t0.9455731567461921\t1970-01-11T05:00:00.000000Z\n" + "-2142917800\t0.16525810396139984\t1970-01-11T05:16:40.000000Z\n" + "1060889076\t0.5173940547749024\t1970-01-11T05:33:20.000000Z\n" + "1185624407\t0.7544676970803467\t1970-01-11T05:50:00.000000Z\n" + "-1677723040\t0.13986493405162936\t1970-01-11T06:06:40.000000Z\n" + "852766828\t0.49324528227010966\t1970-01-11T06:23:20.000000Z\n" + "841483165\t0.11070938825827936\t1970-01-11T06:40:00.000000Z\n" + "-1155434911\t0.00978072311811784\t1970-01-11T06:56:40.000000Z\n" + "1362727008\t0.44599963282948984\t1970-01-11T07:13:20.000000Z\n" + "1192991824\t0.3659276421170724\t1970-01-11T07:30:00.000000Z\n" + "1556431414\t0.026301401183052797\t1970-01-11T07:46:40.000000Z\n" + "32338029\t0.08328091072953259\t1970-01-11T08:03:20.000000Z\n" + "-1097218488\t0.06790969300705241\t1970-01-11T08:20:00.000000Z\n" + "-499968873\t0.2615339514777504\t1970-01-11T08:36:40.000000Z\n" + "-1874709376\t0.45771492702062366\t1970-01-11T08:53:20.000000Z\n" + "319944829\t0.20406886183355866\t1970-01-11T09:10:00.000000Z\n" + "772080999\t0.27575788473179963\t1970-01-11T09:26:40.000000Z\n" + "16459753\t0.6409584133875881\t1970-01-11T09:43:20.000000Z\n" + "1290921378\t0.2713721519500688\t1970-01-11T10:00:00.000000Z\n" + "375593536\t0.04336526294979903\t1970-01-11T10:16:40.000000Z\n" + "1952855598\t0.4083056333675016\t1970-01-11T10:33:20.000000Z\n" + "561962643\t0.7736395764837526\t1970-01-11T10:50:00.000000Z\n" + "-1776012188\t0.17405527561965717\t1970-01-11T11:06:40.000000Z\n" + "1399730601\t0.3854235867370095\t1970-01-11T11:23:20.000000Z\n" + "1499465486\t0.37563375709147684\t1970-01-11T11:40:00.000000Z\n" + "850982263\t0.41258159186565424\t1970-01-11T11:56:40.000000Z\n" + "-1211498921\t0.4217546132070882\t1970-01-11T12:13:20.000000Z\n" + "-518985515\t0.23889505021865998\t1970-01-11T12:30:00.000000Z\n" + "1478600023\t0.5340640161021565\t1970-01-11T12:46:40.000000Z\n" + "-757643200\t0.7700469744126617\t1970-01-11T13:03:20.000000Z\n" + "91266345\t0.6601629127014469\t1970-01-11T13:20:00.000000Z\n" + "956610416\t0.9778843606510285\t1970-01-11T13:36:40.000000Z\n" + "-1444192781\t0.06585925388777292\t1970-01-11T13:53:20.000000Z\n" + "701841024\t0.6670228450708864\t1970-01-11T14:10:00.000000Z\n" + "1863548118\t0.4653998788482615\t1970-01-11T14:26:40.000000Z\n" + "1444864868\t0.41265788151170835\t1970-01-11T14:43:20.000000Z\n" + "1797835122\t0.1914161844876806\t1970-01-11T15:00:00.000000Z\n" + "-1812360042\t0.5469257570499296\t1970-01-11T15:16:40.000000Z\n" + "-1982095870\t0.20869523440218085\t1970-01-11T15:33:20.000000Z\n" + "-1040917954\t0.47046214502342254\t1970-01-11T15:50:00.000000Z\n" + "1558850992\t0.5277233818830627\t1970-01-11T16:06:40.000000Z\n" + "-519239966\t0.2263345107996424\t1970-01-11T16:23:20.000000Z\n" + "1700554356\t0.8375723114173276\t1970-01-11T16:40:00.000000Z\n" + "-1734368808\t0.2973413048547613\t1970-01-11T16:56:40.000000Z\n" + "-251197254\t0.02206807161850266\t1970-01-11T17:13:20.000000Z\n" + "1967503676\t0.7708094983496303\t1970-01-11T17:30:00.000000Z\n" + "171793346\t0.7774992993301526\t1970-01-11T17:46:40.000000Z\n" + "1685464327\t0.8711554561766037\t1970-01-11T18:03:20.000000Z\n" + "-702939849\t0.2353405108400326\t1970-01-11T18:20:00.000000Z\n" + "118335726\t0.17485263263815565\t1970-01-11T18:36:40.000000Z\n" + "-1641406479\t0.19882280937094632\t1970-01-11T18:53:20.000000Z\n" + "1637478680\t0.8451212749109064\t1970-01-11T19:10:00.000000Z\n" + "603472290\t0.362912927226985\t1970-01-11T19:26:40.000000Z\n" + "-1987835306\t0.35083644032896444\t1970-01-11T19:43:20.000000Z\n" + "1845426751\t0.4179029808821145\t1970-01-11T20:00:00.000000Z\n" + "-983118321\t0.05905539454236053\t1970-01-11T20:16:40.000000Z\n" + "-931312258\t0.19751729781600535\t1970-01-11T20:33:20.000000Z\n" + "2096767443\t0.35820401665170765\t1970-01-11T20:50:00.000000Z\n" + "-186002027\t0.06499118875100096\t1970-01-11T21:06:40.000000Z\n" + "210529946\t0.8426876468436052\t1970-01-11T21:23:20.000000Z\n" + "316613958\t0.7947985205275171\t1970-01-11T21:40:00.000000Z\n" + "2007373598\t0.2443292452654071\t1970-01-11T21:56:40.000000Z\n" + "-1973328009\t0.09990632318082981\t1970-01-11T22:13:20.000000Z\n" + "-2050693451\t0.8935939683581362\t1970-01-11T22:30:00.000000Z\n" + "-677022047\t0.10811223855547059\t1970-01-11T22:46:40.000000Z\n" + "1194557424\t0.3236005778073523\t1970-01-11T23:03:20.000000Z\n" + "856082190\t0.09028864342090992\t1970-01-11T23:20:00.000000Z\n" + "-1037890340\t0.8731939170484669\t1970-01-11T23:36:40.000000Z\n" + "-273166864\t0.3883845787817346\t1970-01-11T23:53:20.000000Z\n" + "519573739\t0.6914252886783999\t1970-01-12T00:10:00.000000Z\n" + "-1059163764\t0.5807816609951174\t1970-01-12T00:26:40.000000Z\n" + "-1248364069\t0.47180077197626313\t1970-01-12T00:43:20.000000Z\n" + "-707410819\t0.17675145949691562\t1970-01-12T01:00:00.000000Z\n" + "694073645\t0.17231107928084932\t1970-01-12T01:16:40.000000Z\n" + "1143841840\t0.11572097670276393\t1970-01-12T01:33:20.000000Z\n" + "-1203620259\t0.10992274280613101\t1970-01-12T01:50:00.000000Z\n" + "1001513017\t0.494968979129106\t1970-01-12T02:06:40.000000Z\n" + "-1397486016\t0.13260889791591712\t1970-01-12T02:23:20.000000Z\n" + "-124098231\t0.5418085488978492\t1970-01-12T02:40:00.000000Z\n" + "1375230944\t0.36658512235236584\t1970-01-12T02:56:40.000000Z\n" + "-1602836197\t0.9557940492957487\t1970-01-12T03:13:20.000000Z\n" + "-903320803\t0.1570704400490346\t1970-01-12T03:30:00.000000Z\n" + "260033364\t0.034904847183765186\t1970-01-12T03:46:40.000000Z\n" + "-1913086326\t0.5749982450146361\t1970-01-12T04:03:20.000000Z\n" + "373991096\t0.13360028796545642\t1970-01-12T04:20:00.000000Z\n" + "2000510449\t0.5810641448245488\t1970-01-12T04:36:40.000000Z\n" + "-2081389237\t0.3443944218017603\t1970-01-12T04:53:20.000000Z\n" + "-959535924\t0.44725548780773694\t1970-01-12T05:10:00.000000Z\n" + "-1251112810\t0.6933103859471981\t1970-01-12T05:26:40.000000Z\n" + "1732259734\t0.41876634576982885\t1970-01-12T05:43:20.000000Z\n" + "-987366968\t0.7437656766929067\t1970-01-12T06:00:00.000000Z\n" + "556907040\t0.32010882429399834\t1970-01-12T06:16:40.000000Z\n" + "1569770272\t0.4288965848487438\t1970-01-12T06:33:20.000000Z\n" + "1405080657\t0.18027951967123457\t1970-01-12T06:50:00.000000Z\n" + "526853349\t0.6178183982086626\t1970-01-12T07:06:40.000000Z\n" + "-334179339\t0.8261516071359104\t1970-01-12T07:23:20.000000Z\n" + "-17513564\t0.36138284225880035\t1970-01-12T07:40:00.000000Z\n" + "354098377\t0.6953541428262865\t1970-01-12T07:56:40.000000Z\n" + "1443031361\t0.31908901955539515\t1970-01-12T08:13:20.000000Z\n" + "1175675185\t0.05899019706036246\t1970-01-12T08:30:00.000000Z\n" + "99560093\t0.16347836851309816\t1970-01-12T08:46:40.000000Z\n" + "-1674594591\t0.1407735833402206\t1970-01-12T09:03:20.000000Z\n" + "-1124656535\t0.1528299057907735\t1970-01-12T09:20:00.000000Z\n" + "-1507142148\t0.00825969166045648\t1970-01-12T09:36:40.000000Z\n" + "2049048212\t0.29309813796291284\t1970-01-12T09:53:20.000000Z\n" + "352894170\t0.5832447623746595\t1970-01-12T10:10:00.000000Z\n" + "1513826357\t0.5063850654335724\t1970-01-12T10:26:40.000000Z\n" + "1638798442\t0.28053790406505974\t1970-01-12T10:43:20.000000Z\n" + "-501102817\t0.5524335828965579\t1970-01-12T11:00:00.000000Z\n" + "-2110403420\t0.8114444771798898\t1970-01-12T11:16:40.000000Z\n" + "-1041070703\t0.6810629367436306\t1970-01-12T11:33:20.000000Z\n" + "1774933838\t0.8545511357260956\t1970-01-12T11:50:00.000000Z\n" + "-1189092035\t0.5009939966556752\t1970-01-12T12:06:40.000000Z\n" + "1108319297\t0.4007457065265131\t1970-01-12T12:23:20.000000Z\n" + "1674123731\t0.2679292897042268\t1970-01-12T12:40:00.000000Z\n" + "782820973\t0.9391935526421991\t1970-01-12T12:56:40.000000Z\n" + "413500238\t0.19676893721907063\t1970-01-12T13:13:20.000000Z\n" + "-227038447\t0.4799415921194079\t1970-01-12T13:30:00.000000Z\n";
TestUtils.assertReader(expectedAfterPartitionDelete, reader, sink);
}
});
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class AlterTableAlterSymbolColumnCacheFlagTest method testAlterSymbolCacheFlagToTrueCheckOpenReaderWithCursor.
@Test
public void testAlterSymbolCacheFlagToTrueCheckOpenReaderWithCursor() throws Exception {
final RecordCursorPrinter printer = new SingleColumnRecordCursorPrinter(1);
assertMemoryLeak(() -> {
compiler.compile("create table x (i int, sym symbol nocache) ;", sqlExecutionContext);
executeInsert("insert into x values (1, 'GBP')\"");
executeInsert("insert into x values (2, 'CHF')\"");
executeInsert("insert into x values (3, 'GBP')\"");
executeInsert("insert into x values (4, 'JPY')\"");
executeInsert("insert into x values (5, 'USD')\"");
executeInsert("insert into x values (6, 'GBP')\"");
executeInsert("insert into x values (7, 'GBP')\"");
executeInsert("insert into x values (8, 'GBP')\"");
executeInsert("insert into x values (9, 'GBP')\"");
});
String expectedOrdered = "sym\n" + "CHF\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n" + "JPY\n" + "USD\n";
String expectedChronological = "sym\n" + "GBP\n" + "CHF\n" + "GBP\n" + "JPY\n" + "USD\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n";
assertMemoryLeak(() -> {
assertQueryPlain(expectedOrdered, "select sym from x order by sym");
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
// check cursor before altering symbol column
sink.clear();
printer.print(reader.getCursor(), reader.getMetadata(), true, sink);
Assert.assertEquals(expectedChronological, sink.toString());
try (TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
writer.changeCacheFlag(1, true);
}
// reload reader
Assert.assertTrue(reader.reload());
// check cursor after reload
sink.clear();
printer.print(reader.getCursor(), reader.getMetadata(), true, sink);
Assert.assertEquals(expectedChronological, sink.toString());
try (TableReader reader2 = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
sink.clear();
printer.print(reader2.getCursor(), reader2.getMetadata(), true, sink);
Assert.assertEquals(expectedChronological, sink.toString());
}
}
});
assertQueryPlain(expectedOrdered, "select sym from x order by 1 asc");
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class AlterTableDropColumnTest method testDropTwoColumns.
@Test
public void testDropTwoColumns() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try {
createX();
Assert.assertEquals(ALTER, compiler.compile("alter table x drop column e, m", sqlExecutionContext).getType());
String expected = "{\"columnCount\":14,\"columns\":[{\"index\":0,\"name\":\"i\",\"type\":\"INT\"},{\"index\":1,\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"index\":2,\"name\":\"amt\",\"type\":\"DOUBLE\"},{\"index\":3,\"name\":\"timestamp\",\"type\":\"TIMESTAMP\"},{\"index\":4,\"name\":\"b\",\"type\":\"BOOLEAN\"},{\"index\":5,\"name\":\"c\",\"type\":\"STRING\"},{\"index\":6,\"name\":\"d\",\"type\":\"DOUBLE\"},{\"index\":7,\"name\":\"f\",\"type\":\"SHORT\"},{\"index\":8,\"name\":\"g\",\"type\":\"DATE\"},{\"index\":9,\"name\":\"ik\",\"type\":\"SYMBOL\"},{\"index\":10,\"name\":\"j\",\"type\":\"LONG\"},{\"index\":11,\"name\":\"k\",\"type\":\"TIMESTAMP\"},{\"index\":12,\"name\":\"l\",\"type\":\"BYTE\"},{\"index\":13,\"name\":\"n\",\"type\":\"STRING\"}],\"timestampIndex\":3}";
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_VERSION, TableUtils.ANY_TABLE_VERSION)) {
sink.clear();
reader.getMetadata().toJson(sink);
TestUtils.assertEquals(expected, sink);
}
Assert.assertEquals(0, engine.getBusyWriterCount());
Assert.assertEquals(0, engine.getBusyReaderCount());
} finally {
engine.clear();
}
});
}
Aggregations