Search in sources :

Example 11 with Variable

use of io.siddhi.query.api.expression.Variable in project siddhi by wso2.

the class TestStoreContainingInMemoryTable method update.

@Override
protected void update(CompiledCondition updateCondition, List<Map<String, Object>> updateConditionParameterMaps, Map<String, CompiledExpression> updateSetExpressions, List<Map<String, Object>> updateSetParameterMaps) throws ConnectionUnavailableException {
    MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
    tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
    TableDefinition matchingTableDefinition = TableDefinition.id("");
    for (Attribute attribute : inMemoryTable.getTableDefinition().getAttributeList()) {
        tableMetaStreamEvent.addOutputData(attribute);
        matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, inMemoryTable.getTableDefinition(), 0);
    UpdateSet updateSet = new UpdateSet();
    for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
        updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
    }
    CompiledUpdateSet compiledUpdateSet = inMemoryTable.compileUpdateSet(updateSet, matchingMetaInfoHolder, null, tableMap, null);
    inMemoryTable.update(convForUpdate(updateSetParameterMaps), updateCondition, compiledUpdateSet);
}
Also used : Variable(io.siddhi.query.api.expression.Variable) Attribute(io.siddhi.query.api.definition.Attribute) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) TableDefinition(io.siddhi.query.api.definition.TableDefinition) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet) UpdateSet(io.siddhi.query.api.execution.query.output.stream.UpdateSet) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet)

Example 12 with Variable

use of io.siddhi.query.api.expression.Variable in project siddhi by wso2.

the class TestStoreContainingInMemoryTable method updateOrAdd.

@Override
protected void updateOrAdd(CompiledCondition updateCondition, List<Map<String, Object>> updateConditionParameterMaps, Map<String, CompiledExpression> updateSetExpressions, List<Map<String, Object>> updateSetParameterMaps, List<Object[]> addingRecords) throws ConnectionUnavailableException {
    MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
    tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
    TableDefinition matchingTableDefinition = TableDefinition.id("");
    for (Attribute attribute : inMemoryTable.getTableDefinition().getAttributeList()) {
        tableMetaStreamEvent.addOutputData(attribute);
        matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, inMemoryTable.getTableDefinition(), 0);
    UpdateSet updateSet = new UpdateSet();
    for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
        updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
    }
    CompiledUpdateSet compiledUpdateSet = inMemoryTable.compileUpdateSet(updateSet, matchingMetaInfoHolder, null, tableMap, null);
    inMemoryTable.updateOrAdd(convForUpdate(updateSetParameterMaps), updateCondition, compiledUpdateSet, new AddingStreamEventExtractor(matchingMetaInfoHolder.getMatchingStreamEventIndex()));
}
Also used : Variable(io.siddhi.query.api.expression.Variable) AddingStreamEventExtractor(io.siddhi.core.util.collection.AddingStreamEventExtractor) Attribute(io.siddhi.query.api.definition.Attribute) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) TableDefinition(io.siddhi.query.api.definition.TableDefinition) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet) UpdateSet(io.siddhi.query.api.execution.query.output.stream.UpdateSet) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet)

Example 13 with Variable

use of io.siddhi.query.api.expression.Variable in project siddhi by wso2.

the class ExpressionBuilder method buildVariableExecutors.

private void buildVariableExecutors(Expression expression, ExpressionVisitor expressionVisitor) {
    try {
        if (expression instanceof And) {
            expressionVisitor.beginVisitAnd();
            expressionVisitor.beginVisitAndLeftOperand();
            buildVariableExecutors(((And) expression).getLeftExpression(), expressionVisitor);
            expressionVisitor.endVisitAndLeftOperand();
            expressionVisitor.beginVisitAndRightOperand();
            buildVariableExecutors(((And) expression).getRightExpression(), expressionVisitor);
            expressionVisitor.endVisitAndRightOperand();
            expressionVisitor.endVisitAnd();
        } else if (expression instanceof Or) {
            expressionVisitor.beginVisitOr();
            expressionVisitor.beginVisitOrLeftOperand();
            buildVariableExecutors(((Or) expression).getLeftExpression(), expressionVisitor);
            expressionVisitor.endVisitOrLeftOperand();
            expressionVisitor.beginVisitOrRightOperand();
            buildVariableExecutors(((Or) expression).getRightExpression(), expressionVisitor);
            expressionVisitor.endVisitOrRightOperand();
            expressionVisitor.endVisitOr();
        } else if (expression instanceof Not) {
            expressionVisitor.beginVisitNot();
            buildVariableExecutors(((Not) expression).getExpression(), expressionVisitor);
            expressionVisitor.endVisitNot();
        } else if (expression instanceof Compare) {
            expressionVisitor.beginVisitCompare(((Compare) expression).getOperator());
            expressionVisitor.beginVisitCompareLeftOperand(((Compare) expression).getOperator());
            buildVariableExecutors(((Compare) expression).getLeftExpression(), expressionVisitor);
            expressionVisitor.endVisitCompareLeftOperand(((Compare) expression).getOperator());
            expressionVisitor.beginVisitCompareRightOperand(((Compare) expression).getOperator());
            buildVariableExecutors(((Compare) expression).getRightExpression(), expressionVisitor);
            expressionVisitor.endVisitCompareRightOperand(((Compare) expression).getOperator());
            expressionVisitor.endVisitCompare(((Compare) expression).getOperator());
        } else if (expression instanceof Add) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.ADD);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.ADD);
            buildVariableExecutors(((Add) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.ADD);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.ADD);
            buildVariableExecutors(((Add) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.ADD);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.ADD);
        } else if (expression instanceof Subtract) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.SUBTRACT);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            buildVariableExecutors(((Subtract) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            buildVariableExecutors(((Subtract) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.SUBTRACT);
        } else if (expression instanceof Divide) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.DIVIDE);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.DIVIDE);
            buildVariableExecutors(((Divide) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.DIVIDE);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.DIVIDE);
            buildVariableExecutors(((Divide) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.DIVIDE);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.DIVIDE);
        } else if (expression instanceof Multiply) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.MULTIPLY);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            buildVariableExecutors(((Multiply) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            buildVariableExecutors(((Multiply) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.MULTIPLY);
        } else if (expression instanceof Mod) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.MOD);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.MOD);
            buildVariableExecutors(((Mod) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.MOD);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.MOD);
            buildVariableExecutors(((Mod) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.MOD);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.MOD);
        } else if (expression instanceof IsNull) {
            IsNull isNull = (IsNull) expression;
            if (isNull.getExpression() != null) {
                expressionVisitor.beginVisitIsNull(null);
                buildVariableExecutors(((IsNull) expression).getExpression(), expressionVisitor);
                expressionVisitor.endVisitIsNull(null);
            } else {
                String streamId = isNull.getStreamId();
                MetaStateEvent metaStateEvent = matchingMetaInfoHolder.getMetaStateEvent();
                if (streamId == null) {
                    throw new SiddhiAppCreationException("IsNull does not support streamId being null");
                } else {
                    AbstractDefinition definitionOutput = null;
                    MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
                    for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
                        MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                        AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
                        if (metaStreamEvent.getInputReferenceId() == null) {
                            if (definition.getId().equals(streamId)) {
                                definitionOutput = definition;
                                break;
                            }
                        } else {
                            if (metaStreamEvent.getInputReferenceId().equals(streamId)) {
                                definitionOutput = definition;
                                break;
                            }
                        }
                    }
                    if (definitionOutput != null) {
                        expressionVisitor.beginVisitIsNull(definitionOutput.getId());
                        expressionVisitor.endVisitIsNull(definitionOutput.getId());
                    } else {
                        expressionVisitor.beginVisitIsNull(null);
                        expressionVisitor.endVisitIsNull(null);
                    }
                }
            }
        } else if (expression instanceof In) {
            expressionVisitor.beginVisitIn(((In) expression).getSourceId());
            buildVariableExecutors(((In) expression).getExpression(), expressionVisitor);
            expressionVisitor.endVisitIn(((In) expression).getSourceId());
        } else if (expression instanceof Constant) {
            if (expression instanceof DoubleConstant) {
                expressionVisitor.beginVisitConstant(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
                expressionVisitor.endVisitConstant(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
            } else if (expression instanceof StringConstant) {
                expressionVisitor.beginVisitConstant(((StringConstant) expression).getValue(), Attribute.Type.STRING);
                expressionVisitor.endVisitConstant(((StringConstant) expression).getValue(), Attribute.Type.STRING);
            } else if (expression instanceof IntConstant) {
                expressionVisitor.beginVisitConstant(((IntConstant) expression).getValue(), Attribute.Type.INT);
                expressionVisitor.endVisitConstant(((IntConstant) expression).getValue(), Attribute.Type.INT);
            } else if (expression instanceof BoolConstant) {
                expressionVisitor.beginVisitConstant(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
                expressionVisitor.endVisitConstant(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
            } else if (expression instanceof FloatConstant) {
                expressionVisitor.beginVisitConstant(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
                expressionVisitor.endVisitConstant(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
            } else if (expression instanceof LongConstant) {
                expressionVisitor.beginVisitConstant(((LongConstant) expression).getValue(), Attribute.Type.LONG);
                expressionVisitor.endVisitConstant(((LongConstant) expression).getValue(), Attribute.Type.LONG);
            } else {
                throw new OperationNotSupportedException("No constant exist with type " + expression.getClass().getName());
            }
        } else if (expression instanceof AttributeFunction) {
            expressionVisitor.beginVisitAttributeFunction(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
            Expression[] expressions = ((AttributeFunction) expression).getParameters();
            if (expressions != null) {
                for (int i = 0; i < expressions.length; i++) {
                    expressionVisitor.beginVisitParameterAttributeFunction(i);
                    buildVariableExecutors(expressions[i], expressionVisitor);
                    expressionVisitor.endVisitParameterAttributeFunction(i);
                }
            }
            expressionVisitor.endVisitAttributeFunction(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
        } else if (expression instanceof Variable) {
            Variable variable = ((Variable) expression);
            String attributeName = variable.getAttributeName();
            AbstractDefinition definition;
            Attribute.Type type = null;
            int streamEventChainIndex = matchingMetaInfoHolder.getCurrentState();
            if (variable.getStreamId() == null) {
                MetaStreamEvent[] metaStreamEvents = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents();
                if (streamEventChainIndex == UNKNOWN_STATE) {
                    String firstInput = null;
                    for (int i = 0; i < metaStreamEvents.length; i++) {
                        MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                        definition = metaStreamEvent.getLastInputDefinition();
                        if (type == null) {
                            try {
                                type = definition.getAttributeType(attributeName);
                                firstInput = "Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId();
                                streamEventChainIndex = i;
                            } catch (AttributeNotExistException e) {
                            // do nothing
                            }
                        } else {
                            try {
                                definition.getAttributeType(attributeName);
                                throw new SiddhiAppValidationException(firstInput + " and Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId() + " contains attribute " + "with same" + " name '" + attributeName + "'");
                            } catch (AttributeNotExistException e) {
                            // do nothing as its expected
                            }
                        }
                    }
                    if (streamEventChainIndex != UNKNOWN_STATE) {
                        if (matchingMetaInfoHolder.getMatchingStreamEventIndex() == streamEventChainIndex) {
                            buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
                        } else {
                            buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                        }
                    } else {
                        // Having state : i.e attribute is in the select clause
                        definition = matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition();
                        try {
                            type = definition.getAttributeType(attributeName);
                            buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                        } catch (AttributeNotExistException e) {
                        // do nothing as its not expected
                        }
                    }
                } else {
                    MetaStreamEvent metaStreamEvent = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvent(matchingMetaInfoHolder.getCurrentState());
                    definition = metaStreamEvent.getLastInputDefinition();
                    try {
                        type = definition.getAttributeType(attributeName);
                    } catch (AttributeNotExistException e) {
                        // Having state : i.e attribute is in the select clause
                        definition = matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition();
                        try {
                            type = definition.getAttributeType(attributeName);
                            buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                        } catch (AttributeNotExistException e1) {
                            throw new SiddhiAppValidationException(e1.getMessageWithOutContext() + " Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId(), e1.getQueryContextStartIndex(), e1.getQueryContextEndIndex(), siddhiQueryContext.getSiddhiAppContext().getName(), siddhiQueryContext.getSiddhiAppContext().getSiddhiAppString());
                        }
                    }
                    if (matchingMetaInfoHolder.getCurrentState() == matchingMetaInfoHolder.getMatchingStreamEventIndex()) {
                        buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
                    } else {
                        buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                    }
                }
            } else {
                MetaStreamEvent[] metaStreamEvents = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents();
                for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
                    MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                    definition = metaStreamEvent.getLastInputDefinition();
                    if (metaStreamEvent.getInputReferenceId() == null) {
                        if (definition.getId().equals(variable.getStreamId())) {
                            type = definition.getAttributeType(attributeName);
                            streamEventChainIndex = i;
                            break;
                        }
                    } else {
                        if (metaStreamEvent.getInputReferenceId().equals(variable.getStreamId())) {
                            type = definition.getAttributeType(attributeName);
                            streamEventChainIndex = i;
                            break;
                        }
                    }
                }
                if (matchingMetaInfoHolder.getMatchingStreamEventIndex() == streamEventChainIndex) {
                    buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
                } else {
                    buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                }
            }
        }
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, expression, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext);
        throw t;
    }
}
Also used : Add(io.siddhi.query.api.expression.math.Add) DoubleConstant(io.siddhi.query.api.expression.constant.DoubleConstant) Or(io.siddhi.query.api.expression.condition.Or) Variable(io.siddhi.query.api.expression.Variable) In(io.siddhi.query.api.expression.condition.In) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) DoubleConstant(io.siddhi.query.api.expression.constant.DoubleConstant) FloatConstant(io.siddhi.query.api.expression.constant.FloatConstant) LongConstant(io.siddhi.query.api.expression.constant.LongConstant) IntConstant(io.siddhi.query.api.expression.constant.IntConstant) Constant(io.siddhi.query.api.expression.constant.Constant) BoolConstant(io.siddhi.query.api.expression.constant.BoolConstant) FloatConstant(io.siddhi.query.api.expression.constant.FloatConstant) Divide(io.siddhi.query.api.expression.math.Divide) AttributeNotExistException(io.siddhi.query.api.exception.AttributeNotExistException) Multiply(io.siddhi.query.api.expression.math.Multiply) IntConstant(io.siddhi.query.api.expression.constant.IntConstant) Compare(io.siddhi.query.api.expression.condition.Compare) LongConstant(io.siddhi.query.api.expression.constant.LongConstant) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) BoolConstant(io.siddhi.query.api.expression.constant.BoolConstant) Mod(io.siddhi.query.api.expression.math.Mod) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) AttributeFunction(io.siddhi.query.api.expression.AttributeFunction) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) Not(io.siddhi.query.api.expression.condition.Not) Expression(io.siddhi.query.api.expression.Expression) And(io.siddhi.query.api.expression.condition.And) Subtract(io.siddhi.query.api.expression.math.Subtract) IsNull(io.siddhi.query.api.expression.condition.IsNull) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 14 with Variable

use of io.siddhi.query.api.expression.Variable in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitDefinition_aggregation.

@Override
public AggregationDefinition visitDefinition_aggregation(@NotNull SiddhiQLParser.Definition_aggregationContext ctx) {
    // Read the name of the aggregation
    String aggregationName = (String) visitAggregation_name(ctx.aggregation_name());
    // Create the aggregation using the extracted aggregation name
    AggregationDefinition aggregationDefinition = AggregationDefinition.id(aggregationName);
    // Get all annotation and populate the aggregation
    for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
        aggregationDefinition.annotation((Annotation) visit(annotationContext));
    }
    // Attach the input stream
    BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.standard_stream());
    aggregationDefinition.from(basicSingleInputStream);
    // Extract the selector and attach it to the new aggregation
    BasicSelector selector = (BasicSelector) visit(ctx.group_by_query_selection());
    aggregationDefinition.select(selector);
    // Get the variable (if available) and aggregate on that variable
    if (ctx.attribute_reference() != null) {
        Variable aggregatedBy = (Variable) visit(ctx.attribute_reference());
        aggregationDefinition.aggregateBy(aggregatedBy);
    }
    // Extract the specified time-durations and attache it to the aggregation definition
    TimePeriod timePeriod = (TimePeriod) visit(ctx.aggregation_time());
    aggregationDefinition.every(timePeriod);
    populateQueryContext(aggregationDefinition, ctx);
    return aggregationDefinition;
}
Also used : SiddhiQLParser(io.siddhi.query.compiler.SiddhiQLParser) Variable(io.siddhi.query.api.expression.Variable) AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) TimePeriod(io.siddhi.query.api.aggregation.TimePeriod) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) BasicSelector(io.siddhi.query.api.execution.query.selection.BasicSelector)

Example 15 with Variable

use of io.siddhi.query.api.expression.Variable 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()));
    }
    if (ctx.offset() != null) {
        selector.offset((Constant) visit(ctx.offset()));
    }
    populateQueryContext(selector, ctx);
    return selector;
}
Also used : SiddhiQLParser(io.siddhi.query.compiler.SiddhiQLParser) Variable(io.siddhi.query.api.expression.Variable) ArrayList(java.util.ArrayList) OrderByAttribute(io.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) BasicSelector(io.siddhi.query.api.execution.query.selection.BasicSelector) Selector(io.siddhi.query.api.execution.query.selection.Selector)

Aggregations

Variable (io.siddhi.query.api.expression.Variable)30 Attribute (io.siddhi.query.api.definition.Attribute)18 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)15 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)14 Expression (io.siddhi.query.api.expression.Expression)14 ArrayList (java.util.ArrayList)14 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)13 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)11 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)10 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)9 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)8 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)8 Table (io.siddhi.core.table.Table)7 AttributeFunction (io.siddhi.query.api.expression.AttributeFunction)7 Compare (io.siddhi.query.api.expression.condition.Compare)7 TableDefinition (io.siddhi.query.api.definition.TableDefinition)6 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)4 MetaStateEventAttribute (io.siddhi.core.event.state.MetaStateEventAttribute)4 ConditionExpressionExecutor (io.siddhi.core.executor.condition.ConditionExpressionExecutor)4