Search in sources :

Example 51 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method test1.

@Test
public void test1() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream cseStream ( symbol " + "string, price int, volume float )");
    AssertJUnit.assertEquals(StreamDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 52 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method test2.

@Test
public void test2() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream `define` ( `string` " + "string, price int, volume float );");
    AssertJUnit.assertEquals(StreamDefinition.id("define").attribute("string", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 53 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class SiddhiAppParser method createFaultStreamDefinition.

private static StreamDefinition createFaultStreamDefinition(StreamDefinition streamDefinition) {
    List<Attribute> attributeList = streamDefinition.getAttributeList();
    StreamDefinition faultStreamDefinition = new StreamDefinition();
    faultStreamDefinition.setId(SiddhiConstants.FAULT_STREAM_PREFIX.concat(streamDefinition.getId()));
    for (Attribute attribute : attributeList) {
        faultStreamDefinition.attribute(attribute.getName(), attribute.getType());
    }
    faultStreamDefinition.attribute("_error", Attribute.Type.OBJECT);
    faultStreamDefinition.setQueryContextStartIndex(streamDefinition.getQueryContextStartIndex());
    faultStreamDefinition.setQueryContextEndIndex(streamDefinition.getQueryContextEndIndex());
    return faultStreamDefinition;
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Attribute(io.siddhi.query.api.definition.Attribute)

Example 54 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefinitionParserHelper method validateDefinition.

public static void validateDefinition(AbstractDefinition definition, ConcurrentMap<String, AbstractDefinition> streamDefinitionMap, ConcurrentMap<String, AbstractDefinition> tableDefinitionMap, ConcurrentMap<String, AbstractDefinition> windowDefinitionMap, ConcurrentMap<String, AbstractDefinition> aggregationDefinitionMap) {
    AbstractDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId());
    if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) {
        throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId());
    if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) {
        throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
    if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
        throw new DuplicateDefinitionException("Window Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
    if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
        throw new DuplicateDefinitionException("Aggregation Definition with same Aggregation Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(io.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) TableDefinition(io.siddhi.query.api.definition.TableDefinition) WindowDefinition(io.siddhi.query.api.definition.WindowDefinition)

Example 55 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class SiddhiApp method defineTrigger.

public SiddhiApp defineTrigger(TriggerDefinition triggerDefinition) {
    if (triggerDefinition == null) {
        throw new SiddhiAppValidationException("Trigger Definition should not be null");
    } else if (triggerDefinition.getId() == null) {
        throw new SiddhiAppValidationException("Trigger Id should not be null for Trigger Definition", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    StreamDefinition streamDefinition = StreamDefinition.id(triggerDefinition.getId()).attribute(SiddhiConstants.TRIGGERED_TIME, Attribute.Type.LONG);
    streamDefinition.setQueryContextStartIndex(triggerDefinition.getQueryContextStartIndex());
    streamDefinition.setQueryContextEndIndex(triggerDefinition.getQueryContextEndIndex());
    try {
        checkDuplicateDefinition(streamDefinition);
    } catch (DuplicateDefinitionException e) {
        throw new DuplicateDefinitionException("Trigger '" + triggerDefinition.getId() + "' cannot be defined as," + " " + e.getMessageWithOutContext(), e, triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    if (triggerDefinitionMap.containsKey(triggerDefinition.getId())) {
        throw new DuplicateDefinitionException("Trigger Definition with same Id '" + triggerDefinition.getId() + "' already exist '" + triggerDefinitionMap.get(triggerDefinition.getId()) + "', hence cannot add '" + triggerDefinition + "'", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    this.triggerDefinitionMap.put(triggerDefinition.getId(), triggerDefinition);
    this.streamDefinitionMap.put(streamDefinition.getId(), streamDefinition);
    return this;
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(io.siddhi.query.api.exception.DuplicateDefinitionException) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException)

Aggregations

StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)134 Test (org.testng.annotations.Test)116 SiddhiApp (io.siddhi.query.api.SiddhiApp)88 Event (io.siddhi.core.event.Event)86 Query (io.siddhi.query.api.execution.query.Query)85 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)84 SiddhiManager (io.siddhi.core.SiddhiManager)84 InputHandler (io.siddhi.core.stream.input.InputHandler)81 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)75 Attribute (io.siddhi.query.api.definition.Attribute)12 StreamCallback (io.siddhi.core.stream.output.StreamCallback)10 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)9 StreamEvent (io.siddhi.core.event.stream.StreamEvent)8 Partition (io.siddhi.query.api.execution.partition.Partition)7 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)5 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)5 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)4 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)4 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)4 SelectiveStreamEventConverter (io.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3