Search in sources :

Example 81 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class BindVariableServiceImplTest method testNamedSetLong256ToLong256NoDefine.

@Test
public void testNamedSetLong256ToLong256NoDefine() throws SqlException {
    bindVariableService.setLong256("x", 888, 777, 6666, 5555);
    StringSink sink = new StringSink();
    bindVariableService.getFunction(":x").getLong256(null, sink);
    TestUtils.assertEquals("0x15b30000000000001a0a00000000000003090000000000000378", sink);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 82 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class BindVariableServiceImplTest method testNamedSetLong256ToLong256AsObj.

@Test
public void testNamedSetLong256ToLong256AsObj() throws SqlException {
    final Long256Impl long256 = new Long256Impl();
    long256.setAll(888, 999, 777, 111);
    bindVariableService.setLong256("x");
    bindVariableService.setLong256("x", long256);
    final StringSink sink = new StringSink();
    bindVariableService.getFunction(":x").getLong256(null, sink);
    TestUtils.assertEquals("0x6f000000000000030900000000000003e70000000000000378", sink);
}
Also used : Long256Impl(io.questdb.std.Long256Impl) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 83 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class StrConstantTest method testConstant.

@Test
public void testConstant() {
    StrConstant constant = new StrConstant("abc");
    Assert.assertTrue(constant.isConstant());
    TestUtils.assertEquals("abc", constant.getStr(null));
    TestUtils.assertEquals("abc", constant.getStrB(null));
    Assert.assertEquals(3, constant.getStrLen(null));
    CharSink sink = new StringSink();
    constant.getStr(null, sink);
    TestUtils.assertEquals("abc", (CharSequence) sink);
}
Also used : CharSink(io.questdb.std.str.CharSink) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 84 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class TableSyncModel method fromBinary.

public void fromBinary(long mem) {
    long p = mem;
    tableAction = Unsafe.getUnsafe().getInt(p);
    p += 4;
    dataVersion = Unsafe.getUnsafe().getLong(p);
    p += 8;
    maxTimestamp = Unsafe.getUnsafe().getLong(p);
    p += 8;
    int n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_COLUMN_TOP) {
        columnTops.add(Unsafe.getUnsafe().getLong(p), Unsafe.getUnsafe().getInt(p + 8), Unsafe.getUnsafe().getLong(p + 12), 0);
        p += 20;
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_VAR_COLUMN_SIZE) {
        varColumnSizes.add(Unsafe.getUnsafe().getLong(p), Unsafe.getUnsafe().getInt(p + 8), Unsafe.getUnsafe().getLong(p + 12), 0);
        p += 20;
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_PARTITION) {
        partitions.add(// action
        Unsafe.getUnsafe().getInt(p), // partition timestamp
        Unsafe.getUnsafe().getLong(p + 4), // start row
        Unsafe.getUnsafe().getLong(p + 12), // row count
        Unsafe.getUnsafe().getLong(p + 20), // name txn
        Unsafe.getUnsafe().getLong(p + 28), // data txn
        Unsafe.getUnsafe().getLong(p + 36), 0, 0);
        p += 44;
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    final StringSink nameSink = Misc.getThreadLocalBuilder();
    for (int i = 0; i < n; i++) {
        int nameLen = Unsafe.getUnsafe().getInt(p);
        p += 4;
        for (long lim = p + nameLen * 2L; p < lim; p += 2) {
            nameSink.put(Unsafe.getUnsafe().getChar(p));
        }
        int type = Unsafe.getUnsafe().getInt(p);
        p += 4;
        long hash = Unsafe.getUnsafe().getLong(p);
        p += 8;
        boolean indexed = Unsafe.getUnsafe().getByte(p++) == 0;
        int valueBlockCapacity = Unsafe.getUnsafe().getInt(p);
        p += 4;
        addedColumnMetadata.add(new TableColumnMetadata(Chars.toString(nameSink), hash, type, indexed, valueBlockCapacity, true, null));
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_COLUMN_META_INDEX) {
        columnMetaIndex.add((long) Unsafe.getUnsafe().getInt(p), Unsafe.getUnsafe().getLong(p + 4));
        p += 12;
    }
}
Also used : StringSink(io.questdb.std.str.StringSink)

Example 85 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class PageFrameCursorTest method testVarColumnWithColumnTop.

@Test
public void testVarColumnWithColumnTop() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as (select" + " rnd_int() a," + " rnd_str() b," + " timestamp_sequence(to_timestamp('2022-01-13T00:00:00', 'yyyy-MM-ddTHH:mm:ss'), 100000L) t" + " from long_sequence(10)" + ") timestamp (t) partition by DAY", sqlExecutionContext);
        compiler.compile("alter table x add column c string", sqlExecutionContext).execute(null).await();
        compiler.compile("insert into x " + "select" + " rnd_int() a," + " rnd_str() b," + " timestamp_sequence(to_timestamp('2022-01-13T00:00:01', 'yyyy-MM-ddTHH:mm:ss'), 100000L) t," + " rnd_str() c" + " from long_sequence(10)", sqlExecutionContext);
        TestUtils.printSql(compiler, sqlExecutionContext, "select b from x", sink);
        final StringSink actualSink = new StringSink();
        // header
        actualSink.put("b\n");
        try (RecordCursorFactory factory = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory()) {
            // test that we can read string column without using index
            try (PageFrameCursor pageFrameCursor = factory.getPageFrameCursor(sqlExecutionContext)) {
                PageFrame frame;
                while ((frame = pageFrameCursor.next()) != null) {
                    long size = frame.getPageSize(1);
                    long topOfVarAddress = frame.getPageAddress(1);
                    long fixAddress = frame.getIndexPageAddress(1);
                    long count = frame.getPartitionHi() - frame.getPartitionLo();
                    while (count > 0) {
                        // validate that index column has correct offsets
                        final long offset = Unsafe.getUnsafe().getLong(fixAddress);
                        Assert.assertTrue(offset >= 0 && offset < size);
                        fixAddress += 8;
                        long varAddress = topOfVarAddress + offset;
                        // string len
                        int len = Unsafe.getUnsafe().getInt(varAddress);
                        varAddress += 4;
                        if (len != -1) {
                            for (int i = 0; i < len; i++) {
                                actualSink.put(Unsafe.getUnsafe().getChar(varAddress + i * 2L));
                            }
                        }
                        actualSink.put('\n');
                        count--;
                    }
                }
                TestUtils.assertEquals(sink, actualSink);
            }
        }
    });
}
Also used : PageFrameCursor(io.questdb.cairo.sql.PageFrameCursor) PageFrame(io.questdb.cairo.sql.PageFrame) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Aggregations

StringSink (io.questdb.std.str.StringSink)284 Test (org.junit.Test)167 Function (io.questdb.cairo.sql.Function)38 BaseConnection (org.postgresql.core.BaseConnection)36 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)28 StrConstant (io.questdb.griffin.engine.functions.constants.StrConstant)22 StrFunction (io.questdb.griffin.engine.functions.StrFunction)20 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)16 Path (io.questdb.std.str.Path)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CyclicBarrier (java.util.concurrent.CyclicBarrier)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 SqlCompiler (io.questdb.griffin.SqlCompiler)10 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)10 SqlException (io.questdb.griffin.SqlException)9 Metrics (io.questdb.Metrics)8 io.questdb.cairo (io.questdb.cairo)8 AllowAllCairoSecurityContext (io.questdb.cairo.security.AllowAllCairoSecurityContext)8 NetUtils (io.questdb.cutlass.NetUtils)8