Search in sources :

Example 86 with StringSink

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

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

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

the class SqlCompilerTest method testGeoLiteralBinLength.

@Test
public void testGeoLiteralBinLength() throws Exception {
    assertMemoryLeak(() -> {
        StringSink bitString = Misc.getThreadLocalBuilder();
        bitString.put(Chars.repeat("0", 59)).put('1');
        assertSql("select ##" + bitString + " as geobits", "geobits\n" + "000000000001\n");
    });
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 88 with StringSink

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

the class BooleanFunctionTest method testGetStr2.

@Test
public void testGetStr2() {
    final StringSink sink = new StringSink();
    functionA.getStr(null, sink);
    TestUtils.assertEquals("false", sink);
    sink.clear();
    functionB.getStr(null, sink);
    TestUtils.assertEquals("true", sink);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 89 with StringSink

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

the class CharFunctionTest method testGetStrZ2.

@Test
public void testGetStrZ2() {
    StringSink sink = new StringSink();
    zeroFunc.getStr(null, sink);
    TestUtils.assertEquals("", sink);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 90 with StringSink

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

the class CharFunctionTest method testGetStr2.

@Test
public void testGetStr2() {
    StringSink sink = new StringSink();
    function.getStr(null, sink);
    TestUtils.assertEquals("4", 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