Search in sources :

Example 16 with TableReader

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

the class AlterTableRenameColumnTest method testRenameColumnExistingReader.

@Test
public void testRenameColumnExistingReader() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try {
            createX();
            try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
                Assert.assertEquals(ALTER, compiler.compile("alter table x rename column e to z", sqlExecutionContext).getType());
                String expected = "{\"columnCount\":16,\"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\":\"z\",\"type\":\"FLOAT\"},{\"index\":8,\"name\":\"f\",\"type\":\"SHORT\"},{\"index\":9,\"name\":\"g\",\"type\":\"DATE\"},{\"index\":10,\"name\":\"ik\",\"type\":\"SYMBOL\"},{\"index\":11,\"name\":\"j\",\"type\":\"LONG\"},{\"index\":12,\"name\":\"k\",\"type\":\"TIMESTAMP\"},{\"index\":13,\"name\":\"l\",\"type\":\"BYTE\"},{\"index\":14,\"name\":\"m\",\"type\":\"BINARY\"},{\"index\":15,\"name\":\"n\",\"type\":\"STRING\"}],\"timestampIndex\":3}";
                sink.clear();
                reader.reload();
                reader.getMetadata().toJson(sink);
                TestUtils.assertEquals(expected, sink);
            }
            Assert.assertEquals(0, engine.getBusyWriterCount());
            Assert.assertEquals(0, engine.getBusyReaderCount());
        } finally {
            engine.clear();
        }
    });
}
Also used : TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Example 17 with TableReader

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

the class AlterTableRenameColumnTest method testRenameColumnAndCheckOpenReader.

@Test
public void testRenameColumnAndCheckOpenReader() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x1 (a int, b double, t timestamp) timestamp(t)", sqlExecutionContext);
        try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x1")) {
            Assert.assertEquals("b", reader.getMetadata().getColumnName(1));
            try (TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x1", "testing")) {
                Assert.assertEquals("b", writer.getMetadata().getColumnName(1));
                writer.renameColumn("b", "bb");
                Assert.assertEquals("bb", writer.getMetadata().getColumnName(1));
            }
            Assert.assertTrue(reader.reload());
            Assert.assertEquals("bb", reader.getMetadata().getColumnName(1));
        }
    });
}
Also used : TableWriter(io.questdb.cairo.TableWriter) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Aggregations

TableReader (io.questdb.cairo.TableReader)17 Test (org.junit.Test)13 TableWriter (io.questdb.cairo.TableWriter)9 RecordCursorPrinter (io.questdb.cairo.RecordCursorPrinter)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 Path (io.questdb.std.str.Path)2 MessageBus (io.questdb.MessageBus)1 BitmapIndexReader (io.questdb.cairo.BitmapIndexReader)1 DataFrame (io.questdb.cairo.sql.DataFrame)1 Record (io.questdb.cairo.sql.Record)1 MemoryR (io.questdb.cairo.vm.api.MemoryR)1 Sequence (io.questdb.mp.Sequence)1 LatestByTask (io.questdb.tasks.LatestByTask)1