use of io.questdb.griffin.model.RuntimeIntervalModel in project questdb by bluestreak01.
the class IntervalBwdDataFrameCursorTest method testReload.
public void testReload(int partitionBy, long increment, LongList intervals, int rowCount, CharSequence expected1, CharSequence expected2) throws Exception {
assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", partitionBy).col("a", ColumnType.SYMBOL).indexed(true, 4).col("b", ColumnType.SYMBOL).indexed(true, 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
long timestamp = TimestampFormatUtils.parseTimestamp("1980-01-01T00:00:00.000Z");
final int timestampIndex;
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x")) {
timestampIndex = reader.getMetadata().getTimestampIndex();
}
final TableReaderRecord record = new TableReaderRecord();
final IntervalBwdDataFrameCursorFactory factory = new IntervalBwdDataFrameCursorFactory(engine, "x", -1, 0, new RuntimeIntervalModel(intervals), timestampIndex);
try (DataFrameCursor cursor = factory.getCursor(AllowAllSqlSecurityContext.INSTANCE)) {
// assert that there is nothing to start with
record.of(cursor.getTableReader());
assertEquals("", record, cursor);
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
Assert.assertTrue(cursor.reload());
assertEquals(expected1, record, cursor);
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
Assert.assertTrue(cursor.reload());
if (expected2 != null) {
assertEquals(expected2, record, cursor);
} else {
assertEquals(expected1, record, cursor);
}
Assert.assertFalse(cursor.reload());
}
}
try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "x", "testing")) {
writer.removeColumn("b");
}
try {
factory.getCursor(AllowAllSqlSecurityContext.INSTANCE);
Assert.fail();
} catch (ReaderOutOfDateException ignored) {
}
});
}
use of io.questdb.griffin.model.RuntimeIntervalModel in project questdb by bluestreak01.
the class IntervalFwdDataFrameCursorTest method testIntervals.
private void testIntervals(int partitionBy, long increment, int rowCount, CharSequence expected, long expectedCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", partitionBy).col("a", ColumnType.SYMBOL).indexed(true, 4).col("b", ColumnType.SYMBOL).indexed(true, 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
long timestamp = TimestampFormatUtils.parseTimestamp("1980-01-01T00:00:00.000Z");
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
}
try (TableReader reader = new TableReader(configuration, "x")) {
final TableReaderRecord record = new TableReaderRecord();
IntervalFwdDataFrameCursor cursor = new IntervalFwdDataFrameCursor(new RuntimeIntervalModel(IntervalFwdDataFrameCursorTest.intervals), reader.getMetadata().getTimestampIndex());
cursor.of(reader, null);
record.of(reader);
assertEquals(expected, record, cursor);
if (expected.length() > 0) {
cursor.toTop();
assertIndexRowsMatchSymbol(cursor, record, 0, expectedCount);
cursor.toTop();
assertIndexRowsMatchSymbol(cursor, record, 1, expectedCount);
}
cursor.toTop();
assertEquals(expected, record, cursor);
}
});
}
use of io.questdb.griffin.model.RuntimeIntervalModel in project questdb by bluestreak01.
the class IntervalFwdDataFrameCursorTest method testReload.
public void testReload(int partitionBy, long increment, LongList intervals, int rowCount, CharSequence expected1, CharSequence expected2) throws Exception {
assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", partitionBy).col("a", ColumnType.SYMBOL).indexed(true, 4).col("b", ColumnType.SYMBOL).indexed(true, 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
long timestamp = TimestampFormatUtils.parseTimestamp("1980-01-01T00:00:00.000Z");
final int timestampIndex;
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x")) {
timestampIndex = reader.getMetadata().getTimestampIndex();
}
final TableReaderRecord record = new TableReaderRecord();
final IntervalFwdDataFrameCursorFactory factory = new IntervalFwdDataFrameCursorFactory(engine, "x", -1, 0, new RuntimeIntervalModel(intervals), timestampIndex);
try (DataFrameCursor cursor = factory.getCursor(AllowAllSqlSecurityContext.INSTANCE)) {
// assert that there is nothing to start with
record.of(cursor.getTableReader());
assertEquals("", record, cursor);
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
Assert.assertTrue(cursor.reload());
assertEquals(expected1, record, cursor);
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
Assert.assertTrue(cursor.reload());
if (expected2 != null) {
assertEquals(expected2, record, cursor);
} else {
assertEquals(expected1, record, cursor);
}
Assert.assertFalse(cursor.reload());
}
}
try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "x", "testing")) {
writer.removeColumn("a");
}
try {
factory.getCursor(AllowAllSqlSecurityContext.INSTANCE);
Assert.fail();
} catch (ReaderOutOfDateException ignored) {
}
});
}
use of io.questdb.griffin.model.RuntimeIntervalModel in project questdb by bluestreak01.
the class IntervalFwdDataFrameCursorTest method testClose.
@Test
public void testClose() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE).col("a", ColumnType.INT).col("b", ColumnType.INT).timestamp()) {
CairoTestUtils.create(model);
}
TableReader reader = new TableReader(configuration, "x");
IntervalFwdDataFrameCursor cursor = new IntervalFwdDataFrameCursor(new RuntimeIntervalModel(intervals), reader.getMetadata().getTimestampIndex());
cursor.of(reader, null);
cursor.close();
Assert.assertFalse(reader.isOpen());
cursor.close();
Assert.assertFalse(reader.isOpen());
});
}
use of io.questdb.griffin.model.RuntimeIntervalModel in project questdb by bluestreak01.
the class IntervalBwdDataFrameCursorTest method testIntervals.
private void testIntervals(int partitionBy, long increment, int rowCount, CharSequence expected, long expectedCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", partitionBy).col("a", ColumnType.SYMBOL).indexed(true, 4).col("b", ColumnType.SYMBOL).indexed(true, 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
long timestamp = TimestampFormatUtils.parseTimestamp("1980-01-01T00:00:00.000Z");
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
}
try (TableReader reader = new TableReader(configuration, "x")) {
final TableReaderRecord record = new TableReaderRecord();
IntervalBwdDataFrameCursor cursor = new IntervalBwdDataFrameCursor(new RuntimeIntervalModel(IntervalBwdDataFrameCursorTest.intervals), reader.getMetadata().getTimestampIndex());
cursor.of(reader, null);
record.of(reader);
assertEquals(expected, record, cursor);
if (expected.length() > 0) {
cursor.toTop();
assertIndexRowsMatchSymbol(cursor, record, 0, expectedCount);
cursor.toTop();
assertIndexRowsMatchSymbol(cursor, record, 1, expectedCount);
}
cursor.toTop();
assertEquals(expected, record, cursor);
}
});
}
Aggregations