Search in sources :

Example 31 with StringSink

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

the class ReplDataAccessTest method testSimple.

@Test
public void testSimple() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as (select" + " rnd_int() a," + " rnd_str() b," + " timestamp_sequence(0, 100000000) t" + " from long_sequence(1000)" + ") timestamp (t) partition by DAY", 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 varAddress = frame.getPageAddress(1);
                    long fixAddress = frame.getIndexPageAddress(1);
                    long topOfVarAddress = varAddress;
                    long count = frame.getPartitionHi() - frame.getPartitionLo();
                    while (count > 0) {
                        // validate that index column has correct offsets
                        Assert.assertEquals(varAddress - topOfVarAddress, Unsafe.getUnsafe().getLong(fixAddress));
                        fixAddress += 8;
                        // 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));
                            }
                            varAddress += len * 2L;
                        }
                        actualSink.put('\n');
                        count--;
                    }
                    Assert.assertEquals(varAddress - topOfVarAddress, frame.getPageSize(1));
                }
                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)

Example 32 with StringSink

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

the class GeoHashesSwitchOnIntVsCharBenchmark method isValidBits1.

@Benchmark
public static void isValidBits1() {
    Rnd rnd = new Rnd();
    StringSink sink = Misc.getThreadLocalBuilder();
    for (int j = 0, m = 10_000_000; j < m; j++) {
        if (!isValidBits1(rnd_geobits(rnd, sink), 0)) {
            throw new AssertionError();
        }
    }
}
Also used : Rnd(io.questdb.std.Rnd) StringSink(io.questdb.std.str.StringSink)

Example 33 with StringSink

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

the class CastFloatToSymbolFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    final Function arg = args.getQuick(0);
    if (arg.isConstant()) {
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(arg.getFloat(null), 4);
        return SymbolConstant.newInstance(sink);
    }
    return new Func(arg);
}
Also used : Function(io.questdb.cairo.sql.Function) StringSink(io.questdb.std.str.StringSink)

Example 34 with StringSink

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

the class CastDoubleToStrFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    Function intFunc = args.getQuick(0);
    if (intFunc.isConstant()) {
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(intFunc.getDouble(null), configuration.getDoubleToStrCastScale());
        return new StrConstant(Chars.toString(sink));
    }
    return new Func(args.getQuick(0), configuration.getDoubleToStrCastScale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Example 35 with StringSink

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

the class CastCharToStrFunctionFactory method newInstance.

public Function newInstance(Function func) {
    if (func.isConstant()) {
        final char value = func.getChar(null);
        if (value == 0) {
            return new StrConstant(null);
        }
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(value);
        return new StrConstant(Chars.toString(sink));
    }
    return new Func(func);
}
Also used : StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

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