Search in sources :

Example 1 with CastIntToByteFunctionFactory

use of io.questdb.griffin.engine.functions.cast.CastIntToByteFunctionFactory 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)

Aggregations

GenericRecordMetadata (io.questdb.cairo.GenericRecordMetadata)1 CastIntToByteFunctionFactory (io.questdb.griffin.engine.functions.cast.CastIntToByteFunctionFactory)1 CastIntToShortFunctionFactory (io.questdb.griffin.engine.functions.cast.CastIntToShortFunctionFactory)1 CastLongToDateFunctionFactory (io.questdb.griffin.engine.functions.cast.CastLongToDateFunctionFactory)1 CastLongToTimestampFunctionFactory (io.questdb.griffin.engine.functions.cast.CastLongToTimestampFunctionFactory)1 StringSink (io.questdb.std.str.StringSink)1