@Override
    public StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                             SiddhiQueryContext siddhiQueryContext) {
        if (attributeExpressionExecutors.length != 2) {
            throw new SiddhiAppValidationException("convert() must have at 2 parameters, attribute and to be " +
                    "converted type");
        }
        inputType = attributeExpressionExecutors[0].getReturnType();

        if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
            throw new SiddhiAppValidationException("2nd parameter of convert() must be 'string' have constant " +
                    "value either of (STRING, INT, LONG, FLOAT, DOUBLE, "
                    + "BOOL), but found " +
                    attributeExpressionExecutors[0].getReturnType());
        }
        if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
            throw new SiddhiAppValidationException("2nd parameter of convert() must have constant value either " +
                    "of (STRING, INT, LONG, FLOAT, DOUBLE, BOOL), but found "
                    + "a variable expression");
        }

        String type = (String) attributeExpressionExecutors[1].execute(null);
        if (Attribute.Type.STRING.toString().equalsIgnoreCase(type)) {
            returnType = Attribute.Type.STRING;
        } else if (Attribute.Type.BOOL.toString().equalsIgnoreCase(type)) {
            returnType = Attribute.Type.BOOL;
        } else if (Attribute.Type.DOUBLE.toString().equalsIgnoreCase(type)) {
            returnType = Attribute.Type.DOUBLE;
        } else if (Attribute.Type.FLOAT.toString().equalsIgnoreCase(type)) {
            returnType = Attribute.Type.FLOAT;
        } else if (Attribute.Type.INT.toString().equalsIgnoreCase(type)) {
            returnType = Attribute.Type.INT;
        } else if (Attribute.Type.LONG.toString().equalsIgnoreCase(type)) {
            returnType = Attribute.Type.LONG;
        } else {
            throw new SiddhiAppValidationException("2nd parameter of convert() must have value either of " +
                    "(STRING, INT, LONG, FLOAT, DOUBLE, BOOL), but found '" +
                    type + "'");
        }

        if (inputType == Attribute.Type.OBJECT && returnType != Attribute.Type.STRING) {
            throw new SiddhiAppValidationException("2nd parameter of convert() cannot be other than 'string' if " +
                    "1st parameter is 'object', but found " + attributeExpressionExecutors[1].getReturnType());
        }

        return null;
    }
Executor class for convert function. Function execution logic is implemented in execute here.
modules/siddhi-core/src/main/java/io/siddhi/core/executor/function/ConvertFunctionExecutor.java