Search in sources :

Example 21 with SiddhiAppValidationException

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

the class BatchWindowProcessor method init.

@Override
protected StateFactory<WindowState> init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    this.findToBeExecuted = findToBeExecuted;
    this.siddhiQueryContext = siddhiQueryContext;
    if (attributeExpressionExecutors.length == 1) {
        length = (Integer) (((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue());
    } else if (attributeExpressionExecutors.length == 0) {
        length = 0;
    } else {
        throw new SiddhiAppValidationException("Batch window should have at most one parameter (<int> " + "chunkLength), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    if (length < 0) {
        throw new SiddhiAppValidationException("Batch window should have at most one parameter (<int> " + "chunkLength) greater than zero. But found value 'chunkLength = " + length + " ' ");
    }
    return () -> new WindowState(streamEventClonerHolder, outputExpectsExpiredEvents, findToBeExecuted);
}
Also used : SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException)

Example 22 with SiddhiAppValidationException

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

the class OutputParser method constructOutputCallback.

public static OutputCallback constructOutputCallback(final OutputStream outStream, StreamDefinition outputStreamDefinition, Map<String, Table> tableMap, Map<String, Window> eventWindowMap, boolean convertToStreamEvent, SiddhiQueryContext siddhiQueryContext) {
    String id = outStream.getId();
    Table table = null;
    Window window = null;
    if (id != null) {
        table = tableMap.get(id);
        window = eventWindowMap.get(id);
    }
    StreamEventFactory streamEventFactory = null;
    StreamEventConverter streamEventConverter = null;
    MetaStreamEvent tableMetaStreamEvent = null;
    if (table != null) {
        tableMetaStreamEvent = new MetaStreamEvent();
        tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
        TableDefinition matchingTableDefinition = TableDefinition.id("");
        for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
            tableMetaStreamEvent.addOutputData(attribute);
            matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
        }
        matchingTableDefinition.setQueryContextStartIndex(outStream.getQueryContextStartIndex());
        matchingTableDefinition.setQueryContextEndIndex(outStream.getQueryContextEndIndex());
        tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
        streamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
        streamEventConverter = new ZeroStreamEventConverter();
    }
    // Construct CallBack
    if (outStream instanceof InsertIntoStream || outStream instanceof ReturnStream) {
        if (window != null) {
            if (!siddhiQueryContext.isPartitioned()) {
                return new InsertIntoWindowCallback(window, outputStreamDefinition, siddhiQueryContext.getName());
            } else {
                return new InsertIntoWindowEndPartitionCallback(window, outputStreamDefinition, siddhiQueryContext.getName());
            }
        } else if (table != null) {
            DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
            return new InsertIntoTableCallback(table, outputStreamDefinition, convertToStreamEvent, streamEventFactory, streamEventConverter, siddhiQueryContext.getName());
        } else {
            if (!siddhiQueryContext.isPartitioned() || outputStreamDefinition.getId().startsWith("#")) {
                return new InsertIntoStreamCallback(outputStreamDefinition, siddhiQueryContext.getName());
            } else {
                return new InsertIntoStreamEndPartitionCallback(outputStreamDefinition, siddhiQueryContext.getName());
            }
        }
    } else if (outStream instanceof DeleteStream || outStream instanceof UpdateStream || outStream instanceof UpdateOrInsertStream) {
        if (table != null) {
            if (outStream instanceof UpdateStream) {
                if (((UpdateStream) outStream).getUpdateSet() == null) {
                    TableDefinition tableDefinition = table.getTableDefinition();
                    for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
                        if (!tableDefinition.getAttributeList().contains(attribute)) {
                            throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
                        }
                    }
                }
            }
            if (outStream instanceof UpdateOrInsertStream) {
                TableDefinition tableDefinition = table.getTableDefinition();
                for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
                    if (!tableDefinition.getAttributeList().contains(attribute)) {
                        throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
                    }
                }
            }
            if (outStream instanceof DeleteStream) {
                try {
                    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
                    CompiledCondition compiledCondition = table.compileCondition((((DeleteStream) outStream).getOnDeleteExpression()), matchingMetaInfoHolder, null, tableMap, siddhiQueryContext);
                    StateEventFactory stateEventFactory = new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent());
                    return new DeleteTableCallback(table, compiledCondition, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventFactory, streamEventFactory, streamEventConverter, siddhiQueryContext.getName());
                } catch (SiddhiAppValidationException e) {
                    throw new SiddhiAppCreationException("Cannot create delete for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiQueryContext.getName(), siddhiQueryContext.getSiddhiAppContext().getSiddhiAppString());
                }
            } else if (outStream instanceof UpdateStream) {
                try {
                    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
                    CompiledCondition compiledCondition = table.compileCondition((((UpdateStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, null, tableMap, siddhiQueryContext);
                    UpdateSet updateSet = ((UpdateStream) outStream).getUpdateSet();
                    if (updateSet == null) {
                        updateSet = new UpdateSet();
                        for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
                            updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
                        }
                    }
                    CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, null, tableMap, siddhiQueryContext);
                    StateEventFactory stateEventFactory = new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent());
                    return new UpdateTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventFactory, streamEventFactory, streamEventConverter, siddhiQueryContext.getName());
                } catch (SiddhiAppValidationException e) {
                    throw new SiddhiAppCreationException("Cannot create update for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiQueryContext.getSiddhiAppContext());
                }
            } else {
                DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
                try {
                    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
                    CompiledCondition compiledCondition = table.compileCondition((((UpdateOrInsertStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, null, tableMap, siddhiQueryContext);
                    UpdateSet updateSet = ((UpdateOrInsertStream) outStream).getUpdateSet();
                    if (updateSet == null) {
                        updateSet = new UpdateSet();
                        for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
                            updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
                        }
                    }
                    CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, null, tableMap, siddhiQueryContext);
                    StateEventFactory stateEventFactory = new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent());
                    return new UpdateOrInsertTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventFactory, streamEventFactory, streamEventConverter, siddhiQueryContext.getName());
                } catch (SiddhiAppValidationException e) {
                    throw new SiddhiAppCreationException("Cannot create update or insert into for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiQueryContext.getSiddhiAppContext());
                }
            }
        } else {
            throw new SiddhiAppCreationException("Event table with id :" + id + " does not exist", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
        }
    } else {
        throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
    }
}
Also used : InsertIntoWindowEndPartitionCallback(io.siddhi.core.query.output.callback.InsertIntoWindowEndPartitionCallback) Variable(io.siddhi.query.api.expression.Variable) Attribute(io.siddhi.query.api.definition.Attribute) InsertIntoWindowCallback(io.siddhi.core.query.output.callback.InsertIntoWindowCallback) UpdateStream(io.siddhi.query.api.execution.query.output.stream.UpdateStream) ZeroStreamEventConverter(io.siddhi.core.event.stream.converter.ZeroStreamEventConverter) UpdateTableCallback(io.siddhi.core.query.output.callback.UpdateTableCallback) DeleteStream(io.siddhi.query.api.execution.query.output.stream.DeleteStream) InsertIntoStreamEndPartitionCallback(io.siddhi.core.query.output.callback.InsertIntoStreamEndPartitionCallback) UpdateOrInsertTableCallback(io.siddhi.core.query.output.callback.UpdateOrInsertTableCallback) TableDefinition(io.siddhi.query.api.definition.TableDefinition) InsertIntoTableCallback(io.siddhi.core.query.output.callback.InsertIntoTableCallback) Window(io.siddhi.core.window.Window) Table(io.siddhi.core.table.Table) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEventConverter(io.siddhi.core.event.stream.converter.StreamEventConverter) ZeroStreamEventConverter(io.siddhi.core.event.stream.converter.ZeroStreamEventConverter) InsertIntoStream(io.siddhi.query.api.execution.query.output.stream.InsertIntoStream) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) InsertIntoStreamCallback(io.siddhi.core.query.output.callback.InsertIntoStreamCallback) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet) UpdateOrInsertStream(io.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) DeleteTableCallback(io.siddhi.core.query.output.callback.DeleteTableCallback) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) UpdateSet(io.siddhi.query.api.execution.query.output.stream.UpdateSet) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 23 with SiddhiAppValidationException

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

the class SingleClientDistributedSink method initTransport.

@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Map<String, String> deploymentProperties, List<Map<String, String>> destinationDeploymentProperties, Annotation sinkAnnotation, ConfigReader sinkConfigReader, DistributionStrategy strategy, String type, SiddhiAppContext siddhiAppContext) {
    final String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
    Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
    Set<String> allDynamicOptionKeys = findAllDynamicOptions(destinationOptionHolders);
    destinationOptionHolders.forEach(optionHolder -> {
        optionHolder.merge(sinkOptionHolder);
        allDynamicOptionKeys.forEach(optionKey -> {
            String optionValue = optionHolder.getOrCreateOption(optionKey, null).getValue();
            if (optionValue == null || optionValue.isEmpty()) {
                throw new SiddhiAppValidationException("Destination properties can only contain " + "non-empty static values.");
            }
            Option sinkOption = sinkOptionHolder.getOrAddStaticOption(optionKey, optionValue);
            sinkOption.addVariableValue(optionValue);
            destinationCount++;
        });
    });
    this.sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
    this.sink.initOnlyTransport(streamDefinition, sinkOptionHolder, sinkConfigReader, type, new SingleClientConnectionCallback(destinationCount, strategy), destinationDeploymentProperties.get(0), siddhiAppContext);
    if (!this.sink.getServiceDeploymentInfoList().isEmpty()) {
        ((ServiceDeploymentInfo) this.sink.getServiceDeploymentInfoList().get(0)).addDeploymentProperties(deploymentProperties);
    }
}
Also used : Extension(io.siddhi.query.api.extension.Extension) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) ServiceDeploymentInfo(io.siddhi.core.stream.ServiceDeploymentInfo)

Example 24 with SiddhiAppValidationException

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

the class SiddhiApp method addPartition.

public SiddhiApp addPartition(Partition partition) {
    if (partition == null) {
        throw new SiddhiAppValidationException("Partition should not be null");
    }
    String name = null;
    Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants.ANNOTATION_ELEMENT_NAME, partition.getAnnotations());
    if (element != null) {
        name = element.getValue();
    }
    if (name != null && executionElementNameList.contains(name)) {
        throw new SiddhiAppValidationException("Cannot add Partition as another Execution Element already " + "uses its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
    }
    executionElementNameList.add(name);
    this.executionElementList.add(partition);
    return this;
}
Also used : Element(io.siddhi.query.api.annotation.Element) ExecutionElement(io.siddhi.query.api.execution.ExecutionElement) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException)

Example 25 with SiddhiAppValidationException

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

the class SiddhiApp method defineTable.

public SiddhiApp defineTable(TableDefinition tableDefinition) {
    if (tableDefinition == null) {
        throw new SiddhiAppValidationException("Table Definition should not be null");
    } else if (tableDefinition.getId() == null) {
        throw new SiddhiAppValidationException("Table Id should not be null for Table Definition", tableDefinition.getQueryContextStartIndex(), tableDefinition.getQueryContextEndIndex());
    }
    checkDuplicateDefinition(tableDefinition);
    this.tableDefinitionMap.put(tableDefinition.getId(), tableDefinition);
    return this;
}
Also used : SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException)

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