Search in sources :

Example 6 with AttributeProcessor

use of io.siddhi.core.query.selector.attribute.processor.AttributeProcessor in project siddhi by wso2.

the class SelectorParser method parse.

/**
 * Parse Selector portion of a query and return corresponding QuerySelector.
 *
 * @param selector                    selector to be parsed
 * @param outputStream                output stream
 * @param metaComplexEvent            Meta event used to collect execution info of stream associated with query
 * @param tableMap                    Table Map
 * @param variableExpressionExecutors variable expression executors
 * @param metaPosition                helps to identify the meta position of aggregates
 * @param processingMode              processing mode of the query
 * @param outputExpectsExpiredEvents  is expired events sent as output
 * @param siddhiQueryContext          current siddhi query context
 * @return QuerySelector
 */
public static QuerySelector parse(Selector selector, OutputStream outputStream, MetaComplexEvent metaComplexEvent, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, int metaPosition, ProcessingMode processingMode, boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
    boolean currentOn = false;
    boolean expiredOn = false;
    String id = null;
    if (outputStream.getOutputEventType() == OutputStream.OutputEventType.CURRENT_EVENTS || outputStream.getOutputEventType() == OutputStream.OutputEventType.ALL_EVENTS) {
        currentOn = true;
    }
    if (outputStream.getOutputEventType() == OutputStream.OutputEventType.EXPIRED_EVENTS || outputStream.getOutputEventType() == OutputStream.OutputEventType.ALL_EVENTS) {
        expiredOn = true;
    }
    boolean groupBy = !selector.getGroupByList().isEmpty();
    id = outputStream.getId();
    containsAggregatorThreadLocal.remove();
    QuerySelector querySelector = new QuerySelector(id, selector, currentOn, expiredOn, siddhiQueryContext);
    List<AttributeProcessor> attributeProcessors = getAttributeProcessors(selector, id, metaComplexEvent, tableMap, variableExpressionExecutors, outputStream, metaPosition, processingMode, outputExpectsExpiredEvents, groupBy, siddhiQueryContext);
    querySelector.setAttributeProcessorList(attributeProcessors, "true".equals(containsAggregatorThreadLocal.get()));
    containsAggregatorThreadLocal.remove();
    ConditionExpressionExecutor havingCondition = generateHavingExecutor(selector.getHavingExpression(), metaComplexEvent, tableMap, variableExpressionExecutors, siddhiQueryContext);
    querySelector.setHavingConditionExecutor(havingCondition, "true".equals(containsAggregatorThreadLocal.get()));
    containsAggregatorThreadLocal.remove();
    if (!selector.getGroupByList().isEmpty()) {
        List<Expression> groupByExpressionList = selector.getGroupByList().stream().map(groupByVariable -> (Expression) groupByVariable).collect(Collectors.toList());
        querySelector.setGroupByKeyGenerator(new GroupByKeyGenerator(groupByExpressionList, metaComplexEvent, SiddhiConstants.UNKNOWN_STATE, null, variableExpressionExecutors, siddhiQueryContext));
    }
    if (!selector.getOrderByList().isEmpty()) {
        querySelector.setOrderByEventComparator(new OrderByEventComparator(selector.getOrderByList(), metaComplexEvent, SiddhiConstants.HAVING_STATE, null, variableExpressionExecutors, siddhiQueryContext));
    }
    if (selector.getLimit() != null) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression((Expression) selector.getLimit(), metaComplexEvent, SiddhiConstants.HAVING_STATE, tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        containsAggregatorThreadLocal.remove();
        querySelector.setLimit(((Number) (((ConstantExpressionExecutor) expressionExecutor).getValue())).longValue());
    }
    if (selector.getOffset() != null) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression((Expression) selector.getOffset(), metaComplexEvent, SiddhiConstants.HAVING_STATE, tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        containsAggregatorThreadLocal.remove();
        querySelector.setOffset(((Number) (((ConstantExpressionExecutor) expressionExecutor).getValue())).longValue());
    }
    return querySelector;
}
Also used : Selector(io.siddhi.query.api.execution.query.selection.Selector) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) GroupByKeyGenerator(io.siddhi.core.query.selector.GroupByKeyGenerator) Variable(io.siddhi.query.api.expression.Variable) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) SiddhiConstants(io.siddhi.core.util.SiddhiConstants) QuerySelector(io.siddhi.core.query.selector.QuerySelector) Expression(io.siddhi.query.api.expression.Expression) ArrayList(java.util.ArrayList) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor) Table(io.siddhi.core.table.Table) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaComplexEvent(io.siddhi.core.event.MetaComplexEvent) MetaStateEventAttribute(io.siddhi.core.event.state.MetaStateEventAttribute) Map(java.util.Map) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) ProcessingMode(io.siddhi.core.query.processor.ProcessingMode) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) OrderByEventComparator(io.siddhi.core.query.selector.OrderByEventComparator) ConditionExpressionExecutor(io.siddhi.core.executor.condition.ConditionExpressionExecutor) Attribute(io.siddhi.query.api.definition.Attribute) DuplicateAttributeException(io.siddhi.query.api.exception.DuplicateAttributeException) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) Collectors(java.util.stream.Collectors) List(java.util.List) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) ConditionExpressionExecutor(io.siddhi.core.executor.condition.ConditionExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) Expression(io.siddhi.query.api.expression.Expression) GroupByKeyGenerator(io.siddhi.core.query.selector.GroupByKeyGenerator) QuerySelector(io.siddhi.core.query.selector.QuerySelector) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor) ConditionExpressionExecutor(io.siddhi.core.executor.condition.ConditionExpressionExecutor) OrderByEventComparator(io.siddhi.core.query.selector.OrderByEventComparator)

Example 7 with AttributeProcessor

use of io.siddhi.core.query.selector.attribute.processor.AttributeProcessor in project siddhi by wso2.

the class QuerySelector method processInBatchNoGroupBy.

private ComplexEventChunk processInBatchNoGroupBy(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ComplexEvent lastEvent = null;
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            switch(event.getType()) {
                case CURRENT:
                case EXPIRED:
                    eventPopulator.populateStateEvent(event);
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
                        if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                            complexEventChunk.remove();
                            lastEvent = event;
                        }
                    }
                    break;
                case TIMER:
                    break;
                case RESET:
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    break;
            }
        }
    }
    if (lastEvent != null) {
        complexEventChunk.clear();
        if ((offset == SiddhiConstants.UNKNOWN_STATE || offset == 0) && (limit == SiddhiConstants.UNKNOWN_STATE || limit > 0)) {
            complexEventChunk.add(lastEvent);
        }
        return complexEventChunk;
    }
    return null;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)

Aggregations

AttributeProcessor (io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)7 ComplexEvent (io.siddhi.core.event.ComplexEvent)4 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)4 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)3 MetaStateEventAttribute (io.siddhi.core.event.state.MetaStateEventAttribute)2 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)2 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)2 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)2 ConditionExpressionExecutor (io.siddhi.core.executor.condition.ConditionExpressionExecutor)2 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)2 Attribute (io.siddhi.query.api.definition.Attribute)2 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)2 DuplicateAttributeException (io.siddhi.query.api.exception.DuplicateAttributeException)2 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)2 Variable (io.siddhi.query.api.expression.Variable)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)1 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)1