Java Code Examples for io.siddhi.query.api.expression.Expression#variable()

The following examples show how to use io.siddhi.query.api.expression.Expression#variable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaxIncrementalAttributeAggregator.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public void init(String attributeName, Attribute.Type attributeType) {

    if (attributeName == null) {
        throw new SiddhiAppCreationException("Max incremental attribute aggregation cannot be executed " +
                "when no parameters are given");
    }

    if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG) ||
            attributeType.equals(Attribute.Type.DOUBLE) || attributeType.equals(Attribute.Type.FLOAT)) {
        this.baseAttributes = new Attribute[]{new Attribute("AGG_MAX_".concat(attributeName), attributeType)};
        this.baseAttributesInitialValues = new Expression[]{Expression.variable(attributeName)};
        this.returnType = attributeType;
    } else {
        throw new SiddhiAppRuntimeException(
                "Max aggregation cannot be executed on attribute type " + attributeType.toString());
    }
}
 
Example 2
Source File: MinIncrementalAttributeAggregator.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public void init(String attributeName, Attribute.Type attributeType) {

    if (attributeName == null) {
        throw new SiddhiAppCreationException("Min incremental attribute aggregation cannot be executed " +
                "when no parameters are given");
    }

    if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG) ||
            attributeType.equals(Attribute.Type.DOUBLE) || attributeType.equals(Attribute.Type.FLOAT)) {
        this.baseAttributes = new Attribute[]{new Attribute("AGG_MIN_".concat(attributeName), attributeType)};
        this.baseAttributesInitialValues = new Expression[]{Expression.variable(attributeName)};
        this.returnType = attributeType;
    } else {
        throw new SiddhiAppRuntimeException(
                "Min aggregation cannot be executed on attribute type " + attributeType.toString());
    }
}
 
Example 3
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     * <p>The default implementation returns the result of calling
     * {@link #visitChildren} on {@code ctx}.</p>
     *
     * @param ctx
     */
    @Override
    public Variable visitAttribute_reference(@NotNull SiddhiQLParser.Attribute_referenceContext ctx) {

//        attribute_reference
//        : hash1='#'? name1=name ('['attribute_index1=attribute_index']')? (hash2='#' name2=name
// ('['attribute_index2=attribute_index']')?)? '.'  attribute_name
//        | attribute_name
//        ;

        Variable variable = Expression.variable((String) visit(ctx.attribute_name()));

        if (ctx.name1 != null && ctx.name2 != null) { //Stream and Function
            variable.setStreamId(ctx.hash1 != null, ctx.not != null,
                    (String) visit(ctx.name1));
            if (ctx.attribute_index1 != null) {
                variable.setStreamIndex((Integer) visit(ctx.attribute_index1));
            }

            variable.setFunctionId((String) visit(ctx.name2));
            if (ctx.attribute_index2 != null) {
                variable.setFunctionIndex((Integer) visit(ctx.attribute_index2));
            }
        } else if (ctx.name1 != null) {   //name2 == null
            if (ctx.hash1 == null) {   //Stream
                variable.setStreamId(false, ctx.not != null, (String) visit(ctx.name1));
                if (ctx.attribute_index1 != null) {
                    variable.setStreamIndex((Integer) visit(ctx.attribute_index1));
                }
            } else {  //InnerStream or Function
                String name = (String) visit(ctx.name1);

                if (ctx.not != null) {
                    throw newSiddhiParserException(ctx, "Found '" + ctx.getText() + "', but only inner or fault " +
                            "can be supported at one!");
                }
                if (activeStreams.contains(SiddhiConstants.INNER_STREAM_FLAG + name)) { //InnerStream
                    variable.setStreamId(true, name);
                    if (ctx.attribute_index1 != null) {
                        variable.setStreamIndex((Integer) visit(ctx.attribute_index1));
                    }

                } else { //Function
                    variable.setFunctionId(name);
                    if (ctx.attribute_index1 != null) {
                        variable.setFunctionIndex((Integer) visit(ctx.attribute_index1));
                    }
                }
            }
        }
        populateQueryContext(variable, ctx);
        return variable;
    }
 
Example 4
Source File: CountIncrementalAttributeAggregator.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Override
public Expression aggregate() {
    return Expression.variable(baseAttributes[0].getName());
}
 
Example 5
Source File: SumIncrementalAttributeAggregator.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Override
public Expression aggregate() {
    return Expression.variable(baseAttributes[0].getName());
}
 
Example 6
Source File: MaxIncrementalAttributeAggregator.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Override
public Expression aggregate() {
    return Expression.variable(baseAttributes[0].getName());
}
 
Example 7
Source File: MinIncrementalAttributeAggregator.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Override
public Expression aggregate() {
    return Expression.variable(baseAttributes[0].getName());
}