io.siddhi.query.api.exception.SiddhiAppValidationException Java Examples

The following examples show how to use io.siddhi.query.api.exception.SiddhiAppValidationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartitionQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testDuplicatePartitionQuery() {
    Partition partition = Partition.partition().
            with("StockStream", Expression.variable("symbol")).
            with("StockStream", Expression.variable("symbol")).
            with("StockStream2",
                    Partition.range("LessValue",
                            Expression.compare(
                                    Expression.value(7),
                                    Compare.Operator.GREATER_THAN,
                                    Expression.variable("price"))
                    ),
                    Partition.range("HighValue",
                            Expression.compare(
                                    Expression.value(9.5),
                                    Compare.Operator.LESS_THAN,
                                    Expression.variable("price1"))
                    )
            );
}
 
Example #2
Source File: StringListSizeFunctionExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for StringListSizeFunctionExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors  the executors of each function parameter
 * @param configReader                  the config reader for the Siddhi app
 * @param siddhiQueryContext            the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 1) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:listSize() function, "
                + "required 1, but found " + attributeExpressionExecutors.length);
    }

    Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType();
    if (attributeType != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the argument of str:listSize() "
                + "function, required " + Attribute.Type.STRING + ", but found " + attributeType.toString());
    }
    return null;
}
 
Example #3
Source File: PolicyExecutionPlannerImpl.java    From eagle with Apache License 2.0 6 votes vote down vote up
private void retrievePartition(StreamPartition partition) {
    if (partition == null) {
        return;
    }

    if (!effectivePartitions.containsKey(partition.getStreamId())) {
        effectivePartitions.put(partition.getStreamId(), partition);
    } else if (!effectivePartitions.get(partition.getStreamId()).equals(partition)) {
        StreamPartition existingPartition = effectivePartitions.get(partition.getStreamId());
        // If same Type & Columns but different sort spec, then use larger
        if (existingPartition.getType().equals(partition.getType())
            && ListUtils.isEqualList(existingPartition.getColumns(), partition.getColumns())
            && partition.getSortSpec().getWindowPeriodMillis() > existingPartition.getSortSpec().getWindowPeriodMillis()
            || existingPartition.getType().equals(StreamPartition.Type.SHUFFLE)) {
            effectivePartitions.put(partition.getStreamId(), partition);
        } else {
            // Throw exception as it unable to conflict effectivePartitions on same stream will not be able to run in distributed mode
            throw new SiddhiAppValidationException("You have incompatible partitions on stream " + partition.getStreamId()
                + ": [1] " + effectivePartitions.get(partition.getStreamId()).toString() + " [2] " + partition.toString() + "");
        }
    }
}
 
Example #4
Source File: EqualsIgnoreCaseExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for EqualsIgnoreCaseExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors the executors of each function parameter
 * @param configReader                 the config reader for the Siddhi app
 * @param siddhiQueryContext           the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:equalsIgnoreCase() "
                + "function, required 2, but found " + attributeExpressionExecutors.length);
    }
    if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the first argument of "
                + "str:equalsIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[0].getReturnType().toString());
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the second argument of "
                + "str:equalsIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[1].getReturnType().toString());
    }
    return null;
}
 
Example #5
Source File: RegexpIgnoreCaseFunctionExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for EqualsIgnoreCaseExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors the executors of each function parameter
 * @param configReader                 the config reader for the Siddhi app
 * @param siddhiQueryContext           the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:regexpIgnoreCase() function, "
                + "required 2, but found " + attributeExpressionExecutors.length);
    }
    if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the first argument of "
                + "str:regexpIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[0].getReturnType().toString());
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the second argument of "
                + "str:regexpIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[1].getReturnType().toString());
    }
    if (attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor) {
        String regexConstant = (String) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        patternConstant = Pattern.compile(regexConstant, Pattern.CASE_INSENSITIVE);
        isRegexConstant = true;
    }
    return null;
}
 
Example #6
Source File: ContainsIgnoreCaseExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for ContainsIgnoreCaseExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors the executors of each function parameter
 * @param configReader                 the config reader for the Siddhi app
 * @param siddhiQueryContext           the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:containsIgnoreCase() "
                + "function, required 2, but found " + attributeExpressionExecutors.length);
    }
    if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the first argument of "
                + "str:containsIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[0].getReturnType().toString());
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the second argument of "
                + "str:containsIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[1].getReturnType().toString());
    }
    return null;
}
 
Example #7
Source File: IndexTableTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void indexTableTest32() throws InterruptedException {
    log.info("indexTableTest32");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Index('symbol') " +
            "@Index('symbol') " +
            "define table StockTable (symbol string, price float, volume long); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from StockStream " +
            "insert into StockTable ;" +
            "";

    SiddhiAppRuntime siddhiAppRuntime = null;
    try {
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    } finally {
        if (siddhiAppRuntime != null) {
            siddhiAppRuntime.shutdown();
        }
    }
}
 
Example #8
Source File: KafkaSourceTestCase.java    From siddhi-io-kafka with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class,
        dependsOnMethods = "testKafkaMultipleTopicWithThreadingPerPartitionSource")
public void testKafkaWithoutThreadingOptionSource() throws InterruptedException {
    try {
        log.info("-------------------------------------------------------------------------------------------");
        log.info("Creating test for without any threading option defined.");
        log.info("-------------------------------------------------------------------------------------------");
        String topics[] = new String[]{"no_threading_option_topic"};
        KafkaTestUtil.createTopic(topics, 2);
        SiddhiManager siddhiManager = new SiddhiManager();
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
                "@App:name('TestExecutionPlan') " +
                        "define stream BarStream (symbol string, price float, volume long); " +
                        "@info(name = 'query1') " +
                        "@source(type='kafka', topic.list='no_threading_option_topic', partition.no.list='0,1,2', "
                        + "group.id='test_no_threading_option_topic'," +
                        "@map(type='xml'))" +
                        "Define stream FooStream (symbol string, price float, volume long);" +
                        "from FooStream select symbol, price, volume insert into BarStream;");
        siddhiAppRuntime.start();
        KafkaTestUtil.deleteTopic(topics);
        siddhiAppRuntime.shutdown();
    } catch (ZkTimeoutException ex) {
        log.warn("No zookeeper may not be available.", ex);
    }
}
 
Example #9
Source File: KafkaSourceTestCase.java    From siddhi-io-kafka with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class,
        dependsOnMethods = "testKafkaMultipleTopic_MultiplePartition_AllPartitionSubscribe_Source")
public void testKafkaWithoutBootstrapServerSource() throws InterruptedException {
    try {
        log.info("-------------------------------------------------------------------------------------------");
        log.info("Creating test for without any bootstrap servers defined.");
        log.info("-------------------------------------------------------------------------------------------");
        String topics[] = new String[]{"no_bootstrap_server_topic"};
        KafkaTestUtil.createTopic(topics, 2);
        SiddhiManager siddhiManager = new SiddhiManager();
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
                "@App:name('TestExecutionPlan') " +
                        "define stream BarStream (symbol string, price float, volume long); " +
                        "@info(name = 'query1') " +
                        "@source(type='kafka', topic.list='no_bootstrap_server_topic', partition.no.list='0,1,2', "
                        + "group.id='test', threading.option='single.thread'," +
                        "@map(type='xml'))" +
                        "Define stream FooStream (symbol string, price float, volume long);" +
                        "from FooStream select symbol, price, volume insert into BarStream;");
        siddhiAppRuntime.start();
        KafkaTestUtil.deleteTopic(topics);
        siddhiAppRuntime.shutdown();
    } catch (ZkTimeoutException ex) {
        log.warn("No zookeeper may not be available.", ex);
    }
}
 
Example #10
Source File: KafkaSourceTestCase.java    From siddhi-io-kafka with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class,
        dependsOnMethods = "testTransportCreationDisabledProperty")
public void testKafkaWithoutTopicSource() {
    try {
        log.info("-------------------------------------------------------------------------------------------");
        log.info("Creating test for without topic");
        log.info("-------------------------------------------------------------------------------------------");
        SiddhiManager siddhiManager = new SiddhiManager();
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
                "@App:name('TestExecutionPlan') " +
                        "define stream BarStream (symbol string, price float, volume long); " +
                        "@info(name = 'query1') " +
                        "@source(type='kafka', group.id='test', threading.option='single.thread', "
                        + "bootstrap.servers='localhost:9092'," +
                        "@map(type='xml'))" +
                        "Define stream FooStream (symbol string, price float, volume long);" +
                        "from FooStream select symbol, price, volume insert into BarStream;");
        siddhiAppRuntime.start();
        siddhiAppRuntime.shutdown();
    } catch (ZkTimeoutException ex) {
        log.warn("No zookeeper may not be available.", ex);
    }
}
 
Example #11
Source File: DefaultFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors,
                            ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        // check whether all the arguments passed
        throw new SiddhiAppValidationException("Invalid no of parameters passed to default() function, " +
                "it require only 2 (attribute, default value) , "
                + "but found "
                + attributeExpressionExecutors.length);
    } else if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
        throw new SiddhiAppValidationException("Invalid parameter passed to default() function, " +
                "this only consumes constants, but found "
                + attributeExpressionExecutors[1].getClass().getName());

    } else if ((attributeExpressionExecutors[0].getReturnType() != attributeExpressionExecutors[1]
            .getReturnType())) {
        throw new SiddhiAppValidationException("Both attribute and default value parameters need to be of "
                + "same return type but they are of " +
                attributeExpressionExecutors[0].getReturnType() + "and" +
                attributeExpressionExecutors[1].getReturnType());
    }
    returnType = attributeExpressionExecutors[0].getReturnType();
    return null;
}
 
Example #12
Source File: StringSubtractFunctionExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for StringSubtractFunctionExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors  the executors of each function parameter
 * @param configReader                  the config reader for the Siddhi app
 * @param siddhiQueryContext            the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:subtract() function, "
                + "required 2, but found " + attributeExpressionExecutors.length);
    }

    Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType();
    if (attributeType != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the argument of str:subtract() "
                + "function, required " + Attribute.Type.STRING + ", but found " + attributeType.toString());
    }
    return null;
}
 
Example #13
Source File: OptionHolder.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public String validateAndGetStaticValue(String optionKey) {
    Option option = options.get(optionKey);
    if (option != null) {
        if (!option.isStatic()) {
            throw new SiddhiAppValidationException("'" + optionKey + "' is defined as a 'dynamic' option " +
                    "but it has to be a 'static' option for the " +
                    extension.namespace() + ":" +
                    extension.name() + " configuration.");
        }
        return option.getValue();
    } else {
        throw new SiddhiAppValidationException("'" + optionKey + "' 'static' option is not " +
                "defined in the configuration of " +
                extension.namespace() + ":" + extension.name() + ".");
    }
}
 
Example #14
Source File: Partition.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public Partition addQuery(Query query) {
    if (query == null) {
        throw new SiddhiAppValidationException("Query should not be null");
    }
    String name = null;
    Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants
            .ANNOTATION_ELEMENT_NAME, query.getAnnotations());
    if (element != null) {
        name = element.getValue();
    }
    if (name != null && queryNameList.contains(name)) {
        throw new SiddhiAppValidationException("Cannot add Query as another Execution Element already uses " +
                "its name=" + name + " within the same Partition",
                element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
    }
    queryNameList.add(name);
    this.queryList.add(query);
    return this;
}
 
Example #15
Source File: IncrementalStartTimeEndTimeFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) {
            throw new SiddhiAppValidationException("Only string values are supported for single within clause "
                    + "but found, " + attributeExpressionExecutors[0].getReturnType());
        }
    } else if (attributeExpressionExecutors.length == 2) {
        if (!(attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG
                || attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING)) {
            throw new SiddhiAppValidationException(
                    "Only string and long types are supported as first value of within clause");
        }
        if (!(attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG
                || attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING)) {
            throw new SiddhiAppValidationException(
                    "Only string and long types are supported as second value of within clause");
        }
    } else {
        throw new SiddhiAppValidationException("incrementalAggregator:startTimeEndTime() function accepts " +
                "only one or two arguments, but found " + attributeExpressionExecutors.length);
    }
    return null;
}
 
Example #16
Source File: JoinTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void joinTest13() throws InterruptedException {
    log.info("Join test13");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream cseEventStream (symbol string, price float, volume int); " +
            "define stream twitterStream (user string, tweet string, symbol string); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " +
            "on cseEventStream.symbol== twitterStream.symbol " +
            "select * " +
            "insert into outputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        siddhiAppRuntime.start();
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
 
Example #17
Source File: IncrementalAggregateBaseTimeFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("incrementalAggregator:getAggregationStartTime() function accepts " +
                "two arguments, but found " + attributeExpressionExecutors.length);
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Second argument of " +
                "incrementalAggregator:getAggregationStartTime() function accepts should be of type 'STRING', " +
                "but found '" + attributeExpressionExecutors[1].getReturnType() + "'.");
    }
    this.timeZone = siddhiQueryContext.getSiddhiContext().getConfigManager().extractProperty(SiddhiConstants
            .AGG_TIME_ZONE);
    if (timeZone == null) {
        this.timeZone = SiddhiConstants.AGG_TIME_ZONE_DEFAULT;
    }
    return null;
}
 
Example #18
Source File: SiddhiApp.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public SiddhiApp addQuery(Query query) {
    if (query == null) {
        throw new SiddhiAppValidationException("Query should not be null");
    }
    String name = null;
    Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants
            .ANNOTATION_ELEMENT_NAME, query.getAnnotations());
    if (element != null) {
        name = element.getValue();
    }
    if (name != null && executionElementNameList.contains(name)) {
        throw new SiddhiAppValidationException(
                "Cannot add Query as another Execution Element already uses " + "its name=" + name,
                element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
    }
    executionElementNameList.add(name);
    this.executionElementList.add(query);
    return this;
}
 
Example #19
Source File: SiddhiApp.java    From siddhi with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #20
Source File: SiddhiApp.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public SiddhiApp defineFunction(FunctionDefinition functionDefinition) {
    if (functionDefinition == null) {
        throw new SiddhiAppValidationException("Function Definition should not be null");
    } else if (functionDefinition.getId() == null) {
        throw new SiddhiAppValidationException("Function Id should not be null for Function Definition",
                functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex());
    } else if (functionDefinition.getReturnType() == null) {
        throw new SiddhiAppValidationException("Return type should not be null for Function Definition",
                functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex());
    } else if (functionDefinition.getBody() == null) {
        throw new SiddhiAppValidationException("Body should not be null for Function Definition",
                functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex());
    } else if (functionDefinition.getLanguage() == null) {
        throw new SiddhiAppValidationException("Language should not be null for Function Definition",
                functionDefinition.getQueryContextStartIndex(), functionDefinition.getQueryContextEndIndex());
    }
    checkDuplicateFunctionExist(functionDefinition);
    this.functionDefinitionMap.put(functionDefinition.getId(), functionDefinition);
    return this;
}
 
Example #21
Source File: PatternQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPatternQuery17() {
    Query query = Query.query();
    query.from(
            InputStream.patternStream(
                    State.next(
                            State.stream(InputStream.stream("e1", "Stream1")
                                    .filter(Expression.compare(Expression.variable("price"),
                                            Compare.Operator.GREATER_THAN_EQUAL,
                                            Expression.value(30)))),
                            State.next(State.logicalNot(State.stream(InputStream.stream("e1", "Stream1")
                                            .filter(Expression.compare(Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.value(20)))), new TimeConstant(1000)),
                                    State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.variable("price").ofStream("e1")))))
                    )
            )
    );
}
 
Example #22
Source File: ConvertFunctionTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void convertFunctionTest6() throws InterruptedException {
    log.info("convert function test 6");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "" +
            "" +
            "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " +
            "bool) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from typeStream " +
            "select convert(typeS,string) as valueB1 " +
            "insert into outputStream ;";

    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
 
Example #23
Source File: TimeBatchWindowProcessor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private void initTimeParameter(ExpressionExecutor attributeExpressionExecutor) {
    if (attributeExpressionExecutor instanceof ConstantExpressionExecutor) {
        if (attributeExpressionExecutor.getReturnType() == Attribute.Type.INT) {
            timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutor)
                    .getValue();

        } else if (attributeExpressionExecutor.getReturnType() == Attribute.Type.LONG) {
            timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutor)
                    .getValue();
        } else {
            throw new SiddhiAppValidationException("TimeBatch window's window.time (1st) parameter 'window.time' " +
                    "should be either int or long, but found " + attributeExpressionExecutor.getReturnType());
        }
    } else {
        throw new SiddhiAppValidationException("TimeBatch window's window.time (1st) parameter 'window.time' " +
                "should be a constant but found a dynamic attribute " +
                attributeExpressionExecutor.getClass().getCanonicalName());
    }
}
 
Example #24
Source File: DelayWindowProcessor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    this.siddhiQueryContext = siddhiQueryContext;
    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT ||
                    attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                delayInMilliSeconds = Long.parseLong(((ConstantExpressionExecutor) attributeExpressionExecutors[0])
                        .getValue().toString());
            } else {
                throw new SiddhiAppValidationException("Delay window's parameter attribute should be either " +
                        "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Delay window should have constant parameter attribute but " +
                    "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else {
        throw new SiddhiAppValidationException("Delay window should only have one parameter (<int|long|time> " +
                "delayTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    return () -> new DelayedWindowState(streamEventClonerHolder);
}
 
Example #25
Source File: PartitionedDistributionStrategy.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }

}
 
Example #26
Source File: IndexTableTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void indexTableTest31() throws InterruptedException {
    log.info("indexTableTest31");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Index('symbol', 'volume') " +
            "define table StockTable (symbol string, price float, volume long); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from StockStream " +
            "insert into StockTable ;" +
            "";

    SiddhiAppRuntime siddhiAppRuntime = null;
    try {
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    } finally {
        if (siddhiAppRuntime != null) {
            siddhiAppRuntime.shutdown();
        }
    }
}
 
Example #27
Source File: IfThenElseFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors,
                            ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 3) {
        // check whether all the arguments passed
        throw new SiddhiAppValidationException("Invalid no of arguments passed to ifThenElse() function, " +
                "required only 3, but found " + attributeExpressionExecutors.length);
    } else if (!attributeExpressionExecutors[0].getReturnType().equals(Attribute.Type.BOOL)) {
        // check whether first argument Boolean or not
        throw new SiddhiAppValidationException("Input type of if in ifThenElse function should be of " +
                "type BOOL, but found " + attributeExpressionExecutors[0].getReturnType());
    } else if (!attributeExpressionExecutors[1].getReturnType().equals(
            attributeExpressionExecutors[2].getReturnType())) {
        // check whether second and thirds argument's return type are equivalent.
        throw new SiddhiAppValidationException("Input type of then in ifThenElse function and else in " +
                "ifThenElse function should be of equivalent type. but found then type: " +
                attributeExpressionExecutors[1].getReturnType() + " and else type: " +
                attributeExpressionExecutors[2].getReturnType());
    } else {
        returnType = attributeExpressionExecutors[1].getReturnType();
    }
    return null;
}
 
Example #28
Source File: LengthWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length == 1) {
        length = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
    } else {
        throw new SiddhiAppValidationException("Length window should only have one parameter (<int> " +
                "window.length), but found " + attributeExpressionExecutors.length + " input parameters.");
    }
    return () -> new WindowState();
}
 
Example #29
Source File: TimeWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<WindowState> init(ExpressionExecutor[] attributeExpressionExecutors,
                                         ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    this.siddhiQueryContext = siddhiQueryContext;

    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0])
                        .getValue();

            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0])
                        .getValue();
            } else {
                throw new SiddhiAppValidationException("Time window's parameter attribute should be either " +
                        "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " +
                    "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else {
        throw new SiddhiAppValidationException("Time window should only have one parameter (<int|long|time> " +
                "windowTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    return () -> new WindowState(streamEventClonerHolder);
}
 
Example #30
Source File: MaximumFunctionExecutor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    Attribute.Type attributeTypeOne = attributeExpressionExecutors[0].getReturnType();
    if (!((attributeTypeOne == Attribute.Type.DOUBLE) || (attributeTypeOne == Attribute.Type.INT) ||
            (attributeTypeOne == Attribute.Type.FLOAT) || (attributeTypeOne == Attribute.Type.LONG))) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the argument" + 1 +
                " of maximum() function, " +
                "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG +
                " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE +
                ", but found " + attributeTypeOne.toString());
    }
    for (int i = 1; i < attributeExpressionExecutors.length; i++) {
        Attribute.Type attributeType = attributeExpressionExecutors[i].getReturnType();
        if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) ||
                (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) {
            throw new SiddhiAppValidationException("Invalid parameter type found for the argument" + i +
                    " of maximum() function, " +
                    "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG +
                    " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE +
                    ", but found " + attributeType.toString());
        }
        if (attributeTypeOne != attributeType) {
            throw new SiddhiAppValidationException("Invalid parameter type found for arguments  " +
                    "of maximum() function, all parameters should be of same type, but found " +
                    attributeTypeOne + " and " + attributeExpressionExecutors[i].getReturnType());
        }

    }
    returnType = attributeTypeOne;
    return null;
}