use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class DistinctSymbolRecordCursorFactory method getCursor.
@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) {
TableReader reader = engine.getReader(executionContext.getCairoSecurityContext(), tableName, tableId, tableVersion);
cursor.of(reader, columnIndex);
return cursor;
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class TableRepairTest method testDeletePartitionInTheMiddle.
@Test
public void testDeletePartitionInTheMiddle() throws Exception {
// this delete partition actually deletes files, simulating manual intervention
assertMemoryLeak(() -> {
compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 10000000l) t from long_sequence(100000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
engine.releaseAllWriters();
try (TableReader reader = new TableReader(configuration, "tst")) {
Assert.assertEquals(100000, reader.size());
try (Path path = new Path()) {
path.of(configuration.getRoot()).concat("tst").concat("1970-01-09").$();
Assert.assertEquals(0, Files.rmdir(path));
}
Assert.assertEquals(100000, reader.size());
// repair by opening and closing writer
new TableWriter(configuration, "tst").close();
Assert.assertTrue(reader.reload());
Assert.assertEquals(91360, reader.size());
}
});
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class TableRepairTest method testDeleteActivePartition.
@Test
public void testDeleteActivePartition() throws Exception {
// this delete partition actually deletes files, simulating manual intervention
assertMemoryLeak(() -> {
compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 10000000l) t from long_sequence(100000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
engine.releaseAllWriters();
try (TableReader reader = new TableReader(configuration, "tst")) {
Assert.assertEquals(100000, reader.size());
// last and "active" partition is "1970-01-12"
try (Path path = new Path()) {
path.of(configuration.getRoot()).concat("tst").concat("1970-01-12").$();
Assert.assertEquals(0, Files.rmdir(path));
}
Assert.assertEquals(100000, reader.size());
try (TableWriter w = new TableWriter(configuration, "tst")) {
Assert.assertTrue(reader.reload());
Assert.assertEquals(95040, reader.size());
Assert.assertEquals(950390000000L, w.getMaxTimestamp());
TableWriter.Row row = w.newRow(w.getMaxTimestamp());
row.putInt(0, 150);
row.putDouble(1, 0.67);
row.append();
w.commit();
}
Assert.assertTrue(reader.reload());
Assert.assertEquals(95041, reader.size());
}
});
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class FilterOnExcludedValuesRecordCursorFactory method getCursorInstance.
@Override
protected RecordCursor getCursorInstance(DataFrameCursor dataFrameCursor, SqlExecutionContext executionContext) throws SqlException {
try (TableReader reader = dataFrameCursor.getTableReader()) {
if (reader.getSymbolMapReader(columnIndex).size() > maxSymbolNotEqualsCount) {
throw ReaderOutOfDateException.of(reader.getTableName());
}
Function.init(keyExcludedValueFunctions, reader, executionContext);
}
this.recalculateIncludedValues(dataFrameCursor.getTableReader());
this.cursor.of(dataFrameCursor, executionContext);
if (filter != null) {
filter.init(this.cursor, executionContext);
}
return this.cursor;
}
use of io.questdb.cairo.TableReader in project questdb by bluestreak01.
the class AlterTableRenameColumnTest method testRenameColumnAndCheckOpenReaderWithCursor.
@Test
public void testRenameColumnAndCheckOpenReaderWithCursor() throws Exception {
String expectedBefore = "i\tsym\tamt\ttimestamp\tb\tc\td\te\tf\tg\tik\tj\tk\tl\tm\tn\n" + "1\tmsft\t50.938\t2018-01-01T00:12:00.000000Z\tfalse\tXYZ\t0.4621835429127854\t0.5599\t31\t2015-06-22T18:58:53.562Z\tPEHN\t-4485747798769957016\t1970-01-01T00:00:00.000000Z\t19\t00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\tYSBEOUOJSHRUEDRQ\n" + "2\tgoogl\t42.281\t2018-01-01T00:24:00.000000Z\tfalse\tABC\t0.4138164748227684\t0.5522\t493\t2015-04-09T11:42:28.332Z\tHYRX\t-8811278461560712840\t1970-01-01T00:16:40.000000Z\t29\t00000000 53 d0 fb 64 bb 1a d4 f0 2d 40 e2 4b b1 3e e3 f1\t\n" + "3\tgoogl\t17.371\t2018-01-01T00:36:00.000000Z\tfalse\tABC\t0.05384400312338511\t0.0975\t327\t2015-09-26T18:05:10.217Z\tHYRX\t-3214230645884399728\t1970-01-01T00:33:20.000000Z\t28\t00000000 8e e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28\tSUWDSWUGS\n" + "4\tibm\t44.805\t2018-01-01T00:48:00.000000Z\ttrue\tXYZ\t0.14830552335848957\t0.9442\t95\t2015-01-04T19:58:55.654Z\tPEHN\t-5024542231726589509\t1970-01-01T00:50:00.000000Z\t39\t00000000 49 1c f2 3c ed 39 ac a8 3b a6\tOJIPHZEPIHVL\n" + "5\tgoogl\t42.956\t2018-01-01T01:00:00.000000Z\ttrue\t\t0.22895725920713628\t0.9821\t696\t2015-03-18T09:57:14.898Z\tCPSW\t-8757007522346766135\t1970-01-01T01:06:40.000000Z\t23\t\t\n" + "6\tibm\t82.59700000000001\t2018-01-01T01:12:00.000000Z\ttrue\tCDE\t0.021189232728939578\tNaN\t369\t2015-07-21T10:33:47.953Z\tPEHN\t-9147563299122452591\t1970-01-01T01:23:20.000000Z\t48\t00000000 18 93 bd 0b 61 f5 5d d0 eb 67 44 a7 6a\t\n" + "7\tgoogl\t98.59100000000001\t2018-01-01T01:24:00.000000Z\ttrue\tCDE\t0.24642266252221556\t0.2672\t174\t2015-02-20T01:11:53.748Z\t\t2151565237758036093\t1970-01-01T01:40:00.000000Z\t31\t\tHZSQLDGLOGIFO\n" + "8\tgoogl\t57.086\t2018-01-01T01:36:00.000000Z\ttrue\tABC\t0.6707018622395736\t0.0759\t199\t2015-09-12T07:21:40.050Z\t\t-4058426794463997577\t1970-01-01T01:56:40.000000Z\t37\t00000000 ea 4e ea 8b f5 0f 2d b3 14 33\tFFLRBROMNXKUIZ\n" + "9\tgoogl\t81.44200000000001\t2018-01-01T01:48:00.000000Z\tfalse\t\t0.2677326840703891\t0.5425\t1001\t2015-11-14T07:05:22.934Z\tHYRX\t-8793423647053878901\t1970-01-01T02:13:20.000000Z\t33\t00000000 25 c2 20 ff 70 3a c7 8a b3 14 cd 47 0b 0c\tFMQNTOG\n" + "10\tmsft\t3.973\t2018-01-01T02:00:00.000000Z\tfalse\tXYZ\tNaN\tNaN\t828\t2015-06-18T18:07:42.406Z\tPEHN\t-7398902448022205322\t1970-01-01T02:30:00.000000Z\t50\t00000000 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57 ff\n" + "00000010 9a ef 88 cb\tCNGTNLEGPUHH\n";
String expectedAfter = "i\tsym\tamt\ttimestamp\tbb\tcc\td\te\tf\tg\tik\tj\tk\tl\tm\tn\n" + "1\tmsft\t50.938\t2018-01-01T00:12:00.000000Z\tfalse\tXYZ\t0.4621835429127854\t0.5599\t31\t2015-06-22T18:58:53.562Z\tPEHN\t-4485747798769957016\t1970-01-01T00:00:00.000000Z\t19\t00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\tYSBEOUOJSHRUEDRQ\n" + "2\tgoogl\t42.281\t2018-01-01T00:24:00.000000Z\tfalse\tABC\t0.4138164748227684\t0.5522\t493\t2015-04-09T11:42:28.332Z\tHYRX\t-8811278461560712840\t1970-01-01T00:16:40.000000Z\t29\t00000000 53 d0 fb 64 bb 1a d4 f0 2d 40 e2 4b b1 3e e3 f1\t\n" + "3\tgoogl\t17.371\t2018-01-01T00:36:00.000000Z\tfalse\tABC\t0.05384400312338511\t0.0975\t327\t2015-09-26T18:05:10.217Z\tHYRX\t-3214230645884399728\t1970-01-01T00:33:20.000000Z\t28\t00000000 8e e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28\tSUWDSWUGS\n" + "4\tibm\t44.805\t2018-01-01T00:48:00.000000Z\ttrue\tXYZ\t0.14830552335848957\t0.9442\t95\t2015-01-04T19:58:55.654Z\tPEHN\t-5024542231726589509\t1970-01-01T00:50:00.000000Z\t39\t00000000 49 1c f2 3c ed 39 ac a8 3b a6\tOJIPHZEPIHVL\n" + "5\tgoogl\t42.956\t2018-01-01T01:00:00.000000Z\ttrue\t\t0.22895725920713628\t0.9821\t696\t2015-03-18T09:57:14.898Z\tCPSW\t-8757007522346766135\t1970-01-01T01:06:40.000000Z\t23\t\t\n" + "6\tibm\t82.59700000000001\t2018-01-01T01:12:00.000000Z\ttrue\tCDE\t0.021189232728939578\tNaN\t369\t2015-07-21T10:33:47.953Z\tPEHN\t-9147563299122452591\t1970-01-01T01:23:20.000000Z\t48\t00000000 18 93 bd 0b 61 f5 5d d0 eb 67 44 a7 6a\t\n" + "7\tgoogl\t98.59100000000001\t2018-01-01T01:24:00.000000Z\ttrue\tCDE\t0.24642266252221556\t0.2672\t174\t2015-02-20T01:11:53.748Z\t\t2151565237758036093\t1970-01-01T01:40:00.000000Z\t31\t\tHZSQLDGLOGIFO\n" + "8\tgoogl\t57.086\t2018-01-01T01:36:00.000000Z\ttrue\tABC\t0.6707018622395736\t0.0759\t199\t2015-09-12T07:21:40.050Z\t\t-4058426794463997577\t1970-01-01T01:56:40.000000Z\t37\t00000000 ea 4e ea 8b f5 0f 2d b3 14 33\tFFLRBROMNXKUIZ\n" + "9\tgoogl\t81.44200000000001\t2018-01-01T01:48:00.000000Z\tfalse\t\t0.2677326840703891\t0.5425\t1001\t2015-11-14T07:05:22.934Z\tHYRX\t-8793423647053878901\t1970-01-01T02:13:20.000000Z\t33\t00000000 25 c2 20 ff 70 3a c7 8a b3 14 cd 47 0b 0c\tFMQNTOG\n" + "10\tmsft\t3.973\t2018-01-01T02:00:00.000000Z\tfalse\tXYZ\tNaN\tNaN\t828\t2015-06-18T18:07:42.406Z\tPEHN\t-7398902448022205322\t1970-01-01T02:30:00.000000Z\t50\t00000000 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57 ff\n" + "00000010 9a ef 88 cb\tCNGTNLEGPUHH\n";
assertMemoryLeak(() -> {
createX();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
Assert.assertEquals("b", reader.getMetadata().getColumnName(4));
// check cursor before renaming column
TestUtils.assertReader(expectedBefore, reader, sink);
try (TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
writer.renameColumn("b", "bb");
writer.renameColumn("c", "cc");
Assert.assertEquals("bb", writer.getMetadata().getColumnName(4));
}
// reload reader
Assert.assertTrue(reader.reload());
// check cursor after reload
TestUtils.assertReader(expectedAfter, reader, sink);
assertReader(expectedAfter, "x");
Assert.assertEquals("bb", reader.getMetadata().getColumnName(4));
}
});
}
Aggregations