Search in sources :

Example 6 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class SymbolMapTest method testTransactionalRead.

@Test
public void testTransactionalRead() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1000000;
        Rnd rnd = new Rnd();
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, false);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
                long prev = -1L;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    prev = key;
                }
                rnd.reset();
                try (SymbolMapReaderImpl reader = new SymbolMapReaderImpl(configuration, path, "x", N)) {
                    for (int i = 0; i < N; i++) {
                        CharSequence cs = rnd.nextChars(10);
                        TestUtils.assertEquals(cs, reader.valueOf(i));
                        Assert.assertEquals(i, reader.keyOf(cs));
                    }
                    Assert.assertNull(reader.valueOf(N));
                    Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.keyOf("hola"));
                    Assert.assertEquals(N, writer.put("XYZ"));
                    // must not be able to read new symbol
                    Assert.assertNull(reader.valueOf(N));
                    Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.keyOf("XYZ"));
                    reader.updateSymbolCount(N + 1);
                    TestUtils.assertEquals("XYZ", reader.valueOf(N));
                    Assert.assertEquals(N, reader.keyOf("XYZ"));
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 7 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class SymbolMapTest method testTruncate.

@Test
public void testTruncate() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1024;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, true);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
                Rnd rnd = new Rnd();
                long prev = -1L;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
                Assert.assertEquals(N, writer.getSymbolCount());
                writer.truncate();
                Assert.assertEquals(0, writer.getSymbolCount());
                // reset RND to exercise symbol cache
                rnd.reset();
                prev = -1;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
                Assert.assertEquals(N, writer.getSymbolCount());
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 8 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class SymbolMapTest method testLookupPerformance.

@Test
public void testLookupPerformance() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 10000000;
        int symbolCount = 1024;
        ObjList<String> symbols = new ObjList<>();
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", symbolCount, true);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
                Rnd rnd = new Rnd();
                long prev = -1L;
                for (int i = 0; i < symbolCount; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    symbols.add(cs.toString());
                    Assert.assertEquals(prev + 1, key);
                    prev = key;
                }
                long t = System.nanoTime();
                for (int i = 0; i < N; i++) {
                    int key = rnd.nextPositiveInt() % symbolCount;
                    Assert.assertEquals(key, writer.put(symbols.getQuick(key)));
                }
                System.out.println("SymbolMapWriter lookup performance [10M <500ms]: " + (System.nanoTime() - t) / 1000000);
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) ObjList(io.questdb.std.ObjList) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 9 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class SymbolMapTest method testRollback.

@Test
public void testRollback() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1024;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, true);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
                Rnd rnd = new Rnd();
                long prev = -1L;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
                writer.rollback(N / 2);
                prev = N / 2 - 1;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 10 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class SymbolMapTest method testAppend.

@Test
public void testAppend() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 1000;
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", N, true);
            Rnd rnd = new Rnd();
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
                long prev = -1L;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
            }
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", N, -1, NOOP_COLLECTOR)) {
                long prev = N - 1;
                // append second batch and check that symbol keys start with N
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    Assert.assertEquals(key, writer.put(cs));
                    prev = key;
                }
                // try append first batch - this should return symbol keys starting with 0
                rnd.reset();
                prev = -1;
                for (int i = 0; i < N; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    Assert.assertEquals(prev + 1, key);
                    prev = key;
                }
                Assert.assertEquals(SymbolTable.VALUE_IS_NULL, writer.put(null));
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Aggregations

Rnd (io.questdb.std.Rnd)76 Test (org.junit.Test)49 Record (io.questdb.cairo.sql.Record)32 RecordCursor (io.questdb.cairo.sql.RecordCursor)29 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)28 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)24 TableWriter (io.questdb.cairo.TableWriter)23 Path (io.questdb.std.str.Path)10 RuntimeIntervalModel (io.questdb.griffin.model.RuntimeIntervalModel)4 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 DataFrameCursor (io.questdb.cairo.sql.DataFrameCursor)2 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)2 RowCursor (io.questdb.cairo.sql.RowCursor)2 StaticSymbolTable (io.questdb.cairo.sql.StaticSymbolTable)2 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)2 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)2 AbstractFunctionFactoryTest (io.questdb.griffin.engine.AbstractFunctionFactoryTest)2 BinarySequence (io.questdb.std.BinarySequence)2 BytecodeAssembler (io.questdb.std.BytecodeAssembler)2 FilesFacade (io.questdb.std.FilesFacade)2