Search in sources :

Example 6 with ConfigReader

use of io.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

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
 * @param groupBy                    is for groupBy expression
 * @param defaultStreamEventIndex    Default StreamEvent Index
 * @param processingMode             processing mode of the query
 * @param outputExpectsExpiredEvents is expired events sent as output
 * @param siddhiQueryContext         current siddhi query context
 * @return ExpressionExecutor
 */
public static ExpressionExecutor parseExpression(Expression expression, MetaComplexEvent metaEvent, int currentState, Map<String, Table> tableMap, List<VariableExpressionExecutor> executorList, boolean groupBy, int defaultStreamEventIndex, ProcessingMode processingMode, boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
    try {
        if (expression instanceof And) {
            return new AndConditionExpressionExecutor(parseExpression(((And) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((And) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
        } else if (expression instanceof Or) {
            return new OrConditionExpressionExecutor(parseExpression(((Or) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((Or) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
        } else if (expression instanceof Not) {
            return new NotConditionExpressionExecutor(parseExpression(((Not) expression).getExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
        } else if (expression instanceof Compare) {
            if (((Compare) expression).getOperator() == Compare.Operator.EQUAL) {
                Expression leftExpression = ((Compare) expression).getLeftExpression();
                Expression rightExpression = ((Compare) expression).getRightExpression();
                ExpressionExecutor leftExpressionExecutor = parseExpression(leftExpression, metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
                ExpressionExecutor rightExpressionExecutor = parseExpression(rightExpression, metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
                return parseEqualCompare(leftExpressionExecutor, rightExpressionExecutor);
            } else if (((Compare) expression).getOperator() == Compare.Operator.NOT_EQUAL) {
                return parseNotEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
            } else if (((Compare) expression).getOperator() == Compare.Operator.GREATER_THAN) {
                return parseGreaterThanCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
            } else if (((Compare) expression).getOperator() == Compare.Operator.GREATER_THAN_EQUAL) {
                return parseGreaterThanEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
            } else if (((Compare) expression).getOperator() == Compare.Operator.LESS_THAN) {
                return parseLessThanCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
            } else if (((Compare) expression).getOperator() == Compare.Operator.LESS_THAN_EQUAL) {
                return parseLessThanEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext));
            }
        } 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, siddhiQueryContext);
        } else if (expression instanceof Multiply) {
            ExpressionExecutor left = parseExpression(((Multiply) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            ExpressionExecutor right = parseExpression(((Multiply) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            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, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            ExpressionExecutor right = parseExpression(((Add) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            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, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            ExpressionExecutor right = parseExpression(((Subtract) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            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, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            ExpressionExecutor right = parseExpression(((Mod) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            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, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            ExpressionExecutor right = parseExpression(((Divide) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
            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 ((siddhiQueryContext.getSiddhiAppContext().isFunctionExist(((AttributeFunction) expression).getName())) && (((AttributeFunction) expression).getNamespace()).isEmpty()) {
                    executor = new ScriptFunctionExecutor(((AttributeFunction) expression).getName());
                } else {
                    executor = SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, FunctionExecutorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
                }
            } catch (SiddhiAppCreationException ex) {
                try {
                    executor = SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, AttributeAggregatorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
                } catch (SiddhiAppCreationException e) {
                    throw new ExtensionNotFoundException("'" + ((AttributeFunction) expression).getName() + "' is" + " neither a function extension nor an aggregated attribute extension", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
                }
            }
            ConfigReader configReader = siddhiQueryContext.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, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
                expressionExecutor.initExecutor(innerExpressionExecutors, processingMode, configReader, groupBy, siddhiQueryContext);
                if (expressionExecutor.getReturnType() == Attribute.Type.BOOL) {
                    return new BoolConditionExpressionExecutor(expressionExecutor);
                }
                return expressionExecutor;
            } else {
                AttributeAggregatorExecutor attributeAggregatorExecutor = (AttributeAggregatorExecutor) executor;
                Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
                ExpressionExecutor[] innerExpressionExecutors = parseInnerExpression(innerExpressions, metaEvent, currentState, tableMap, executorList, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
                attributeAggregatorExecutor.initAggregator(innerExpressionExecutors, processingMode, outputExpectsExpiredEvents, configReader, groupBy, siddhiQueryContext);
                // AbstractAggregationAttributeExecutor aggregationAttributeProcessor;
                // if (groupBy) {
                // aggregationAttributeProcessor = new GroupByAggregationAttributeExecutor(attributeAggregatorExecutor,
                // innerExpressionExecutors, configReader, siddhiQueryContext);
                // } else {
                // aggregationAttributeProcessor = new AggregationAttributeExecutor(attributeAggregatorExecutor,
                // innerExpressionExecutors, siddhiQueryContext);
                // }
                SelectorParser.getContainsAggregatorThreadLocal().set("true");
                return attributeAggregatorExecutor;
            }
        } 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, executorList, tableMap, siddhiQueryContext);
            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, groupBy, defaultStreamEventIndex, processingMode, outputExpectsExpiredEvents, siddhiQueryContext);
                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 <= SiddhiConstants.LAST) {
                            eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex + 1;
                        } else {
                            eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex;
                        }
                    } else {
                        eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = defaultStreamEventIndex;
                    }
                    eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = SiddhiConstants.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[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = i;
                                    break;
                                }
                            } else {
                                if (metaStreamEvent.getInputReferenceId().equals(streamId)) {
                                    eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = i;
                                    if (currentState > -1 && metaStreamEvents[currentState].getInputReferenceId() != null && streamIndex != null && streamIndex <= SiddhiConstants.LAST) {
                                        if (streamId.equals(metaStreamEvents[currentState].getInputReferenceId())) {
                                            eventPosition[SiddhiConstants.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, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext);
        throw t;
    }
}
Also used : Add(io.siddhi.query.api.expression.math.Add) Or(io.siddhi.query.api.expression.condition.Or) DivideExpressionExecutorFloat(io.siddhi.core.executor.math.divide.DivideExpressionExecutorFloat) ModExpressionExecutorDouble(io.siddhi.core.executor.math.mod.ModExpressionExecutorDouble) ModExpressionExecutorInt(io.siddhi.core.executor.math.mod.ModExpressionExecutorInt) EqualCompareConditionExpressionExecutorStringString(io.siddhi.core.executor.condition.compare.equal.EqualCompareConditionExpressionExecutorStringString) NotEqualCompareConditionExpressionExecutorStringString(io.siddhi.core.executor.condition.compare.notequal.NotEqualCompareConditionExpressionExecutorStringString) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) Divide(io.siddhi.query.api.expression.math.Divide) MultiplyExpressionExecutorLong(io.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorLong) AddExpressionExecutorLong(io.siddhi.core.executor.math.add.AddExpressionExecutorLong) Multiply(io.siddhi.query.api.expression.math.Multiply) AddExpressionExecutorInt(io.siddhi.core.executor.math.add.AddExpressionExecutorInt) Compare(io.siddhi.query.api.expression.condition.Compare) DivideExpressionExecutorDouble(io.siddhi.core.executor.math.divide.DivideExpressionExecutorDouble) ExtensionNotFoundException(io.siddhi.core.exception.ExtensionNotFoundException) FunctionExecutor(io.siddhi.core.executor.function.FunctionExecutor) EventVariableFunctionExecutor(io.siddhi.core.executor.EventVariableFunctionExecutor) MultiValueVariableFunctionExecutor(io.siddhi.core.executor.MultiValueVariableFunctionExecutor) ScriptFunctionExecutor(io.siddhi.core.executor.function.ScriptFunctionExecutor) AddExpressionExecutorFloat(io.siddhi.core.executor.math.add.AddExpressionExecutorFloat) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) Not(io.siddhi.query.api.expression.condition.Not) MultiplyExpressionExecutorFloat(io.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorFloat) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition) And(io.siddhi.query.api.expression.condition.And) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) SubtractExpressionExecutorLong(io.siddhi.core.executor.math.subtract.SubtractExpressionExecutorLong) IsNullStreamConditionExpressionExecutor(io.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor) Subtract(io.siddhi.query.api.expression.math.Subtract) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) DoubleConstant(io.siddhi.query.api.expression.constant.DoubleConstant) Variable(io.siddhi.query.api.expression.Variable) MultiplyExpressionExecutorDouble(io.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorDouble) Attribute(io.siddhi.query.api.definition.Attribute) In(io.siddhi.query.api.expression.condition.In) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) Constant(io.siddhi.query.api.expression.constant.Constant) DoubleConstant(io.siddhi.query.api.expression.constant.DoubleConstant) FloatConstant(io.siddhi.query.api.expression.constant.FloatConstant) BoolConstant(io.siddhi.query.api.expression.constant.BoolConstant) LongConstant(io.siddhi.query.api.expression.constant.LongConstant) IntConstant(io.siddhi.query.api.expression.constant.IntConstant) ModExpressionExecutorLong(io.siddhi.core.executor.math.mod.ModExpressionExecutorLong) ScriptFunctionExecutor(io.siddhi.core.executor.function.ScriptFunctionExecutor) InConditionExpressionExecutor(io.siddhi.core.executor.condition.InConditionExpressionExecutor) FloatConstant(io.siddhi.query.api.expression.constant.FloatConstant) AddExpressionExecutorDouble(io.siddhi.core.executor.math.add.AddExpressionExecutorDouble) AndConditionExpressionExecutor(io.siddhi.core.executor.condition.AndConditionExpressionExecutor) MultiplyExpressionExecutorInt(io.siddhi.core.executor.math.multiply.MultiplyExpressionExecutorInt) IsNullConditionExpressionExecutor(io.siddhi.core.executor.condition.IsNullConditionExpressionExecutor) SubtractExpressionExecutorInt(io.siddhi.core.executor.math.subtract.SubtractExpressionExecutorInt) IntConstant(io.siddhi.query.api.expression.constant.IntConstant) SubtractExpressionExecutorDouble(io.siddhi.core.executor.math.subtract.SubtractExpressionExecutorDouble) AttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.AttributeAggregatorExecutor) LongConstant(io.siddhi.query.api.expression.constant.LongConstant) BoolConstant(io.siddhi.query.api.expression.constant.BoolConstant) Mod(io.siddhi.query.api.expression.math.Mod) Table(io.siddhi.core.table.Table) IsNullConditionExpressionExecutor(io.siddhi.core.executor.condition.IsNullConditionExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) NotConditionExpressionExecutor(io.siddhi.core.executor.condition.NotConditionExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) ConditionExpressionExecutor(io.siddhi.core.executor.condition.ConditionExpressionExecutor) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) OrConditionExpressionExecutor(io.siddhi.core.executor.condition.OrConditionExpressionExecutor) BoolConditionExpressionExecutor(io.siddhi.core.executor.condition.BoolConditionExpressionExecutor) InConditionExpressionExecutor(io.siddhi.core.executor.condition.InConditionExpressionExecutor) AndConditionExpressionExecutor(io.siddhi.core.executor.condition.AndConditionExpressionExecutor) IsNullStreamConditionExpressionExecutor(io.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor) ConfigReader(io.siddhi.core.util.config.ConfigReader) OrConditionExpressionExecutor(io.siddhi.core.executor.condition.OrConditionExpressionExecutor) DivideExpressionExecutorLong(io.siddhi.core.executor.math.divide.DivideExpressionExecutorLong) AttributeFunction(io.siddhi.query.api.expression.AttributeFunction) DivideExpressionExecutorInt(io.siddhi.core.executor.math.divide.DivideExpressionExecutorInt) SubtractExpressionExecutorFloat(io.siddhi.core.executor.math.subtract.SubtractExpressionExecutorFloat) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) Expression(io.siddhi.query.api.expression.Expression) NotConditionExpressionExecutor(io.siddhi.core.executor.condition.NotConditionExpressionExecutor) ModExpressionExecutorFloat(io.siddhi.core.executor.math.mod.ModExpressionExecutorFloat) StateEvent(io.siddhi.core.event.state.StateEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) IsNull(io.siddhi.query.api.expression.condition.IsNull) BoolConditionExpressionExecutor(io.siddhi.core.executor.condition.BoolConditionExpressionExecutor)

Example 7 with ConfigReader

use of io.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class AggregationParser method getCudProcessor.

private static Processor getCudProcessor(StreamHandler streamHandler, SiddhiQueryContext siddhiQueryContext, MetaStreamEvent metaStreamEvent, ExpressionExecutor[] attributeExpressionExecutors, TimePeriod.Duration duration) {
    ConfigReader configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName());
    AbstractStreamProcessor abstractStreamProcessor;
    abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
    abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, false, false, false, streamHandler, siddhiQueryContext);
    if (metaStreamEvent.getInputDefinitions().size() == 2) {
        AbstractDefinition outputDefinition = metaStreamEvent.getInputDefinitions().get(1);
        List<Attribute> outputAttributes = outputDefinition.getAttributeList();
        for (Attribute attribute : outputAttributes) {
            metaStreamEvent.addOutputData(attribute);
        }
        metaStreamEvent.setOutputDefinition((StreamDefinition) outputDefinition);
    }
    abstractStreamProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
    abstractStreamProcessor.setNextProcessor(new PersistedAggregationResultsProcessor(duration));
    return abstractStreamProcessor;
}
Also used : PersistedAggregationResultsProcessor(io.siddhi.core.aggregation.persistedaggregation.config.PersistedAggregationResultsProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) ConfigReader(io.siddhi.core.util.config.ConfigReader) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition)

Example 8 with ConfigReader

use of io.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class YAMLConfigManagerTestCase method yamlConfigManagerTest1.

@Test
public void yamlConfigManagerTest1() {
    log.info("YAMLConfigManagerTest1");
    String baseDir = Paths.get(".").toString();
    Path filePath = Paths.get(baseDir, "src", "test", "resources", "systemProperties.yaml");
    String fileContent = FileReader.readYAMLConfigFile(filePath);
    YAMLConfigManager yamlConfigManager = new YAMLConfigManager(fileContent);
    Map<String, String> testConfigs = yamlConfigManager.extractSystemConfigs("test");
    Assert.assertEquals(testConfigs.size(), 0);
    Map<String, String> source1Ref = yamlConfigManager.extractSystemConfigs("ref1");
    Assert.assertEquals(source1Ref.size(), 3);
    Assert.assertEquals(source1Ref.get("type"), "testStoreContainingInMemoryTable");
    Assert.assertEquals(source1Ref.get("property1"), "value1");
    Assert.assertEquals(source1Ref.get("property2"), "value2");
    Assert.assertNull(source1Ref.get("property3"));
    String partitionById = yamlConfigManager.extractProperty("partitionById");
    Assert.assertEquals(partitionById, "TRUE");
    String shardID1 = yamlConfigManager.extractProperty("shardId1");
    Assert.assertNull(shardID1);
    ConfigReader testConfigReader = yamlConfigManager.generateConfigReader("test", "test");
    Assert.assertEquals(testConfigReader.getAllConfigs().size(), 0);
    ConfigReader configReader = yamlConfigManager.generateConfigReader("store", "rdbms");
    Assert.assertEquals(configReader.getAllConfigs().size(), 5);
    Assert.assertEquals(configReader.readConfig("mysql.batchEnable", "test"), "true");
    Assert.assertEquals(configReader.readConfig("test", "test"), "test");
}
Also used : Path(java.nio.file.Path) YAMLConfigManager(io.siddhi.core.util.config.YAMLConfigManager) ConfigReader(io.siddhi.core.util.config.ConfigReader) StringConcatAggregatorExecutorString(io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString) Test(org.testng.annotations.Test)

Example 9 with ConfigReader

use of io.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class DefinitionParserHelper method addFunction.

public static void addFunction(SiddhiAppContext siddhiAppContext, final FunctionDefinition functionDefinition) {
    Extension extension = new Extension() {

        @Override
        public String getNamespace() {
            return "script";
        }

        @Override
        public String getName() {
            return functionDefinition.getLanguage().toLowerCase();
        }
    };
    try {
        Script script = (Script) SiddhiClassLoader.loadExtensionImplementation(extension, ScriptExtensionHolder.getInstance(siddhiAppContext));
        ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
        script.setReturnType(functionDefinition.getReturnType());
        script.init(functionDefinition.getId(), functionDefinition.getBody(), configReader);
        siddhiAppContext.getScriptFunctionMap().put(functionDefinition.getId(), script);
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, functionDefinition, siddhiAppContext);
        throw t;
    }
}
Also used : Extension(io.siddhi.query.api.extension.Extension) Script(io.siddhi.core.function.Script) ConfigReader(io.siddhi.core.util.config.ConfigReader)

Example 10 with ConfigReader

use of io.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class DefinitionParserHelper method addTable.

public static void addTable(TableDefinition tableDefinition, ConcurrentMap<String, Table> tableMap, SiddhiAppContext siddhiAppContext) {
    if (!tableMap.containsKey(tableDefinition.getId())) {
        MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
        tableMetaStreamEvent.addInputDefinition(tableDefinition);
        for (Attribute attribute : tableDefinition.getAttributeList()) {
            tableMetaStreamEvent.addOutputData(attribute);
        }
        StreamEventFactory tableStreamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
        StreamEventCloner tableStreamEventCloner = new StreamEventCloner(tableMetaStreamEvent, tableStreamEventFactory);
        Annotation annotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_STORE, tableDefinition.getAnnotations());
        Table table;
        ConfigReader configReader = null;
        RecordTableHandlerManager recordTableHandlerManager = null;
        RecordTableHandler recordTableHandler = null;
        if (annotation != null) {
            annotation = updateAnnotationRef(annotation, SiddhiConstants.NAMESPACE_STORE, siddhiAppContext);
            String tableType = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
            if (tableType == null) {
                throw new SiddhiAppCreationException("Attribute 'type' does not exist for annotation '" + annotation + "'", annotation, siddhiAppContext);
            }
            Extension extension = new Extension() {

                @Override
                public String getNamespace() {
                    return SiddhiConstants.NAMESPACE_STORE;
                }

                @Override
                public String getName() {
                    return tableType;
                }
            };
            recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
            if (recordTableHandlerManager != null) {
                recordTableHandler = recordTableHandlerManager.generateRecordTableHandler();
            }
            table = (Table) SiddhiClassLoader.loadExtensionImplementation(extension, TableExtensionHolder.getInstance(siddhiAppContext));
            configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
        } else {
            table = new InMemoryTable();
        }
        table.initTable(tableDefinition, tableStreamEventFactory, tableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
        if (recordTableHandler != null) {
            recordTableHandlerManager.registerRecordTableHandler(recordTableHandler.getId(), recordTableHandler);
        }
        tableMap.putIfAbsent(tableDefinition.getId(), table);
    }
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) Table(io.siddhi.core.table.Table) InMemoryTable(io.siddhi.core.table.InMemoryTable) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) ConfigReader(io.siddhi.core.util.config.ConfigReader) RecordTableHandler(io.siddhi.core.table.record.RecordTableHandler) Annotation(io.siddhi.query.api.annotation.Annotation) Extension(io.siddhi.query.api.extension.Extension) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) RecordTableHandlerManager(io.siddhi.core.table.record.RecordTableHandlerManager) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

ConfigReader (io.siddhi.core.util.config.ConfigReader)10 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)6 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)4 Attribute (io.siddhi.query.api.definition.Attribute)4 Extension (io.siddhi.query.api.extension.Extension)4 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)3 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)3 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)2 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)2 WindowProcessor (io.siddhi.core.query.processor.stream.window.WindowProcessor)2 Table (io.siddhi.core.table.Table)2 OptionHolder (io.siddhi.core.util.transport.OptionHolder)2 Annotation (io.siddhi.query.api.annotation.Annotation)2 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)2 PersistedAggregationResultsProcessor (io.siddhi.core.aggregation.persistedaggregation.config.PersistedAggregationResultsProcessor)1 StateEvent (io.siddhi.core.event.state.StateEvent)1 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)1 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)1 ExtensionNotFoundException (io.siddhi.core.exception.ExtensionNotFoundException)1 OperationNotSupportedException (io.siddhi.core.exception.OperationNotSupportedException)1