Search in sources :

Example 16 with SiddhiAppValidationException

use of io.siddhi.query.api.exception.SiddhiAppValidationException in project siddhi by wso2.

the class CoalesceFunctionExecutor method init.

@Override
public StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length == 0) {
        throw new SiddhiAppValidationException("Coalesce must have at least one parameter");
    }
    Attribute.Type type = attributeExpressionExecutors[0].getReturnType();
    for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) {
        if (type != expressionExecutor.getReturnType()) {
            throw new SiddhiAppValidationException("Coalesce cannot have parameters with different type");
        }
    }
    returnType = type;
    return null;
}
Also used : ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) Attribute(io.siddhi.query.api.definition.Attribute) ReturnAttribute(io.siddhi.annotation.ReturnAttribute) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException)

Example 17 with SiddhiAppValidationException

use of io.siddhi.query.api.exception.SiddhiAppValidationException in project siddhi by wso2.

the class ExpressionParser method parseVariable.

/**
 * Parse and validate the given Siddhi variable and return a VariableExpressionExecutor
 *
 * @param variable           Variable to be parsed
 * @param metaEvent          Meta event used to collect execution info of stream associated with query
 * @param currentState       Current State Number
 * @param executorList       List to hold VariableExpressionExecutors to update after query parsing @return
 * @param siddhiQueryContext Siddhi Query Context
 * @return VariableExpressionExecutor representing given variable
 */
private static ExpressionExecutor parseVariable(Variable variable, MetaComplexEvent metaEvent, int currentState, List<VariableExpressionExecutor> executorList, int defaultStreamEventIndex, SiddhiQueryContext siddhiQueryContext) {
    String attributeName = variable.getAttributeName();
    int[] eventPosition = new int[2];
    if (variable.getStreamIndex() != null) {
        if (variable.getStreamIndex() <= SiddhiConstants.LAST) {
            eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = variable.getStreamIndex() + 1;
        } else {
            eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = variable.getStreamIndex();
        }
    } else {
        eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = defaultStreamEventIndex;
    }
    eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = SiddhiConstants.UNKNOWN_STATE;
    if (metaEvent instanceof MetaStreamEvent) {
        MetaStreamEvent metaStreamEvent = (MetaStreamEvent) metaEvent;
        AbstractDefinition abstractDefinition;
        Attribute.Type type;
        if (currentState == SiddhiConstants.HAVING_STATE) {
            abstractDefinition = metaStreamEvent.getOutputStreamDefinition();
            type = abstractDefinition.getAttributeType(attributeName);
            eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = SiddhiConstants.HAVING_STATE;
        } else {
            abstractDefinition = metaStreamEvent.getLastInputDefinition();
            type = abstractDefinition.getAttributeType(attributeName);
            ((MetaStreamEvent) metaEvent).addData(new Attribute(attributeName, type));
        }
        if (variable.getStreamId() != null && !variable.getStreamId().equals(abstractDefinition.getId())) {
            throw new SiddhiAppCreationException("Id '" + variable.getStreamId() + "' not defined within the " + "current scope", variable, siddhiQueryContext.getSiddhiAppContext());
        }
        VariableExpressionExecutor variableExpressionExecutor = new VariableExpressionExecutor(new Attribute(attributeName, type), eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX], eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN]);
        if (((MetaStreamEvent) metaEvent).getEventType() != MetaStreamEvent.EventType.DEFAULT) {
            variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_ATTRIBUTE_TYPE_INDEX] = SiddhiConstants.OUTPUT_DATA_INDEX;
            variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_ATTRIBUTE_INDEX_IN_TYPE] = abstractDefinition.getAttributePosition(variableExpressionExecutor.getAttribute().getName());
        }
        if (executorList != null) {
            executorList.add(variableExpressionExecutor);
        }
        return variableExpressionExecutor;
    } else {
        MetaStateEvent metaStateEvent = (MetaStateEvent) metaEvent;
        Attribute.Type type = null;
        AbstractDefinition definition = null;
        String firstInput = null;
        boolean multiValue = false;
        if (variable.getStreamId() == null) {
            MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
            if (currentState == SiddhiConstants.HAVING_STATE) {
                definition = metaStateEvent.getOutputStreamDefinition();
                try {
                    type = definition.getAttributeType(attributeName);
                    eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = SiddhiConstants.HAVING_STATE;
                } catch (AttributeNotExistException e) {
                    currentState = SiddhiConstants.UNKNOWN_STATE;
                }
            }
            if (currentState == SiddhiConstants.UNKNOWN_STATE) {
                for (int i = 0; i < metaStreamEvents.length; i++) {
                    MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                    definition = metaStreamEvent.getLastInputDefinition();
                    if (type == null) {
                        try {
                            type = definition.getAttributeType(attributeName);
                            firstInput = "Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId();
                            eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = i;
                        } catch (AttributeNotExistException e) {
                        // do nothing
                        }
                    } else {
                        try {
                            definition.getAttributeType(attributeName);
                            throw new SiddhiAppValidationException(firstInput + " and Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId() + " contains attribute " + "with same" + " name '" + attributeName + "'");
                        } catch (AttributeNotExistException e) {
                        // do nothing as its expected
                        }
                    }
                }
            } else if (currentState >= 0) {
                MetaStreamEvent metaStreamEvent = metaStreamEvents[currentState];
                definition = metaStreamEvent.getLastInputDefinition();
                try {
                    type = definition.getAttributeType(attributeName);
                    eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = currentState;
                } catch (AttributeNotExistException e) {
                    ExpressionExecutor functionExecutor = constructEventExpressionExecutor(variable, currentState, siddhiQueryContext, eventPosition, metaStateEvent);
                    if (functionExecutor != null) {
                        return functionExecutor;
                    }
                    throw new SiddhiAppValidationException(e.getMessageWithOutContext() + " Input stream '" + definition.getId() + "' with reference '" + metaStreamEvent.getInputReferenceId() + "' for attribute '" + variable.getAttributeName() + "'", e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex());
                }
            }
        } else {
            MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
            for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
                MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                definition = metaStreamEvent.getLastInputDefinition();
                if (metaStreamEvent.getInputReferenceId() == null) {
                    if (definition.getId().equals(variable.getStreamId())) {
                        type = definition.getAttributeType(attributeName);
                        eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = i;
                        break;
                    }
                } else {
                    if (metaStreamEvent.getInputReferenceId().equals(variable.getStreamId())) {
                        type = definition.getAttributeType(attributeName);
                        eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = i;
                        if (currentState > -1 && metaStreamEvents[currentState].getInputReferenceId() != null && variable.getStreamIndex() != null && variable.getStreamIndex() <= SiddhiConstants.LAST) {
                            if (variable.getStreamId().equals(metaStreamEvents[currentState].getInputReferenceId())) {
                                eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN] = variable.getStreamIndex();
                            }
                        } else if (currentState == SiddhiConstants.UNKNOWN_STATE && variable.getStreamIndex() == null) {
                            multiValue = metaStreamEvent.isMultiValue();
                        }
                        break;
                    }
                }
            }
        }
        if (eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] == SiddhiConstants.UNKNOWN_STATE) {
            if (variable.getStreamId() == null) {
                ExpressionExecutor functionExecutor = constructEventExpressionExecutor(variable, currentState, siddhiQueryContext, eventPosition, metaStateEvent);
                if (functionExecutor != null) {
                    return functionExecutor;
                }
                throw new SiddhiAppValidationException("No matching stream reference found for attribute '" + variable.getAttributeName() + "'");
            } else {
                throw new SiddhiAppValidationException("Stream with reference '" + variable.getStreamId() + "' not found for attribute '" + variable.getAttributeName() + "'");
            }
        }
        VariableExpressionExecutor variableExpressionExecutor = new VariableExpressionExecutor(new Attribute(attributeName, type), eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX], eventPosition[SiddhiConstants.STREAM_EVENT_INDEX_IN_CHAIN]);
        if (eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] != SiddhiConstants.HAVING_STATE) {
            MetaStreamEvent metaStreamEvent = ((MetaStateEvent) metaEvent).getMetaStreamEvent(eventPosition[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX]);
            if (metaStreamEvent.getEventType() != MetaStreamEvent.EventType.DEFAULT) {
                variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_ATTRIBUTE_TYPE_INDEX] = SiddhiConstants.OUTPUT_DATA_INDEX;
                variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getLastInputDefinition().getAttributePosition(variableExpressionExecutor.getAttribute().getName());
                for (Attribute attribute : metaStreamEvent.getLastInputDefinition().getAttributeList()) {
                    metaStreamEvent.addOutputData(new Attribute(attribute.getName(), attribute.getType()));
                }
            }
            metaStreamEvent.addData(new Attribute(attributeName, type));
        }
        if (executorList != null) {
            executorList.add(variableExpressionExecutor);
        }
        if (multiValue) {
            FunctionExecutor functionExecutor = new MultiValueVariableFunctionExecutor();
            ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[] { variableExpressionExecutor };
            functionExecutor.initExecutor(innerExpressionExecutors, ProcessingMode.BATCH, null, false, siddhiQueryContext);
            return functionExecutor;
        }
        return variableExpressionExecutor;
    }
}
Also used : 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) Attribute(io.siddhi.query.api.definition.Attribute) 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) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) EqualCompareConditionExpressionExecutorStringString(io.siddhi.core.executor.condition.compare.equal.EqualCompareConditionExpressionExecutorStringString) NotEqualCompareConditionExpressionExecutorStringString(io.siddhi.core.executor.condition.compare.notequal.NotEqualCompareConditionExpressionExecutorStringString) MultiValueVariableFunctionExecutor(io.siddhi.core.executor.MultiValueVariableFunctionExecutor) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) AttributeNotExistException(io.siddhi.query.api.exception.AttributeNotExistException) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 18 with SiddhiAppValidationException

use of io.siddhi.query.api.exception.SiddhiAppValidationException in project siddhi by wso2.

the class EventHolderPasser method parse.

public static EventHolder parse(AbstractDefinition tableDefinition, StreamEventFactory tableStreamEventFactory, SiddhiAppContext siddhiAppContext, boolean isCacheTable) {
    ZeroStreamEventConverter eventConverter = new ZeroStreamEventConverter();
    PrimaryKeyReferenceHolder[] primaryKeyReferenceHolders = null;
    Map<String, Integer> indexMetaData = new HashMap<String, Integer>();
    // primaryKey.
    Annotation primaryKeyAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY, tableDefinition.getAnnotations());
    if (primaryKeyAnnotation != null) {
        if (primaryKeyAnnotation.getElements().size() == 0) {
            throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_PRIMARY_KEY + " annotation " + "contains " + primaryKeyAnnotation.getElements().size() + " element, at '" + tableDefinition.getId() + "'");
        }
        primaryKeyReferenceHolders = primaryKeyAnnotation.getElements().stream().map(element -> element.getValue().trim()).map(key -> new PrimaryKeyReferenceHolder(key, tableDefinition.getAttributePosition(key))).toArray(PrimaryKeyReferenceHolder[]::new);
    }
    for (Annotation indexAnnotation : AnnotationHelper.getAnnotations(SiddhiConstants.ANNOTATION_INDEX, tableDefinition.getAnnotations())) {
        if (indexAnnotation.getElements().size() == 0) {
            throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_INDEX + " annotation of " + "in-memory table should contain only one index element, but found " + indexAnnotation.getElements().size() + " element", indexAnnotation.getQueryContextStartIndex(), indexAnnotation.getQueryContextEndIndex());
        } else if (indexAnnotation.getElements().size() > 1) {
            throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_INDEX + " annotation of the " + "in-memory table should only contain one index element but found " + indexAnnotation.getElements().size() + " elements. To use multiple indexes, " + "define multiple '@index(<index key>)' annotations with one index element " + "per each index key", indexAnnotation.getQueryContextStartIndex(), indexAnnotation.getQueryContextEndIndex());
        }
        for (Element element : indexAnnotation.getElements()) {
            Integer previousValue = indexMetaData.put(element.getValue().trim(), tableDefinition.getAttributePosition(element.getValue().trim()));
            if (previousValue != null) {
                throw new SiddhiAppValidationException("Multiple " + SiddhiConstants.ANNOTATION_INDEX + " " + "annotations defined with same attribute '" + element.getValue().trim() + "', at '" + tableDefinition.getId() + "'", indexAnnotation.getQueryContextStartIndex(), indexAnnotation.getQueryContextEndIndex());
            }
        }
    }
    // not support indexBy.
    Annotation indexByAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX_BY, tableDefinition.getAnnotations());
    if (indexByAnnotation != null) {
        throw new OperationNotSupportedException(SiddhiConstants.ANNOTATION_INDEX_BY + " annotation is not " + "supported anymore, please use @PrimaryKey or @Index annotations instead," + " at '" + tableDefinition.getId() + "'");
    }
    if (primaryKeyReferenceHolders != null || indexMetaData.size() > 0) {
        boolean isNumeric = false;
        if (primaryKeyReferenceHolders != null) {
            if (primaryKeyReferenceHolders.length == 1) {
                Attribute.Type type = tableDefinition.getAttributeType(primaryKeyReferenceHolders[0].getPrimaryKeyAttribute());
                if (type == Attribute.Type.DOUBLE || type == Attribute.Type.FLOAT || type == Attribute.Type.INT || type == Attribute.Type.LONG) {
                    isNumeric = true;
                }
            }
        }
        if (isCacheTable) {
            return new IndexEventHolderForCache(tableStreamEventFactory, eventConverter, primaryKeyReferenceHolders, isNumeric, indexMetaData, tableDefinition, siddhiAppContext);
        } else {
            return new IndexEventHolder(tableStreamEventFactory, eventConverter, primaryKeyReferenceHolders, isNumeric, indexMetaData, tableDefinition, siddhiAppContext);
        }
    } else {
        MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
        for (Attribute attribute : tableDefinition.getAttributeList()) {
            metaStreamEvent.addOutputData(attribute);
        }
        StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, tableStreamEventFactory);
        return new ListEventHolder(tableStreamEventFactory, eventConverter, new StreamEventClonerHolder(streamEventCloner));
    }
}
Also used : StreamEventClonerHolder(io.siddhi.core.event.stream.holder.StreamEventClonerHolder) AnnotationHelper(io.siddhi.query.api.util.AnnotationHelper) SiddhiAppContext(io.siddhi.core.config.SiddhiAppContext) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) PrimaryKeyReferenceHolder(io.siddhi.core.table.holder.PrimaryKeyReferenceHolder) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) SiddhiConstants(io.siddhi.core.util.SiddhiConstants) Attribute(io.siddhi.query.api.definition.Attribute) Annotation(io.siddhi.query.api.annotation.Annotation) HashMap(java.util.HashMap) IndexEventHolderForCache(io.siddhi.core.table.holder.IndexEventHolderForCache) Element(io.siddhi.query.api.annotation.Element) IndexEventHolder(io.siddhi.core.table.holder.IndexEventHolder) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) ListEventHolder(io.siddhi.core.table.holder.ListEventHolder) Logger(org.apache.logging.log4j.Logger) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ZeroStreamEventConverter(io.siddhi.core.event.stream.converter.ZeroStreamEventConverter) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) Map(java.util.Map) EventHolder(io.siddhi.core.table.holder.EventHolder) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) LogManager(org.apache.logging.log4j.LogManager) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) IndexEventHolder(io.siddhi.core.table.holder.IndexEventHolder) HashMap(java.util.HashMap) Attribute(io.siddhi.query.api.definition.Attribute) Element(io.siddhi.query.api.annotation.Element) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) PrimaryKeyReferenceHolder(io.siddhi.core.table.holder.PrimaryKeyReferenceHolder) Annotation(io.siddhi.query.api.annotation.Annotation) StreamEventClonerHolder(io.siddhi.core.event.stream.holder.StreamEventClonerHolder) ZeroStreamEventConverter(io.siddhi.core.event.stream.converter.ZeroStreamEventConverter) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) ListEventHolder(io.siddhi.core.table.holder.ListEventHolder) IndexEventHolderForCache(io.siddhi.core.table.holder.IndexEventHolderForCache) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 19 with SiddhiAppValidationException

use of io.siddhi.query.api.exception.SiddhiAppValidationException in project siddhi by wso2.

the class PartitionedDistributionStrategy method init.

/**
 * Initialize the Distribution strategy with the information it will require to make decisions.
 *
 * @param streamDefinition         The stream attached to the sink this DistributionStrategy is used in
 * @param transportOptionHolder    Sink options of the sink which uses this DistributionStrategy
 * @param destinationOptionHolders The list of options under @destination of the relevant sink.
 * @param configReader             This hold the {@link PartitionedDistributionStrategy} configuration reader.
 */
@Override
public void init(StreamDefinition streamDefinition, OptionHolder transportOptionHolder, OptionHolder distributionOptionHolder, List<OptionHolder> destinationOptionHolders, ConfigReader configReader) {
    totalDestinationCount = destinationOptionHolders.size();
    String partitionKey = distributionOptionHolder.validateAndGetStaticValue(SiddhiConstants.PARTITION_KEY_FIELD_KEY);
    if (partitionKey == null || partitionKey.isEmpty()) {
        throw new SiddhiAppValidationException("PartitionKey is required for partitioned distribution " + "strategy.");
    }
    try {
        int partitionKeyFieldPosition = streamDefinition.getAttributePosition(partitionKey);
        partitionOption = new Option(partitionKeyFieldPosition);
    } catch (AttributeNotExistException e) {
        throw new SiddhiAppValidationException("Could not find partition key attribute", e);
    }
}
Also used : AttributeNotExistException(io.siddhi.query.api.exception.AttributeNotExistException) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) Option(io.siddhi.core.util.transport.Option)

Example 20 with SiddhiAppValidationException

use of io.siddhi.query.api.exception.SiddhiAppValidationException in project siddhi by wso2.

the class TimeBatchWindowProcessor method init.

@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    this.siddhiQueryContext = siddhiQueryContext;
    if (attributeExpressionExecutors.length == 1) {
        initTimeParameter(attributeExpressionExecutors[0]);
    } else if (attributeExpressionExecutors.length == 2) {
        initTimeParameter(attributeExpressionExecutors[0]);
        if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
            throw new SiddhiAppValidationException("TimeBatch window's window.time (2nd) parameter should be " + "constant but found a dynamic attribute " + attributeExpressionExecutors[1].getClass().getCanonicalName());
        }
        // start time
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            isStartTimeEnabled = true;
            startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
            isStartTimeEnabled = true;
            startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.BOOL) {
            isStreamCurrentEvents = Boolean.valueOf(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else {
            throw new SiddhiAppValidationException("TimeBatch window's 2nd parameter " + "should be 'start.time' which is int or long, or 'stream.current.event' which is bool " + " but found " + attributeExpressionExecutors[1].getReturnType());
        }
    } else if (attributeExpressionExecutors.length == 3) {
        initTimeParameter(attributeExpressionExecutors[0]);
        if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
            throw new SiddhiAppValidationException("TimeBatch window's window.time (2nd) parameter 'start.time' " + "should be a constant but found a dynamic attribute " + attributeExpressionExecutors[1].getClass().getCanonicalName());
        }
        // start time
        isStartTimeEnabled = true;
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
            startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else {
            throw new SiddhiAppValidationException("TimeBatch window's 2nd parameter " + "should be 'start.time' which is int or long, " + " but found " + attributeExpressionExecutors[1].getReturnType());
        }
        if (!(attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor)) {
            throw new SiddhiAppValidationException("TimeBatch window's window.time (3rd) parameter " + "'stream.current.event' should be a constant but found a dynamic attribute " + attributeExpressionExecutors[2].getClass().getCanonicalName());
        }
        if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.BOOL) {
            isStreamCurrentEvents = Boolean.valueOf(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
        } else {
            throw new SiddhiAppValidationException("TimeBatch window's 3rd parameter " + "should be 'stream.current.event' which is bool " + " but found " + attributeExpressionExecutors[2].getReturnType());
        }
    } else {
        throw new SiddhiAppValidationException("Time window should only have one or two parameters. " + "(<int|long|time> windowTime), but found " + attributeExpressionExecutors.length + " input " + "attributes");
    }
    return () -> new WindowState(streamEventClonerHolder, outputExpectsExpiredEvents, findToBeExecuted);
}
Also used : SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor)

Aggregations

SiddhiAppValidationException (io.siddhi.query.api.exception.SiddhiAppValidationException)27 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)7 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)7 Attribute (io.siddhi.query.api.definition.Attribute)7 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)6 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)5 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)5 Element (io.siddhi.query.api.annotation.Element)5 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)4 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)4 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)4 ArrayList (java.util.ArrayList)4 Expression (io.siddhi.query.api.expression.Expression)3 HashMap (java.util.HashMap)3 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)2 StreamEvent (io.siddhi.core.event.stream.StreamEvent)2 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)2 ZeroStreamEventConverter (io.siddhi.core.event.stream.converter.ZeroStreamEventConverter)2 QueryableRecordTableException (io.siddhi.core.exception.QueryableRecordTableException)2 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)2