Search in sources :

Example 1 with ConditionExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor in project ballerina by ballerina-lang.

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 siddhiAppContext            query to be parsed
 * @param metaComplexEvent            Meta event used to collect execution info of stream associated with query
 * @param tableMap                    Table Map
 * @param variableExpressionExecutors variable expression executors
 * @param queryName                   query name of selector belongs to.
 * @param metaPosition                helps to identify the meta position of aggregates
 * @return QuerySelector
 */
public static QuerySelector parse(Selector selector, OutputStream outputStream, SiddhiAppContext siddhiAppContext, MetaComplexEvent metaComplexEvent, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, String queryName, int metaPosition) {
    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;
    }
    id = outputStream.getId();
    containsAggregatorThreadLocal.remove();
    QuerySelector querySelector = new QuerySelector(id, selector, currentOn, expiredOn, siddhiAppContext);
    List<AttributeProcessor> attributeProcessors = getAttributeProcessors(selector, id, siddhiAppContext, metaComplexEvent, tableMap, variableExpressionExecutors, outputStream, queryName, metaPosition);
    querySelector.setAttributeProcessorList(attributeProcessors, "true".equals(containsAggregatorThreadLocal.get()));
    containsAggregatorThreadLocal.remove();
    ConditionExpressionExecutor havingCondition = generateHavingExecutor(selector.getHavingExpression(), metaComplexEvent, siddhiAppContext, tableMap, variableExpressionExecutors, queryName);
    querySelector.setHavingConditionExecutor(havingCondition, "true".equals(containsAggregatorThreadLocal.get()));
    containsAggregatorThreadLocal.remove();
    if (!selector.getGroupByList().isEmpty()) {
        querySelector.setGroupByKeyGenerator(new GroupByKeyGenerator(selector.getGroupByList(), metaComplexEvent, SiddhiConstants.UNKNOWN_STATE, null, variableExpressionExecutors, siddhiAppContext, queryName));
    }
    if (!selector.getOrderByList().isEmpty()) {
        querySelector.setOrderByEventComparator(new OrderByEventComparator(selector.getOrderByList(), metaComplexEvent, SiddhiConstants.HAVING_STATE, null, variableExpressionExecutors, siddhiAppContext, queryName));
    }
    if (selector.getLimit() != null) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression((Expression) selector.getLimit(), metaComplexEvent, SiddhiConstants.HAVING_STATE, tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        containsAggregatorThreadLocal.remove();
        querySelector.setLimit(((Number) (((ConstantExpressionExecutor) expressionExecutor).getValue())).longValue());
    }
    return querySelector;
}
Also used : ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) GroupByKeyGenerator(org.ballerinalang.siddhi.core.query.selector.GroupByKeyGenerator) QuerySelector(org.ballerinalang.siddhi.core.query.selector.QuerySelector) AttributeProcessor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) OrderByEventComparator(org.ballerinalang.siddhi.core.query.selector.OrderByEventComparator)

Example 2 with ConditionExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor in project ballerina by ballerina-lang.

the class StreamPartitioner method createSingleInputStreamExecutors.

private void createSingleInputStreamExecutors(SingleInputStream inputStream, Partition partition, MetaStreamEvent metaEvent, List<VariableExpressionExecutor> executors, Map<String, Table> tableMap, SiddhiAppContext siddhiAppContext, String queryName) {
    List<PartitionExecutor> executorList = new ArrayList<PartitionExecutor>();
    partitionExecutorLists.add(executorList);
    if (!inputStream.isInnerStream()) {
        for (PartitionType partitionType : partition.getPartitionTypeMap().values()) {
            if (partitionType instanceof ValuePartitionType) {
                if (partitionType.getStreamId().equals(inputStream.getStreamId())) {
                    executorList.add(new ValuePartitionExecutor(ExpressionParser.parseExpression(((ValuePartitionType) partitionType).getExpression(), metaEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, executors, siddhiAppContext, false, 0, queryName)));
                }
            } else {
                for (RangePartitionType.RangePartitionProperty rangePartitionProperty : ((RangePartitionType) partitionType).getRangePartitionProperties()) {
                    if (partitionType.getStreamId().equals(inputStream.getStreamId())) {
                        executorList.add(new RangePartitionExecutor((ConditionExpressionExecutor) ExpressionParser.parseExpression(rangePartitionProperty.getCondition(), metaEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, executors, siddhiAppContext, false, 0, queryName), rangePartitionProperty.getPartitionKey()));
                    }
                }
            }
        }
    }
}
Also used : ValuePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.ValuePartitionExecutor) RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.ValuePartitionExecutor) RangePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.RangePartitionExecutor) PartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor) ArrayList(java.util.ArrayList) RangePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.RangePartitionExecutor) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)

Aggregations

ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)2 ArrayList (java.util.ArrayList)1 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)1 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)1 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)1 PartitionExecutor (org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor)1 RangePartitionExecutor (org.ballerinalang.siddhi.core.partition.executor.RangePartitionExecutor)1 ValuePartitionExecutor (org.ballerinalang.siddhi.core.partition.executor.ValuePartitionExecutor)1 GroupByKeyGenerator (org.ballerinalang.siddhi.core.query.selector.GroupByKeyGenerator)1 OrderByEventComparator (org.ballerinalang.siddhi.core.query.selector.OrderByEventComparator)1 QuerySelector (org.ballerinalang.siddhi.core.query.selector.QuerySelector)1 AttributeProcessor (org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor)1 PartitionType (org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType)1