Search in sources :

Example 1 with RecordCursorPrinter

use of io.questdb.cairo.RecordCursorPrinter in project questdb by bluestreak01.

the class AlterTableAlterSymbolColumnCacheFlagTest method testAlterSymbolCacheFlagToFalseAndCheckOpenReaderWithCursor.

@Test
public void testAlterSymbolCacheFlagToFalseAndCheckOpenReaderWithCursor() throws Exception {
    String expectedOrdered = "sym\n" + "googl\n" + "googl\n" + "googl\n" + "googl\n" + "googl\n" + "googl\n" + "ibm\n" + "ibm\n" + "msft\n" + "msft\n";
    String expectedChronological = "sym\n" + "msft\n" + "googl\n" + "googl\n" + "ibm\n" + "googl\n" + "ibm\n" + "googl\n" + "googl\n" + "googl\n" + "msft\n";
    final RecordCursorPrinter printer = new SingleColumnRecordCursorPrinter(1);
    assertMemoryLeak(() -> {
        assertMemoryLeak(this::createX);
        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, false);
            }
            // 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");
}
Also used : RecordCursorPrinter(io.questdb.cairo.RecordCursorPrinter) TableWriter(io.questdb.cairo.TableWriter) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Example 2 with RecordCursorPrinter

use of io.questdb.cairo.RecordCursorPrinter 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");
}
Also used : RecordCursorPrinter(io.questdb.cairo.RecordCursorPrinter) TableWriter(io.questdb.cairo.TableWriter) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Aggregations

RecordCursorPrinter (io.questdb.cairo.RecordCursorPrinter)2 TableReader (io.questdb.cairo.TableReader)2 TableWriter (io.questdb.cairo.TableWriter)2 Test (org.junit.Test)2