Search in sources :

Example 61 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReaderMetadataTest method assertThat.

private void assertThat(String expected, ColumnManipulator manipulator, int columnCount) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(root).concat("all")) {
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    manipulator.restructure(writer);
                }
                long pTranstionIndex = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(pTranstionIndex);
                    Assert.assertEquals(columnCount, metadata.getColumnCount());
                    for (int i = 0; i < columnCount; i++) {
                        RecordColumnMetadata m = metadata.getColumnQuick(i);
                        sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    if (expected.length() > 0) {
                        String[] lines = expected.split("\n");
                        Assert.assertEquals(columnCount, lines.length);
                        for (int i = 0; i < columnCount; i++) {
                            int p = lines[i].indexOf(':');
                            Assert.assertEquals(i, metadata.getColumnIndexQuiet(lines[i].substring(0, p)));
                        }
                    }
                } finally {
                    TableReaderMetadata.freeTransitionIndex(pTranstionIndex);
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) StringSink(com.questdb.std.str.StringSink)

Example 62 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReaderMetadataTest method testColumnIndex.

@Test
public void testColumnIndex() {
    ObjIntHashMap<String> expected = new ObjIntHashMap<>();
    expected.put("int", 0);
    expected.put("byte", 2);
    expected.put("bin", 9);
    expected.put("short", 1);
    expected.put("float", 4);
    expected.put("long", 5);
    expected.put("xyz", -1);
    expected.put("str", 6);
    expected.put("double", 3);
    expected.put("sym", 7);
    expected.put("bool", 8);
    expected.put("all.int", 0);
    expected.put("all.byte", 2);
    expected.put("all.bin", 9);
    expected.put("all.short", 1);
    expected.put("all.float", 4);
    expected.put("all.long", 5);
    expected.put("all.xyz", -1);
    expected.put("all.str", 6);
    expected.put("all.double", 3);
    expected.put("all.sym", 7);
    expected.put("zall.sym", -1);
    try (Path path = new Path().of(root).concat("all").concat(TableUtils.META_FILE_NAME).$();
        TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path)) {
        for (ObjIntHashMap.Entry<String> e : expected) {
            Assert.assertEquals(e.value, metadata.getColumnIndexQuiet(e.key));
        }
    }
}
Also used : Path(com.questdb.std.str.Path) ObjIntHashMap(com.questdb.std.ObjIntHashMap) Test(org.junit.Test)

Example 63 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReaderMetadataTimestampTest method assertThat.

private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
    int columnCount = 11;
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(root).concat("all")) {
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
                Assert.assertEquals(12, metadata.getColumnCount());
                Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    writer.removeColumn("timestamp");
                }
                long pTransitionIndex = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(pTransitionIndex);
                    Assert.assertEquals(columnCount, metadata.getColumnCount());
                    for (int i = 0; i < columnCount; i++) {
                        RecordColumnMetadata m = metadata.getColumnQuick(i);
                        sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    Assert.assertEquals(-1, metadata.getTimestampIndex());
                } finally {
                    TableReaderMetadata.freeTransitionIndex(pTransitionIndex);
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) StringSink(com.questdb.std.str.StringSink)

Example 64 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableReaderMetadataTimestampTest method assertThatTimestampRemains.

private void assertThatTimestampRemains(TableReaderMetadataTest.ColumnManipulator manipulator, String expected, int expectedInitialTimestampIndex, int expectedFinalTimestampIndex, int expectedColumnCount) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(root).concat("all")) {
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
                Assert.assertEquals(12, metadata.getColumnCount());
                Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    manipulator.restructure(writer);
                }
                long address = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(address);
                    Assert.assertEquals(expectedColumnCount, metadata.getColumnCount());
                    for (int i = 0; i < expectedColumnCount; i++) {
                        RecordColumnMetadata m = metadata.getColumnQuick(i);
                        sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    Assert.assertEquals(expectedFinalTimestampIndex, metadata.getTimestampIndex());
                } finally {
                    TableReaderMetadata.freeTransitionIndex(address);
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) StringSink(com.questdb.std.str.StringSink)

Example 65 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class TableUtilsTest method testCreate.

@Test
public void testCreate() {
    final CharSequence root = temp.getRoot().getAbsolutePath();
    final JournalMetadata metadata = getJournalStructure().build();
    try (AppendMemory appendMemory = new AppendMemory()) {
        try (Path path = new Path()) {
            TableUtils.create(FF, path, appendMemory, root, metadata, 509);
            Assert.assertEquals(TABLE_EXISTS, TableUtils.exists(FF, path, root, metadata.getName()));
            path.of(root).concat(metadata.getName()).concat("_meta").$();
            try (ReadOnlyMemory mem = new ReadOnlyMemory(FF, path, Files.PAGE_SIZE, FF.length(path))) {
                long p = 0;
                Assert.assertEquals(metadata.getColumnCount(), mem.getInt(p));
                p += 4;
                Assert.assertEquals(PartitionBy.NONE, mem.getInt(p));
                p += 4;
                Assert.assertEquals(metadata.getTimestampIndex(), mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.INT, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.DOUBLE, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.FLOAT, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.BYTE, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.LONG, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.STRING, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.BOOLEAN, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.SYMBOL, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.SHORT, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.DATE, mem.getInt(p));
                p += 4;
                Assert.assertEquals(ColumnType.DATE, mem.getInt(p));
                p += 4;
                p = assertCol(mem, p, "i");
                p = assertCol(mem, p, "d");
                p = assertCol(mem, p, "f");
                p = assertCol(mem, p, "b");
                p = assertCol(mem, p, "l");
                p = assertCol(mem, p, "str");
                p = assertCol(mem, p, "boo");
                p = assertCol(mem, p, "sym");
                p = assertCol(mem, p, "sho");
                p = assertCol(mem, p, "date");
                assertCol(mem, p, "timestamp");
            }
        }
    }
}
Also used : Path(com.questdb.std.str.Path) JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Test(org.junit.Test)

Aggregations

Path (com.questdb.std.str.Path)74 Test (org.junit.Test)46 File (java.io.File)8 Rnd (com.questdb.std.Rnd)7 LPSZ (com.questdb.std.str.LPSZ)6 NativeLPSZ (com.questdb.std.str.NativeLPSZ)5 NumericException (com.questdb.common.NumericException)3 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)3 DirectCharSequence (com.questdb.std.str.DirectCharSequence)3 StringSink (com.questdb.std.str.StringSink)3 RowCursor (com.questdb.common.RowCursor)2 CreateTableModel (com.questdb.griffin.lexer.model.CreateTableModel)2 ObjList (com.questdb.std.ObjList)2 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 ByteBuffer (java.nio.ByteBuffer)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 Chars (com.questdb.std.Chars)1 FilesFacade (com.questdb.std.FilesFacade)1