Search in sources :

Example 1 with ConfigReader

use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.

the class ExpressionParser method parseExpression.

/**
 * Parse the given expression and create the appropriate Executor by recursively traversing the expression
 *
 * @param expression              Expression to be parsed
 * @param metaEvent               Meta Event
 * @param currentState            Current state number
 * @param tableMap                Event Table Map
 * @param executorList            List to hold VariableExpressionExecutors to update after query parsing @return
 * @param siddhiAppContext        SiddhiAppContext
 * @param groupBy                 is for groupBy expression
 * @param defaultStreamEventIndex Default StreamEvent Index
 * @param queryName               query name of expression belongs to.
 * @return ExpressionExecutor
 */
public static ExpressionExecutor parseExpression(Expression expression, MetaComplexEvent metaEvent, int currentState, Map<String, Table> tableMap, List<VariableExpressionExecutor> executorList, SiddhiAppContext siddhiAppContext, boolean groupBy, int defaultStreamEventIndex, String queryName) {
    try {
        if (expression instanceof And) {
            return new AndConditionExpressionExecutor(parseExpression(((And) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((And) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
        } else if (expression instanceof Or) {
            return new OrConditionExpressionExecutor(parseExpression(((Or) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Or) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
        } else if (expression instanceof Not) {
            return new NotConditionExpressionExecutor(parseExpression(((Not) expression).getExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
        } else if (expression instanceof Compare) {
            if (((Compare) expression).getOperator() == Compare.Operator.EQUAL) {
                return parseEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
            } else if (((Compare) expression).getOperator() == Compare.Operator.NOT_EQUAL) {
                return parseNotEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
            } else if (((Compare) expression).getOperator() == Compare.Operator.GREATER_THAN) {
                return parseGreaterThanCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
            } else if (((Compare) expression).getOperator() == Compare.Operator.GREATER_THAN_EQUAL) {
                return parseGreaterThanEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
            } else if (((Compare) expression).getOperator() == Compare.Operator.LESS_THAN) {
                return parseLessThanCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
            } else if (((Compare) expression).getOperator() == Compare.Operator.LESS_THAN_EQUAL) {
                return parseLessThanEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
            }
        } else if (expression instanceof Constant) {
            if (expression instanceof BoolConstant) {
                return new ConstantExpressionExecutor(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
            } else if (expression instanceof StringConstant) {
                return new ConstantExpressionExecutor(((StringConstant) expression).getValue(), Attribute.Type.STRING);
            } else if (expression instanceof IntConstant) {
                return new ConstantExpressionExecutor(((IntConstant) expression).getValue(), Attribute.Type.INT);
            } else if (expression instanceof LongConstant) {
                return new ConstantExpressionExecutor(((LongConstant) expression).getValue(), Attribute.Type.LONG);
            } else if (expression instanceof FloatConstant) {
                return new ConstantExpressionExecutor(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
            } else if (expression instanceof DoubleConstant) {
                return new ConstantExpressionExecutor(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
            }
        } else if (expression instanceof Variable) {
            return parseVariable((Variable) expression, metaEvent, currentState, executorList, defaultStreamEventIndex);
        } else if (expression instanceof Multiply) {
            ExpressionExecutor left = parseExpression(((Multiply) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            ExpressionExecutor right = parseExpression(((Multiply) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            Attribute.Type type = parseArithmeticOperationResultType(left, right);
            switch(type) {
                case INT:
                    return new MultiplyExpressionExecutorInt(left, right);
                case LONG:
                    return new MultiplyExpressionExecutorLong(left, right);
                case FLOAT:
                    return new MultiplyExpressionExecutorFloat(left, right);
                case DOUBLE:
                    return new MultiplyExpressionExecutorDouble(left, right);
                // Will not happen. Handled in parseArithmeticOperationResultType()
                default:
            }
        } else if (expression instanceof Add) {
            ExpressionExecutor left = parseExpression(((Add) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            ExpressionExecutor right = parseExpression(((Add) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            Attribute.Type type = parseArithmeticOperationResultType(left, right);
            switch(type) {
                case INT:
                    return new AddExpressionExecutorInt(left, right);
                case LONG:
                    return new AddExpressionExecutorLong(left, right);
                case FLOAT:
                    return new AddExpressionExecutorFloat(left, right);
                case DOUBLE:
                    return new AddExpressionExecutorDouble(left, right);
                // Will not happen. Handled in parseArithmeticOperationResultType()
                default:
            }
        } else if (expression instanceof Subtract) {
            ExpressionExecutor left = parseExpression(((Subtract) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            ExpressionExecutor right = parseExpression(((Subtract) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            Attribute.Type type = parseArithmeticOperationResultType(left, right);
            switch(type) {
                case INT:
                    return new SubtractExpressionExecutorInt(left, right);
                case LONG:
                    return new SubtractExpressionExecutorLong(left, right);
                case FLOAT:
                    return new SubtractExpressionExecutorFloat(left, right);
                case DOUBLE:
                    return new SubtractExpressionExecutorDouble(left, right);
                // Will not happen. Handled in parseArithmeticOperationResultType()
                default:
            }
        } else if (expression instanceof Mod) {
            ExpressionExecutor left = parseExpression(((Mod) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            ExpressionExecutor right = parseExpression(((Mod) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            Attribute.Type type = parseArithmeticOperationResultType(left, right);
            switch(type) {
                case INT:
                    return new ModExpressionExecutorInt(left, right);
                case LONG:
                    return new ModExpressionExecutorLong(left, right);
                case FLOAT:
                    return new ModExpressionExecutorFloat(left, right);
                case DOUBLE:
                    return new ModExpressionExecutorDouble(left, right);
                // Will not happen. Handled in parseArithmeticOperationResultType()
                default:
            }
        } else if (expression instanceof Divide) {
            ExpressionExecutor left = parseExpression(((Divide) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            ExpressionExecutor right = parseExpression(((Divide) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            Attribute.Type type = parseArithmeticOperationResultType(left, right);
            switch(type) {
                case INT:
                    return new DivideExpressionExecutorInt(left, right);
                case LONG:
                    return new DivideExpressionExecutorLong(left, right);
                case FLOAT:
                    return new DivideExpressionExecutorFloat(left, right);
                case DOUBLE:
                    return new DivideExpressionExecutorDouble(left, right);
                // Will not happen. Handled in parseArithmeticOperationResultType()
                default:
            }
        } else if (expression instanceof AttributeFunction) {
            // extensions
            Object executor;
            try {
                if ((siddhiAppContext.isFunctionExist(((AttributeFunction) expression).getName())) && (((AttributeFunction) expression).getNamespace()).isEmpty()) {
                    executor = new ScriptFunctionExecutor(((AttributeFunction) expression).getName());
                } else {
                    executor = SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, FunctionExecutorExtensionHolder.getInstance(siddhiAppContext));
                }
            } catch (SiddhiAppCreationException ex) {
                try {
                    executor = SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, AttributeAggregatorExtensionHolder.getInstance(siddhiAppContext));
                } catch (SiddhiAppCreationException e) {
                    throw new SiddhiAppCreationException("'" + ((AttributeFunction) expression).getName() + "' is" + " neither a function extension nor an aggregated attribute extension", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
                }
            }
            ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
            if (executor instanceof FunctionExecutor) {
                FunctionExecutor expressionExecutor = (FunctionExecutor) executor;
                Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
                ExpressionExecutor[] innerExpressionExecutors = parseInnerExpression(innerExpressions, metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
                expressionExecutor.initExecutor(innerExpressionExecutors, siddhiAppContext, queryName, configReader);
                if (expressionExecutor.getReturnType() == Attribute.Type.BOOL) {
                    return new BoolConditionExpressionExecutor(expressionExecutor);
                }
                return expressionExecutor;
            } else {
                AttributeAggregator attributeAggregator = (AttributeAggregator) executor;
                Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
                ExpressionExecutor[] innerExpressionExecutors = parseInnerExpression(innerExpressions, metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
                attributeAggregator.initAggregator(innerExpressionExecutors, siddhiAppContext, configReader);
                AbstractAggregationAttributeExecutor aggregationAttributeProcessor;
                if (groupBy) {
                    aggregationAttributeProcessor = new GroupByAggregationAttributeExecutor(attributeAggregator, innerExpressionExecutors, configReader, siddhiAppContext, queryName);
                } else {
                    aggregationAttributeProcessor = new AggregationAttributeExecutor(attributeAggregator, innerExpressionExecutors, siddhiAppContext, queryName);
                }
                SelectorParser.getContainsAggregatorThreadLocal().set("true");
                return aggregationAttributeProcessor;
            }
        } else if (expression instanceof In) {
            Table table = tableMap.get(((In) expression).getSourceId());
            MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(metaEvent, defaultStreamEventIndex, table.getTableDefinition(), defaultStreamEventIndex);
            CompiledCondition compiledCondition = table.compileCondition(((In) expression).getExpression(), matchingMetaInfoHolder, siddhiAppContext, executorList, tableMap, queryName);
            return new InConditionExpressionExecutor(table, compiledCondition, matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents().length, metaEvent instanceof StateEvent, 0);
        } else if (expression instanceof IsNull) {
            IsNull isNull = (IsNull) expression;
            if (isNull.getExpression() != null) {
                ExpressionExecutor innerExpressionExecutor = parseExpression(isNull.getExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
                return new IsNullConditionExpressionExecutor(innerExpressionExecutor);
            } else {
                String streamId = isNull.getStreamId();
                Integer streamIndex = isNull.getStreamIndex();
                if (metaEvent instanceof MetaStateEvent) {
                    int[] eventPosition = new int[2];
                    if (streamIndex != null) {
                        if (streamIndex <= LAST) {
                            eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex + 1;
                        } else {
                            eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex;
                        }
                    } else {
                        eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = defaultStreamEventIndex;
                    }
                    eventPosition[STREAM_EVENT_CHAIN_INDEX] = UNKNOWN_STATE;
                    MetaStateEvent metaStateEvent = (MetaStateEvent) metaEvent;
                    if (streamId == null) {
                        throw new SiddhiAppCreationException("IsNull does not support streamId being null", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
                    } else {
                        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)) {
                                    eventPosition[STREAM_EVENT_CHAIN_INDEX] = i;
                                    break;
                                }
                            } else {
                                if (metaStreamEvent.getInputReferenceId().equals(streamId)) {
                                    eventPosition[STREAM_EVENT_CHAIN_INDEX] = i;
                                    if (currentState > -1 && metaStreamEvents[currentState].getInputReferenceId() != null && streamIndex != null && streamIndex <= LAST) {
                                        if (streamId.equals(metaStreamEvents[currentState].getInputReferenceId())) {
                                            eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    return new IsNullStreamConditionExpressionExecutor(eventPosition);
                } else {
                    return new IsNullStreamConditionExpressionExecutor(null);
                }
            }
        }
        throw new UnsupportedOperationException(expression.toString() + " not supported!");
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, expression, siddhiAppContext);
        throw t;
    }
}
Also used : Add(org.ballerinalang.siddhi.query.api.expression.math.Add) Or(org.ballerinalang.siddhi.query.api.expression.condition.Or) DivideExpressionExecutorFloat(org.ballerinalang.siddhi.core.executor.math.divide.DivideExpressionExecutorFloat) ModExpressionExecutorDouble(org.ballerinalang.siddhi.core.executor.math.mod.ModExpressionExecutorDouble) ModExpressionExecutorInt(org.ballerinalang.siddhi.core.executor.math.mod.ModExpressionExecutorInt) EqualCompareConditionExpressionExecutorStringString(org.ballerinalang.siddhi.core.executor.condition.compare.equal.EqualCompareConditionExpressionExecutorStringString) NotEqualCompareConditionExpressionExecutorStringString(org.ballerinalang.siddhi.core.executor.condition.compare.notequal.NotEqualCompareConditionExpressionExecutorStringString) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) Divide(org.ballerinalang.siddhi.query.api.expression.math.Divide) MultiplyExpressionExecutorLong(org.ballerinalang.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorLong) AddExpressionExecutorLong(org.ballerinalang.siddhi.core.executor.math.add.AddExpressionExecutorLong) Multiply(org.ballerinalang.siddhi.query.api.expression.math.Multiply) AddExpressionExecutorInt(org.ballerinalang.siddhi.core.executor.math.add.AddExpressionExecutorInt) Compare(org.ballerinalang.siddhi.query.api.expression.condition.Compare) DivideExpressionExecutorDouble(org.ballerinalang.siddhi.core.executor.math.divide.DivideExpressionExecutorDouble) ScriptFunctionExecutor(org.ballerinalang.siddhi.core.executor.function.ScriptFunctionExecutor) FunctionExecutor(org.ballerinalang.siddhi.core.executor.function.FunctionExecutor) AddExpressionExecutorFloat(org.ballerinalang.siddhi.core.executor.math.add.AddExpressionExecutorFloat) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) AttributeAggregator(org.ballerinalang.siddhi.core.query.selector.attribute.aggregator.AttributeAggregator) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) GroupByAggregationAttributeExecutor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.executor.GroupByAggregationAttributeExecutor) Not(org.ballerinalang.siddhi.query.api.expression.condition.Not) MultiplyExpressionExecutorFloat(org.ballerinalang.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorFloat) CompiledCondition(org.ballerinalang.siddhi.core.util.collection.operator.CompiledCondition) And(org.ballerinalang.siddhi.query.api.expression.condition.And) MatchingMetaInfoHolder(org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) SubtractExpressionExecutorLong(org.ballerinalang.siddhi.core.executor.math.subtract.SubtractExpressionExecutorLong) IsNullStreamConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor) Subtract(org.ballerinalang.siddhi.query.api.expression.math.Subtract) StringConstant(org.ballerinalang.siddhi.query.api.expression.constant.StringConstant) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) DoubleConstant(org.ballerinalang.siddhi.query.api.expression.constant.DoubleConstant) AbstractAggregationAttributeExecutor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.executor.AbstractAggregationAttributeExecutor) Variable(org.ballerinalang.siddhi.query.api.expression.Variable) MultiplyExpressionExecutorDouble(org.ballerinalang.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorDouble) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) In(org.ballerinalang.siddhi.query.api.expression.condition.In) FloatConstant(org.ballerinalang.siddhi.query.api.expression.constant.FloatConstant) StringConstant(org.ballerinalang.siddhi.query.api.expression.constant.StringConstant) LongConstant(org.ballerinalang.siddhi.query.api.expression.constant.LongConstant) DoubleConstant(org.ballerinalang.siddhi.query.api.expression.constant.DoubleConstant) BoolConstant(org.ballerinalang.siddhi.query.api.expression.constant.BoolConstant) IntConstant(org.ballerinalang.siddhi.query.api.expression.constant.IntConstant) Constant(org.ballerinalang.siddhi.query.api.expression.constant.Constant) ModExpressionExecutorLong(org.ballerinalang.siddhi.core.executor.math.mod.ModExpressionExecutorLong) ScriptFunctionExecutor(org.ballerinalang.siddhi.core.executor.function.ScriptFunctionExecutor) InConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.InConditionExpressionExecutor) FloatConstant(org.ballerinalang.siddhi.query.api.expression.constant.FloatConstant) AddExpressionExecutorDouble(org.ballerinalang.siddhi.core.executor.math.add.AddExpressionExecutorDouble) AndConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor) MultiplyExpressionExecutorInt(org.ballerinalang.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorInt) IsNullConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.IsNullConditionExpressionExecutor) SubtractExpressionExecutorInt(org.ballerinalang.siddhi.core.executor.math.subtract.SubtractExpressionExecutorInt) IntConstant(org.ballerinalang.siddhi.query.api.expression.constant.IntConstant) SubtractExpressionExecutorDouble(org.ballerinalang.siddhi.core.executor.math.subtract.SubtractExpressionExecutorDouble) GroupByAggregationAttributeExecutor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.executor.GroupByAggregationAttributeExecutor) AggregationAttributeExecutor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.executor.AggregationAttributeExecutor) AbstractAggregationAttributeExecutor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.executor.AbstractAggregationAttributeExecutor) LongConstant(org.ballerinalang.siddhi.query.api.expression.constant.LongConstant) BoolConstant(org.ballerinalang.siddhi.query.api.expression.constant.BoolConstant) Mod(org.ballerinalang.siddhi.query.api.expression.math.Mod) Table(org.ballerinalang.siddhi.core.table.Table) InConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.InConditionExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) NotConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.NotConditionExpressionExecutor) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) BoolConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.BoolConditionExpressionExecutor) IsNullStreamConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) OrConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.OrConditionExpressionExecutor) AndConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor) IsNullConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.IsNullConditionExpressionExecutor) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader) OrConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.OrConditionExpressionExecutor) DivideExpressionExecutorLong(org.ballerinalang.siddhi.core.executor.math.divide.DivideExpressionExecutorLong) AttributeFunction(org.ballerinalang.siddhi.query.api.expression.AttributeFunction) DivideExpressionExecutorInt(org.ballerinalang.siddhi.core.executor.math.divide.DivideExpressionExecutorInt) SubtractExpressionExecutorFloat(org.ballerinalang.siddhi.core.executor.math.subtract.SubtractExpressionExecutorFloat) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) NotConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.NotConditionExpressionExecutor) ModExpressionExecutorFloat(org.ballerinalang.siddhi.core.executor.math.mod.ModExpressionExecutorFloat) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) IsNull(org.ballerinalang.siddhi.query.api.expression.condition.IsNull) BoolConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.BoolConditionExpressionExecutor)

Example 2 with ConfigReader

use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.

the class JoinInputStreamParser method insertJoinProcessorsAndGetFindable.

private static FindableProcessor insertJoinProcessorsAndGetFindable(JoinProcessor preJoinProcessor, JoinProcessor postJoinProcessor, SingleStreamRuntime streamRuntime, SiddhiAppContext siddhiAppContext, boolean outputExpectsExpiredEvents, String queryName, InputStream inputStream) {
    Processor lastProcessor = streamRuntime.getProcessorChain();
    Processor prevLastProcessor = null;
    if (lastProcessor != null) {
        while (lastProcessor.getNextProcessor() != null) {
            prevLastProcessor = lastProcessor;
            lastProcessor = lastProcessor.getNextProcessor();
        }
    }
    if (lastProcessor == null) {
        try {
            WindowProcessor windowProcessor = new LengthWindowProcessor();
            ExpressionExecutor[] expressionExecutors = new ExpressionExecutor[1];
            expressionExecutors[0] = new ConstantExpressionExecutor(0, Attribute.Type.INT);
            ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader("", "length");
            windowProcessor.initProcessor(((MetaStreamEvent) streamRuntime.getMetaComplexEvent()).getLastInputDefinition(), expressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, inputStream);
            lastProcessor = windowProcessor;
        } catch (Throwable t) {
            throw new SiddhiAppCreationException(t);
        }
    }
    if (lastProcessor instanceof FindableProcessor) {
        if (prevLastProcessor != null) {
            prevLastProcessor.setNextProcessor(preJoinProcessor);
        } else {
            streamRuntime.setProcessorChain(preJoinProcessor);
        }
        preJoinProcessor.setNextProcessor(lastProcessor);
        lastProcessor.setNextProcessor(postJoinProcessor);
        return (FindableProcessor) lastProcessor;
    } else {
        throw new OperationNotSupportedException("Stream " + ((MetaStreamEvent) streamRuntime.getMetaComplexEvent()).getLastInputDefinition().getId() + "'s last processor " + lastProcessor.getClass().getCanonicalName() + " is not an instance of " + FindableProcessor.class.getCanonicalName() + " hence join cannot be proceed");
    }
}
Also used : OperationNotSupportedException(org.ballerinalang.siddhi.core.exception.OperationNotSupportedException) LengthWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.LengthWindowProcessor) FindableProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.FindableProcessor) Processor(org.ballerinalang.siddhi.core.query.processor.Processor) LengthWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.LengthWindowProcessor) AggregateWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.AggregateWindowProcessor) JoinProcessor(org.ballerinalang.siddhi.core.query.input.stream.join.JoinProcessor) FindableProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.FindableProcessor) WindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor) TableWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.TableWindowProcessor) WindowWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowWindowProcessor) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader) LengthWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.LengthWindowProcessor) AggregateWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.AggregateWindowProcessor) WindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor) TableWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.TableWindowProcessor) WindowWindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowWindowProcessor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)

Example 3 with ConfigReader

use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.

the class SingleInputStreamParser method generateProcessor.

public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> variableExpressionExecutors, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, String queryName) {
    Expression[] parameters = streamHandler.getParameters();
    MetaStreamEvent metaStreamEvent;
    int stateIndex = SiddhiConstants.UNKNOWN_STATE;
    if (metaEvent instanceof MetaStateEvent) {
        stateIndex = ((MetaStateEvent) metaEvent).getStreamEventCount() - 1;
        metaStreamEvent = ((MetaStateEvent) metaEvent).getMetaStreamEvent(stateIndex);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaEvent;
    }
    ExpressionExecutor[] attributeExpressionExecutors;
    if (parameters != null) {
        if (parameters.length > 0) {
            attributeExpressionExecutors = new ExpressionExecutor[parameters.length];
            for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) {
                attributeExpressionExecutors[i] = ExpressionParser.parseExpression(parameters[i], metaEvent, stateIndex, tableMap, variableExpressionExecutors, siddhiAppContext, false, SiddhiConstants.CURRENT, queryName);
            }
        } else {
            List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
            int parameterSize = attributeList.size();
            attributeExpressionExecutors = new ExpressionExecutor[parameterSize];
            for (int i = 0; i < parameterSize; i++) {
                attributeExpressionExecutors[i] = ExpressionParser.parseExpression(new Variable(attributeList.get(i).getName()), metaEvent, stateIndex, tableMap, variableExpressionExecutors, siddhiAppContext, false, SiddhiConstants.CURRENT, queryName);
            }
        }
    } else {
        attributeExpressionExecutors = new ExpressionExecutor[0];
    }
    ConfigReader configReader;
    if (streamHandler instanceof Filter) {
        return new FilterProcessor(attributeExpressionExecutors[0]);
    } else if (streamHandler instanceof Window) {
        WindowProcessor windowProcessor = (WindowProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, WindowProcessorExtensionHolder.getInstance(siddhiAppContext));
        configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((Window) streamHandler).getNamespace(), ((Window) streamHandler).getName());
        windowProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler);
        return windowProcessor;
    } else if (streamHandler instanceof StreamFunction) {
        AbstractStreamProcessor abstractStreamProcessor;
        configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName());
        if (supportsBatchProcessing) {
            try {
                abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiAppContext));
                metaStreamEvent.addInputDefinition(abstractStreamProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler));
                return abstractStreamProcessor;
            } catch (SiddhiAppCreationException e) {
                if (!e.isClassLoadingIssue()) {
                    ExceptionUtil.populateQueryContext(e, streamHandler, siddhiAppContext);
                    throw e;
                }
            }
        }
        abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamFunctionProcessorExtensionHolder.getInstance(siddhiAppContext));
        metaStreamEvent.addInputDefinition(abstractStreamProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler));
        return abstractStreamProcessor;
    } else {
        throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported", streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex());
    }
}
Also used : Window(org.ballerinalang.siddhi.query.api.execution.query.input.handler.Window) Variable(org.ballerinalang.siddhi.query.api.expression.Variable) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) AbstractStreamProcessor(org.ballerinalang.siddhi.core.query.processor.stream.AbstractStreamProcessor) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) FilterProcessor(org.ballerinalang.siddhi.core.query.processor.filter.FilterProcessor) StreamFunction(org.ballerinalang.siddhi.query.api.execution.query.input.handler.StreamFunction) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) Filter(org.ballerinalang.siddhi.query.api.execution.query.input.handler.Filter) WindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)

Example 4 with ConfigReader

use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.

the class DefinitionParserHelper method addEventSource.

public static void addEventSource(StreamDefinition streamDefinition, ConcurrentMap<String, List<Source>> eventSourceMap, SiddhiAppContext siddhiAppContext) {
    for (Annotation sourceAnnotation : streamDefinition.getAnnotations()) {
        if (SiddhiConstants.ANNOTATION_SOURCE.equalsIgnoreCase(sourceAnnotation.getName())) {
            sourceAnnotation = updateAnnotationRef(sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE, siddhiAppContext);
            Annotation mapAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_MAP, sourceAnnotation.getAnnotations());
            if (mapAnnotation == null) {
                mapAnnotation = Annotation.annotation(SiddhiConstants.ANNOTATION_MAP).element(SiddhiConstants.ANNOTATION_ELEMENT_TYPE, "passThrough");
            }
            final String sourceType = sourceAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
            final String mapType = mapAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
            if (sourceType != null && mapType != null) {
                SourceHandlerManager sourceHandlerManager = siddhiAppContext.getSiddhiContext().getSourceHandlerManager();
                SourceHandler sourceHandler = null;
                if (sourceHandlerManager != null) {
                    sourceHandler = sourceHandlerManager.generateSourceHandler();
                }
                // load input transport extension
                Extension sourceExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SOURCE, sourceType, sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE);
                Source source = (Source) SiddhiClassLoader.loadExtensionImplementation(sourceExtension, SourceExecutorExtensionHolder.getInstance(siddhiAppContext));
                ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(sourceExtension.getNamespace(), sourceExtension.getName());
                // load input mapper extension
                Extension mapperExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_MAP, mapType, sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE_MAPPER);
                SourceMapper sourceMapper = (SourceMapper) SiddhiClassLoader.loadExtensionImplementation(mapperExtension, SourceMapperExecutorExtensionHolder.getInstance(siddhiAppContext));
                ConfigReader mapperConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(mapperExtension.getNamespace(), mapperExtension.getName());
                validateSourceMapperCompatibility(streamDefinition, sourceType, mapType, source, sourceMapper, sourceAnnotation);
                OptionHolder sourceOptionHolder = constructOptionHolder(streamDefinition, sourceAnnotation, source.getClass().getAnnotation(org.ballerinalang.siddhi.annotation.Extension.class), null);
                OptionHolder mapOptionHolder = constructOptionHolder(streamDefinition, mapAnnotation, sourceMapper.getClass().getAnnotation(org.ballerinalang.siddhi.annotation.Extension.class), null);
                AttributesHolder attributesHolder = getAttributeMappings(mapAnnotation, mapType, streamDefinition);
                String[] transportPropertyNames = getTransportPropertyNames(attributesHolder);
                try {
                    source.init(sourceType, sourceOptionHolder, sourceMapper, transportPropertyNames, configReader, mapType, mapOptionHolder, attributesHolder.payloadMappings, attributesHolder.transportMappings, mapperConfigReader, sourceHandler, streamDefinition, siddhiAppContext);
                } catch (Throwable t) {
                    ExceptionUtil.populateQueryContext(t, sourceAnnotation, siddhiAppContext);
                    throw t;
                }
                siddhiAppContext.getSnapshotService().addSnapshotable(source.getStreamDefinition().getId(), source);
                if (sourceHandlerManager != null) {
                    sourceHandlerManager.registerSourceHandler(sourceHandler.getElementId(), sourceHandler);
                    siddhiAppContext.getSnapshotService().addSnapshotable(streamDefinition.getId(), sourceHandler);
                }
                List<Source> eventSources = eventSourceMap.get(streamDefinition.getId());
                if (eventSources == null) {
                    eventSources = new ArrayList<>();
                    eventSources.add(source);
                    eventSourceMap.put(streamDefinition.getId(), eventSources);
                } else {
                    eventSources.add(source);
                }
            } else {
                throw new SiddhiAppCreationException("Both @Sink(type=) and @map(type=) are required.", sourceAnnotation.getQueryContextStartIndex(), sourceAnnotation.getQueryContextEndIndex());
            }
        }
    }
}
Also used : SourceHandler(org.ballerinalang.siddhi.core.stream.input.source.SourceHandler) SourceHandlerManager(org.ballerinalang.siddhi.core.stream.input.source.SourceHandlerManager) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader) Annotation(org.ballerinalang.siddhi.query.api.annotation.Annotation) Source(org.ballerinalang.siddhi.core.stream.input.source.Source) Extension(org.ballerinalang.siddhi.query.api.extension.Extension) OptionHolder(org.ballerinalang.siddhi.core.util.transport.OptionHolder) SourceMapper(org.ballerinalang.siddhi.core.stream.input.source.SourceMapper)

Example 5 with ConfigReader

use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.

the class DefinitionParserHelper method addEventSink.

public static void addEventSink(StreamDefinition streamDefinition, ConcurrentMap<String, List<Sink>> eventSinkMap, SiddhiAppContext siddhiAppContext) {
    for (Annotation sinkAnnotation : streamDefinition.getAnnotations()) {
        if (SiddhiConstants.ANNOTATION_SINK.equalsIgnoreCase(sinkAnnotation.getName())) {
            sinkAnnotation = updateAnnotationRef(sinkAnnotation, SiddhiConstants.NAMESPACE_SINK, siddhiAppContext);
            Annotation mapAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_MAP, sinkAnnotation.getAnnotations());
            if (mapAnnotation == null) {
                mapAnnotation = Annotation.annotation(SiddhiConstants.ANNOTATION_MAP).element(SiddhiConstants.ANNOTATION_ELEMENT_TYPE, "passThrough");
            }
            Annotation distributionAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_DISTRIBUTION, sinkAnnotation.getAnnotations());
            if (mapAnnotation != null) {
                String[] supportedDynamicOptions = null;
                List<OptionHolder> destinationOptHolders = new ArrayList<>();
                String sinkType = sinkAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
                Extension sinkExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, sinkType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
                ConfigReader sinkConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(sinkExtension.getNamespace(), sinkExtension.getName());
                final boolean isDistributedTransport = (distributionAnnotation != null);
                boolean isMultiClient = false;
                if (isDistributedTransport) {
                    Sink sink = createSink(sinkExtension, siddhiAppContext);
                    isMultiClient = isMultiClientDistributedTransport(sink, streamDefinition, distributionAnnotation, siddhiAppContext);
                    supportedDynamicOptions = sink.getSupportedDynamicOptions();
                    destinationOptHolders = createDestinationOptionHolders(distributionAnnotation, streamDefinition, sink, siddhiAppContext);
                }
                final String mapType = mapAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
                if (mapType != null) {
                    Sink sink;
                    if (isDistributedTransport) {
                        sink = (isMultiClient) ? new MultiClientDistributedSink() : new SingleClientDistributedSink();
                    } else {
                        sink = createSink(sinkExtension, siddhiAppContext);
                    }
                    if (supportedDynamicOptions == null) {
                        supportedDynamicOptions = sink.getSupportedDynamicOptions();
                    }
                    // load output mapper extension
                    Extension mapperExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_MAP, mapType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK_MAPPER);
                    ConfigReader mapperConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(sinkExtension.getNamespace(), sinkExtension.getName());
                    SinkMapper sinkMapper = (SinkMapper) SiddhiClassLoader.loadExtensionImplementation(mapperExtension, SinkMapperExecutorExtensionHolder.getInstance(siddhiAppContext));
                    org.ballerinalang.siddhi.annotation.Extension sinkExt = sink.getClass().getAnnotation(org.ballerinalang.siddhi.annotation.Extension.class);
                    OptionHolder transportOptionHolder = constructOptionHolder(streamDefinition, sinkAnnotation, sinkExt, supportedDynamicOptions);
                    OptionHolder mapOptionHolder = constructOptionHolder(streamDefinition, mapAnnotation, sinkMapper.getClass().getAnnotation(org.ballerinalang.siddhi.annotation.Extension.class), sinkMapper.getSupportedDynamicOptions());
                    List<Element> payloadElementList = getPayload(mapAnnotation);
                    OptionHolder distributionOptHolder = null;
                    SinkHandlerManager sinkHandlerManager = siddhiAppContext.getSiddhiContext().getSinkHandlerManager();
                    SinkHandler sinkHandler = null;
                    if (sinkHandlerManager != null) {
                        sinkHandler = sinkHandlerManager.generateSinkHandler();
                    }
                    if (isDistributedTransport) {
                        distributionOptHolder = constructOptionHolder(streamDefinition, distributionAnnotation, sinkExt, supportedDynamicOptions);
                        String strategyType = distributionOptHolder.validateAndGetStaticValue(SiddhiConstants.DISTRIBUTION_STRATEGY_KEY);
                        Extension strategyExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, strategyType, sinkAnnotation, SiddhiConstants.NAMESPACE_DISTRIBUTION_STRATEGY);
                        ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(strategyExtension.getNamespace(), strategyExtension.getName());
                        DistributionStrategy distributionStrategy = (DistributionStrategy) SiddhiClassLoader.loadExtensionImplementation(strategyExtension, DistributionStrategyExtensionHolder.getInstance(siddhiAppContext));
                        try {
                            distributionStrategy.init(streamDefinition, transportOptionHolder, distributionOptHolder, destinationOptHolders, configReader);
                            ((DistributedTransport) sink).init(streamDefinition, sinkType, transportOptionHolder, sinkConfigReader, sinkMapper, mapType, mapOptionHolder, sinkHandler, payloadElementList, mapperConfigReader, siddhiAppContext, destinationOptHolders, sinkAnnotation, distributionStrategy, supportedDynamicOptions);
                        } catch (Throwable t) {
                            ExceptionUtil.populateQueryContext(t, sinkAnnotation, siddhiAppContext);
                            throw t;
                        }
                    } else {
                        try {
                            sink.init(streamDefinition, sinkType, transportOptionHolder, sinkConfigReader, sinkMapper, mapType, mapOptionHolder, sinkHandler, payloadElementList, mapperConfigReader, siddhiAppContext);
                        } catch (Throwable t) {
                            ExceptionUtil.populateQueryContext(t, sinkAnnotation, siddhiAppContext);
                            throw t;
                        }
                    }
                    if (sinkHandlerManager != null) {
                        sinkHandlerManager.registerSinkHandler(sinkHandler.getElementId(), sinkHandler);
                        siddhiAppContext.getSnapshotService().addSnapshotable(streamDefinition.getId(), sinkHandler);
                    }
                    validateSinkMapperCompatibility(streamDefinition, sinkType, mapType, sink, sinkMapper, sinkAnnotation);
                    // Setting the output group determiner
                    OutputGroupDeterminer groupDeterminer = constructOutputGroupDeterminer(transportOptionHolder, distributionOptHolder, streamDefinition, destinationOptHolders.size());
                    if (groupDeterminer != null) {
                        sink.getMapper().setGroupDeterminer(groupDeterminer);
                    }
                    siddhiAppContext.getSnapshotService().addSnapshotable(sink.getStreamDefinition().getId(), sink);
                    List<Sink> eventSinks = eventSinkMap.get(streamDefinition.getId());
                    if (eventSinks == null) {
                        eventSinks = new ArrayList<>();
                        eventSinks.add(sink);
                        eventSinkMap.put(streamDefinition.getId(), eventSinks);
                    } else {
                        eventSinks.add(sink);
                    }
                }
            } else {
                throw new SiddhiAppCreationException("Both @sink(type=) and @map(type=) are required.", sinkAnnotation.getQueryContextStartIndex(), sinkAnnotation.getQueryContextEndIndex());
            }
        }
    }
}
Also used : Element(org.ballerinalang.siddhi.query.api.annotation.Element) ArrayList(java.util.ArrayList) OutputGroupDeterminer(org.ballerinalang.siddhi.core.stream.output.sink.OutputGroupDeterminer) SingleClientDistributedSink(org.ballerinalang.siddhi.core.util.transport.SingleClientDistributedSink) Sink(org.ballerinalang.siddhi.core.stream.output.sink.Sink) MultiClientDistributedSink(org.ballerinalang.siddhi.core.util.transport.MultiClientDistributedSink) SingleClientDistributedSink(org.ballerinalang.siddhi.core.util.transport.SingleClientDistributedSink) OptionHolder(org.ballerinalang.siddhi.core.util.transport.OptionHolder) SinkMapper(org.ballerinalang.siddhi.core.stream.output.sink.SinkMapper) SinkHandlerManager(org.ballerinalang.siddhi.core.stream.output.sink.SinkHandlerManager) SinkHandler(org.ballerinalang.siddhi.core.stream.output.sink.SinkHandler) DistributedTransport(org.ballerinalang.siddhi.core.stream.output.sink.distributed.DistributedTransport) DistributionStrategy(org.ballerinalang.siddhi.core.stream.output.sink.distributed.DistributionStrategy) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader) Annotation(org.ballerinalang.siddhi.query.api.annotation.Annotation) Extension(org.ballerinalang.siddhi.query.api.extension.Extension) MultiClientDistributedSink(org.ballerinalang.siddhi.core.util.transport.MultiClientDistributedSink)

Aggregations

ConfigReader (org.ballerinalang.siddhi.core.util.config.ConfigReader)7 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)5 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)4 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)3 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)3 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)3 Extension (org.ballerinalang.siddhi.query.api.extension.Extension)3 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)2 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)2 WindowProcessor (org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor)2 Annotation (org.ballerinalang.siddhi.query.api.annotation.Annotation)2 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)2 ArrayList (java.util.ArrayList)1 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)1 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1 AndConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor)1 BoolConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.BoolConditionExpressionExecutor)1 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)1