Search in sources :

Example 21 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project siddhi by wso2.

the class PlaybackTestCase method playbackTest9.

@Test(expectedExceptions = SiddhiParserException.class)
public void playbackTest9() throws InterruptedException {
    log.info("Playback Test 9: Testing playback with invalid increment time constant");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "@app:playback(idle.time = '100 millisecond', increment = '2') " + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(2 sec) " + "select symbol,price,volume " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 22 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project siddhi by wso2.

the class ConvertFunctionExecutor method init.

@Override
public void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("convert() must have at 2 parameters, attribute and to be " + "converted type");
    }
    inputType = attributeExpressionExecutors[0].getReturnType();
    if (inputType == Attribute.Type.OBJECT) {
        throw new SiddhiAppValidationException("1st parameter of convert() cannot be 'object' as " + "it's not supported, it has to be either of (STRING, " + "INT, LONG, FLOAT, DOUBLE, BOOL), but found " + 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 + "'");
    }
}
Also used : SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 23 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project siddhi by wso2.

the class ExternalTimeBatchWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    if (outputExpectsExpiredEvents) {
        this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
        this.storeExpiredEvents = true;
    }
    if (attributeExpressionExecutors.length >= 2 && attributeExpressionExecutors.length <= 5) {
        if (!(attributeExpressionExecutors[0] instanceof VariableExpressionExecutor)) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be a" + " variable, but found " + attributeExpressionExecutors[0].getClass());
        }
        if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.LONG) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be " + "type long, but found " + attributeExpressionExecutors[0].getReturnType());
        }
        timestampExpressionExecutor = (VariableExpressionExecutor) attributeExpressionExecutors[0];
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            timeToKeep = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
            timeToKeep = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        } else {
            throw new SiddhiAppValidationException("ExternalTimeBatch window's 2nd parameter windowTime " + "should be either int or long, but found " + attributeExpressionExecutors[1].getReturnType());
        }
        if (attributeExpressionExecutors.length >= 3) {
            isStartTimeEnabled = true;
            if ((attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor)) {
                if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.INT) {
                    startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
                } else if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.LONG) {
                    startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
                } else {
                    throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter " + "startTime should either be a constant (of type int or long) or an attribute (of type" + " long), but found " + attributeExpressionExecutors[2].getReturnType());
                }
            } else if (attributeExpressionExecutors[2].getReturnType() != Attribute.Type.LONG) {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter startTime " + "should either be a constant (of type int or long) or an attribute (of type long), but " + "found " + attributeExpressionExecutors[2].getReturnType());
            } else {
                startTimeAsVariable = attributeExpressionExecutors[2];
            }
        }
        if (attributeExpressionExecutors.length >= 4) {
            if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.INT) {
                schedulerTimeout = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
            } else if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.LONG) {
                schedulerTimeout = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
            } else {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 4th parameter timeout " + "should be either int or long, but found " + attributeExpressionExecutors[3].getReturnType());
            }
        }
        if (attributeExpressionExecutors.length == 5) {
            if (attributeExpressionExecutors[4].getReturnType() == Attribute.Type.BOOL) {
                replaceTimestampWithBatchEndTime = Boolean.parseBoolean(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[4]).getValue()));
            } else {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 5th parameter " + "replaceTimestampWithBatchEndTime should be bool, but found " + attributeExpressionExecutors[4].getReturnType());
            }
        }
    } else {
        throw new SiddhiAppValidationException("ExternalTimeBatch window should only have two to five " + "parameters (<long> timestamp, <int|long|time> windowTime, <long> startTime, <int|long|time> " + "timeout, <bool> replaceTimestampWithBatchEndTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    if (schedulerTimeout > 0) {
        if (expiredEventChunk == null) {
            this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 24 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitQuery_section.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Selector visitQuery_section(@NotNull SiddhiQLParser.Query_sectionContext ctx) {
    // query_section
    // :(SELECT ('*'| (output_attribute (',' output_attribute)* ))) group_by? having?
    // ;
    Selector selector = new Selector();
    List<OutputAttribute> attributeList = new ArrayList<OutputAttribute>(ctx.output_attribute().size());
    for (SiddhiQLParser.Output_attributeContext output_attributeContext : ctx.output_attribute()) {
        attributeList.add((OutputAttribute) visit(output_attributeContext));
    }
    selector.addSelectionList(attributeList);
    if (ctx.group_by() != null) {
        selector.addGroupByList((List<Variable>) visit(ctx.group_by()));
    }
    if (ctx.having() != null) {
        selector.having((Expression) visit(ctx.having()));
    }
    if (ctx.order_by() != null) {
        selector.addOrderByList((List<OrderByAttribute>) visit(ctx.order_by()));
    }
    if (ctx.limit() != null) {
        selector.limit((Constant) visit(ctx.limit()));
    }
    populateQueryContext(selector, ctx);
    return selector;
}
Also used : SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) Variable(org.wso2.siddhi.query.api.expression.Variable) ArrayList(java.util.ArrayList) OrderByAttribute(org.wso2.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputAttribute(org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute) BasicSelector(org.wso2.siddhi.query.api.execution.query.selection.BasicSelector) Selector(org.wso2.siddhi.query.api.execution.query.selection.Selector)

Example 25 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitConstant_value.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Constant visitConstant_value(@NotNull SiddhiQLParser.Constant_valueContext ctx) {
    // constant_value
    // :bool_value
    // |signed_double_value
    // |signed_float_value
    // |signed_long_value
    // |signed_int_value
    // |time_value
    // |string_value
    // ;
    Constant constant;
    if (ctx.bool_value() != null) {
        constant = Expression.value(((BoolConstant) visit(ctx.bool_value())).getValue());
    } else if (ctx.signed_double_value() != null) {
        constant = Expression.value(((DoubleConstant) visit(ctx.signed_double_value())).getValue());
    } else if (ctx.signed_float_value() != null) {
        constant = Expression.value(((FloatConstant) visit(ctx.signed_float_value())).getValue());
    } else if (ctx.signed_long_value() != null) {
        constant = Expression.value(((LongConstant) visit(ctx.signed_long_value())).getValue());
    } else if (ctx.signed_int_value() != null) {
        constant = Expression.value(((IntConstant) visit(ctx.signed_int_value())).getValue());
    } else if (ctx.time_value() != null) {
        constant = (TimeConstant) visit(ctx.time_value());
    } else if (ctx.string_value() != null) {
        constant = Expression.value(((StringConstant) visit(ctx.string_value())).getValue());
    } else {
        throw newSiddhiParserException(ctx);
    }
    populateQueryContext(constant, ctx);
    return constant;
}
Also used : BoolConstant(org.wso2.siddhi.query.api.expression.constant.BoolConstant) Constant(org.wso2.siddhi.query.api.expression.constant.Constant) LongConstant(org.wso2.siddhi.query.api.expression.constant.LongConstant) FloatConstant(org.wso2.siddhi.query.api.expression.constant.FloatConstant) StringConstant(org.wso2.siddhi.query.api.expression.constant.StringConstant) DoubleConstant(org.wso2.siddhi.query.api.expression.constant.DoubleConstant) TimeConstant(org.wso2.siddhi.query.api.expression.constant.TimeConstant) BoolConstant(org.wso2.siddhi.query.api.expression.constant.BoolConstant) IntConstant(org.wso2.siddhi.query.api.expression.constant.IntConstant) FloatConstant(org.wso2.siddhi.query.api.expression.constant.FloatConstant) IntConstant(org.wso2.siddhi.query.api.expression.constant.IntConstant) StringConstant(org.wso2.siddhi.query.api.expression.constant.StringConstant) TimeConstant(org.wso2.siddhi.query.api.expression.constant.TimeConstant)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)10 Test (org.testng.annotations.Test)9 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)8 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)7 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)7 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)5 ArrayList (java.util.ArrayList)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)4 PackageNode (org.ballerinalang.model.tree.PackageNode)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)4 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)4 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)3 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)3 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)3 Variable (org.wso2.siddhi.query.api.expression.Variable)3 BoolConstant (org.wso2.siddhi.query.api.expression.constant.BoolConstant)3 Constant (org.wso2.siddhi.query.api.expression.constant.Constant)3 DoubleConstant (org.wso2.siddhi.query.api.expression.constant.DoubleConstant)3