Search in sources :

Example 11 with StringSink

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

the class GeoHashesTest method testFromString.

@Test(expected = NumericException.class)
public void testFromString() throws NumericException {
    StringSink sink = Misc.getThreadLocalBuilder();
    sink.put("@s");
    GeoHashes.fromString(sink.toString(), 0, 2);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 12 with StringSink

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

the class AbstractFunctionFactoryTest method callCustomised.

private Invocation callCustomised(String signature, boolean forceConstant, boolean argTypeFromSig, Object... args) throws SqlException {
    setUp();
    toShortRefs = 0;
    toByteRefs = 0;
    toTimestampRefs = 0;
    toDateRefs = 0;
    final FunctionFactory functionFactory = getFactory0();
    if (signature == null) {
        signature = functionFactory.getSignature();
    }
    // validate signature first
    final int pos = FunctionFactoryDescriptor.validateSignatureAndGetNameSeparator(signature);
    // create metadata
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    final String name = signature.substring(0, pos);
    final int argCount;
    final boolean hasVarArg;
    final boolean constVarArg;
    if (signature.indexOf('v', pos) != -1) {
        hasVarArg = true;
        constVarArg = true;
    } else if (signature.indexOf('V', pos) != -1) {
        hasVarArg = true;
        constVarArg = false;
    } else {
        hasVarArg = false;
        constVarArg = false;
    }
    if (hasVarArg) {
        argCount = signature.length() - pos - 3;
        Assert.assertTrue(args.length >= argCount);
    } else {
        argCount = signature.length() - pos - 2;
        Assert.assertEquals("Invalid number of arguments", argCount, args.length);
    }
    final StringSink expression1 = new StringSink();
    final StringSink expression2 = new StringSink();
    final boolean setOperation = OperatorExpression.getOperatorType(name) == OperatorExpression.SET;
    final boolean operator = OperatorExpression.isOperator(name);
    if (operator && !setOperation) {
        switch(argCount) {
            case 0:
                expression1.put(name);
                expression2.put(name);
                break;
            case 1:
                expression1.put(name).put(' ');
                expression2.put(name).put(' ');
                printArgument(signature, pos, forceConstant, metadata, argTypeFromSig, constVarArg, expression1, expression2, 0, args[0]);
                break;
            default:
                // two args
                printArgument(signature, pos, forceConstant, metadata, argTypeFromSig, constVarArg, expression1, expression2, 0, args[0]);
                expression1.put(' ').put(name).put(' ');
                expression2.put(' ').put(name).put(' ');
                printArgument(signature, pos, forceConstant, metadata, argTypeFromSig, constVarArg, expression1, expression2, 1, args[1]);
                break;
        }
    } else {
        if (!setOperation) {
            expression1.put(name).put('(');
            expression2.put(name).put('(');
        }
        for (int i = 0, n = args.length; i < n; i++) {
            if ((setOperation && i > 1) || (!setOperation && i > 0)) {
                expression1.put(',');
                expression2.put(',');
            }
            printArgument(signature, pos, forceConstant, metadata, i < argCount, constVarArg, expression1, expression2, i, args[i]);
            if (i == 0 && setOperation) {
                expression1.put(' ').put(name).put(' ').put('(');
                expression2.put(' ').put(name).put(' ').put('(');
            }
        }
        expression1.put(')');
        expression2.put(')');
    }
    functions.add(functionFactory);
    if (toTimestampRefs > 0) {
        functions.add(new CastLongToTimestampFunctionFactory());
    }
    if (toDateRefs > 0) {
        functions.add(new CastLongToDateFunctionFactory());
    }
    if (toShortRefs > 0) {
        functions.add(new CastIntToShortFunctionFactory());
    }
    if (toByteRefs > 0) {
        functions.add(new CastIntToByteFunctionFactory());
    }
    addExtraFunctions();
    FunctionParser functionParser = new FunctionParser(configuration, new FunctionFactoryCache(configuration, functions));
    return new Invocation(parseFunction(expression1, metadata, functionParser), parseFunction(expression2, metadata, functionParser), new TestRecord(args));
}
Also used : CastLongToTimestampFunctionFactory(io.questdb.griffin.engine.functions.cast.CastLongToTimestampFunctionFactory) CastIntToByteFunctionFactory(io.questdb.griffin.engine.functions.cast.CastIntToByteFunctionFactory) StringSink(io.questdb.std.str.StringSink) CastLongToDateFunctionFactory(io.questdb.griffin.engine.functions.cast.CastLongToDateFunctionFactory) GenericRecordMetadata(io.questdb.cairo.GenericRecordMetadata) CastIntToShortFunctionFactory(io.questdb.griffin.engine.functions.cast.CastIntToShortFunctionFactory) CastLongToTimestampFunctionFactory(io.questdb.griffin.engine.functions.cast.CastLongToTimestampFunctionFactory) CastIntToShortFunctionFactory(io.questdb.griffin.engine.functions.cast.CastIntToShortFunctionFactory) CastLongToDateFunctionFactory(io.questdb.griffin.engine.functions.cast.CastLongToDateFunctionFactory) CastIntToByteFunctionFactory(io.questdb.griffin.engine.functions.cast.CastIntToByteFunctionFactory)

Example 13 with StringSink

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

the class StrBindVariableTest method testSimple.

@Test
public void testSimple() {
    String expected = "xyz";
    StrBindVariable variable = new StrBindVariable(Numbers.MAX_SCALE);
    variable.setValue(expected);
    TestUtils.assertEquals(expected, variable.getStr(null));
    TestUtils.assertEquals(expected, variable.getStrB(null));
    Assert.assertEquals(expected.length(), variable.getStrLen(null));
    StringSink sink = new StringSink();
    variable.getStr(null, sink);
    TestUtils.assertEquals(expected, sink);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 14 with StringSink

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

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 15 with StringSink

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

the class BindVariableServiceImplTest method testSetLong256ToLong256.

@Test
public void testSetLong256ToLong256() throws SqlException {
    bindVariableService.define(0, ColumnType.LONG256, 0);
    bindVariableService.setLong256(0, 888, 777, 6666, 5555);
    StringSink sink = new StringSink();
    bindVariableService.getFunction(0).getLong256(null, sink);
    TestUtils.assertEquals("0x15b30000000000001a0a00000000000003090000000000000378", sink);
}
Also used : 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