Siddhi query for event prior to another within time limit












0















I am trying to write a Siddhi query to detect if an event didn't happen prior to another within a time limit. The query I have to detect if 'X' didn't ever happen prior to 'Y' in the entire life of the siddhi application is:



from stream[value == 'Y']
and not stream[value == 'X']


I assumed adding a time constraint would work:



from stream[value == 'Y']
and not stream[value == 'X'] for 5 min


However, the 'for' statement never has any effect that I can see. This query is still triggered whether 'X' was 4 minutes ago or 6 minutes ago. I understand that a similar effect can be achieved by checking if 'Y' comes after 'X' within a time limit, but for my purposes I need to know the other way around.



Is this possible with Siddhi? If so can someone please provide a sample query that could achieve this?










share|improve this question























  • I do not understand why "checking if 'Y' comes after 'X' within a time limit" does not achieve your requirement. It is the proper way to write this plus you will get the same result. Can you please explain?

    – Tishan
    Nov 17 '18 at 18:17











  • @Tishan Because if X happens Y may or may not happen. But if Y happens X must have happened.

    – wearebob
    Nov 18 '18 at 19:43











  • Yes I understand that. Yet you only need to identify if there is a 'X' prior to 'Y'. In other words for every 'Y' you need to check for a prior 'X' and if 'X' is there emit a result. If you can confirm above is the requirement we can do it using a pattern query. Upon confirmation Ill post an answer with a sample query

    – Tishan
    Nov 19 '18 at 9:16











  • It might help if I explain the use case. We are trying to use Siddhi to loosely model a state machine by mostly using sequence queries. But to make sure a user doesn't enter the state machine at some random state in the middle, we need to verify for each state whether the previous state happened within some time limit. If our state machine is 'X' -> 'Y' then the only way we can verify they didn't start at 'Y' is making sure 'X' already happened.

    – wearebob
    Nov 19 '18 at 14:58
















0















I am trying to write a Siddhi query to detect if an event didn't happen prior to another within a time limit. The query I have to detect if 'X' didn't ever happen prior to 'Y' in the entire life of the siddhi application is:



from stream[value == 'Y']
and not stream[value == 'X']


I assumed adding a time constraint would work:



from stream[value == 'Y']
and not stream[value == 'X'] for 5 min


However, the 'for' statement never has any effect that I can see. This query is still triggered whether 'X' was 4 minutes ago or 6 minutes ago. I understand that a similar effect can be achieved by checking if 'Y' comes after 'X' within a time limit, but for my purposes I need to know the other way around.



Is this possible with Siddhi? If so can someone please provide a sample query that could achieve this?










share|improve this question























  • I do not understand why "checking if 'Y' comes after 'X' within a time limit" does not achieve your requirement. It is the proper way to write this plus you will get the same result. Can you please explain?

    – Tishan
    Nov 17 '18 at 18:17











  • @Tishan Because if X happens Y may or may not happen. But if Y happens X must have happened.

    – wearebob
    Nov 18 '18 at 19:43











  • Yes I understand that. Yet you only need to identify if there is a 'X' prior to 'Y'. In other words for every 'Y' you need to check for a prior 'X' and if 'X' is there emit a result. If you can confirm above is the requirement we can do it using a pattern query. Upon confirmation Ill post an answer with a sample query

    – Tishan
    Nov 19 '18 at 9:16











  • It might help if I explain the use case. We are trying to use Siddhi to loosely model a state machine by mostly using sequence queries. But to make sure a user doesn't enter the state machine at some random state in the middle, we need to verify for each state whether the previous state happened within some time limit. If our state machine is 'X' -> 'Y' then the only way we can verify they didn't start at 'Y' is making sure 'X' already happened.

    – wearebob
    Nov 19 '18 at 14:58














0












0








0








I am trying to write a Siddhi query to detect if an event didn't happen prior to another within a time limit. The query I have to detect if 'X' didn't ever happen prior to 'Y' in the entire life of the siddhi application is:



from stream[value == 'Y']
and not stream[value == 'X']


I assumed adding a time constraint would work:



from stream[value == 'Y']
and not stream[value == 'X'] for 5 min


However, the 'for' statement never has any effect that I can see. This query is still triggered whether 'X' was 4 minutes ago or 6 minutes ago. I understand that a similar effect can be achieved by checking if 'Y' comes after 'X' within a time limit, but for my purposes I need to know the other way around.



Is this possible with Siddhi? If so can someone please provide a sample query that could achieve this?










share|improve this question














I am trying to write a Siddhi query to detect if an event didn't happen prior to another within a time limit. The query I have to detect if 'X' didn't ever happen prior to 'Y' in the entire life of the siddhi application is:



from stream[value == 'Y']
and not stream[value == 'X']


I assumed adding a time constraint would work:



from stream[value == 'Y']
and not stream[value == 'X'] for 5 min


However, the 'for' statement never has any effect that I can see. This query is still triggered whether 'X' was 4 minutes ago or 6 minutes ago. I understand that a similar effect can be achieved by checking if 'Y' comes after 'X' within a time limit, but for my purposes I need to know the other way around.



Is this possible with Siddhi? If so can someone please provide a sample query that could achieve this?







cep siddhi stream-processing complex-event-processing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 23:55









wearebobwearebob

156




156













  • I do not understand why "checking if 'Y' comes after 'X' within a time limit" does not achieve your requirement. It is the proper way to write this plus you will get the same result. Can you please explain?

    – Tishan
    Nov 17 '18 at 18:17











  • @Tishan Because if X happens Y may or may not happen. But if Y happens X must have happened.

    – wearebob
    Nov 18 '18 at 19:43











  • Yes I understand that. Yet you only need to identify if there is a 'X' prior to 'Y'. In other words for every 'Y' you need to check for a prior 'X' and if 'X' is there emit a result. If you can confirm above is the requirement we can do it using a pattern query. Upon confirmation Ill post an answer with a sample query

    – Tishan
    Nov 19 '18 at 9:16











  • It might help if I explain the use case. We are trying to use Siddhi to loosely model a state machine by mostly using sequence queries. But to make sure a user doesn't enter the state machine at some random state in the middle, we need to verify for each state whether the previous state happened within some time limit. If our state machine is 'X' -> 'Y' then the only way we can verify they didn't start at 'Y' is making sure 'X' already happened.

    – wearebob
    Nov 19 '18 at 14:58



















  • I do not understand why "checking if 'Y' comes after 'X' within a time limit" does not achieve your requirement. It is the proper way to write this plus you will get the same result. Can you please explain?

    – Tishan
    Nov 17 '18 at 18:17











  • @Tishan Because if X happens Y may or may not happen. But if Y happens X must have happened.

    – wearebob
    Nov 18 '18 at 19:43











  • Yes I understand that. Yet you only need to identify if there is a 'X' prior to 'Y'. In other words for every 'Y' you need to check for a prior 'X' and if 'X' is there emit a result. If you can confirm above is the requirement we can do it using a pattern query. Upon confirmation Ill post an answer with a sample query

    – Tishan
    Nov 19 '18 at 9:16











  • It might help if I explain the use case. We are trying to use Siddhi to loosely model a state machine by mostly using sequence queries. But to make sure a user doesn't enter the state machine at some random state in the middle, we need to verify for each state whether the previous state happened within some time limit. If our state machine is 'X' -> 'Y' then the only way we can verify they didn't start at 'Y' is making sure 'X' already happened.

    – wearebob
    Nov 19 '18 at 14:58

















I do not understand why "checking if 'Y' comes after 'X' within a time limit" does not achieve your requirement. It is the proper way to write this plus you will get the same result. Can you please explain?

– Tishan
Nov 17 '18 at 18:17





I do not understand why "checking if 'Y' comes after 'X' within a time limit" does not achieve your requirement. It is the proper way to write this plus you will get the same result. Can you please explain?

– Tishan
Nov 17 '18 at 18:17













@Tishan Because if X happens Y may or may not happen. But if Y happens X must have happened.

– wearebob
Nov 18 '18 at 19:43





@Tishan Because if X happens Y may or may not happen. But if Y happens X must have happened.

– wearebob
Nov 18 '18 at 19:43













Yes I understand that. Yet you only need to identify if there is a 'X' prior to 'Y'. In other words for every 'Y' you need to check for a prior 'X' and if 'X' is there emit a result. If you can confirm above is the requirement we can do it using a pattern query. Upon confirmation Ill post an answer with a sample query

– Tishan
Nov 19 '18 at 9:16





Yes I understand that. Yet you only need to identify if there is a 'X' prior to 'Y'. In other words for every 'Y' you need to check for a prior 'X' and if 'X' is there emit a result. If you can confirm above is the requirement we can do it using a pattern query. Upon confirmation Ill post an answer with a sample query

– Tishan
Nov 19 '18 at 9:16













It might help if I explain the use case. We are trying to use Siddhi to loosely model a state machine by mostly using sequence queries. But to make sure a user doesn't enter the state machine at some random state in the middle, we need to verify for each state whether the previous state happened within some time limit. If our state machine is 'X' -> 'Y' then the only way we can verify they didn't start at 'Y' is making sure 'X' already happened.

– wearebob
Nov 19 '18 at 14:58





It might help if I explain the use case. We are trying to use Siddhi to loosely model a state machine by mostly using sequence queries. But to make sure a user doesn't enter the state machine at some random state in the middle, we need to verify for each state whether the previous state happened within some time limit. If our state machine is 'X' -> 'Y' then the only way we can verify they didn't start at 'Y' is making sure 'X' already happened.

– wearebob
Nov 19 '18 at 14:58












1 Answer
1






active

oldest

votes


















0














Based on your comment I am composing below answer.
Sequence construct in Siddhi will guarantee that no one can enter the state flow at a random point. As an example let's take below sample sequence query.



from every e1=InputStream[state='X'], e2=InputStream[state'Y']
select e1.state as initialState, e2.state as finalState
insert into NextStream;


So in here we are mandating X followed by a consecutive Y. If Y occurs before X sequence construct will handle that and discard Y. So whatever goes into NextStream is guaranteed to satisfy x -> Y state transition.



More relaxed construct of sequence is pattern. It is same as sequence while relaxing the consecutive arrival requirement. Hope this helps!!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346871%2fsiddhi-query-for-event-prior-to-another-within-time-limit%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Based on your comment I am composing below answer.
    Sequence construct in Siddhi will guarantee that no one can enter the state flow at a random point. As an example let's take below sample sequence query.



    from every e1=InputStream[state='X'], e2=InputStream[state'Y']
    select e1.state as initialState, e2.state as finalState
    insert into NextStream;


    So in here we are mandating X followed by a consecutive Y. If Y occurs before X sequence construct will handle that and discard Y. So whatever goes into NextStream is guaranteed to satisfy x -> Y state transition.



    More relaxed construct of sequence is pattern. It is same as sequence while relaxing the consecutive arrival requirement. Hope this helps!!






    share|improve this answer




























      0














      Based on your comment I am composing below answer.
      Sequence construct in Siddhi will guarantee that no one can enter the state flow at a random point. As an example let's take below sample sequence query.



      from every e1=InputStream[state='X'], e2=InputStream[state'Y']
      select e1.state as initialState, e2.state as finalState
      insert into NextStream;


      So in here we are mandating X followed by a consecutive Y. If Y occurs before X sequence construct will handle that and discard Y. So whatever goes into NextStream is guaranteed to satisfy x -> Y state transition.



      More relaxed construct of sequence is pattern. It is same as sequence while relaxing the consecutive arrival requirement. Hope this helps!!






      share|improve this answer


























        0












        0








        0







        Based on your comment I am composing below answer.
        Sequence construct in Siddhi will guarantee that no one can enter the state flow at a random point. As an example let's take below sample sequence query.



        from every e1=InputStream[state='X'], e2=InputStream[state'Y']
        select e1.state as initialState, e2.state as finalState
        insert into NextStream;


        So in here we are mandating X followed by a consecutive Y. If Y occurs before X sequence construct will handle that and discard Y. So whatever goes into NextStream is guaranteed to satisfy x -> Y state transition.



        More relaxed construct of sequence is pattern. It is same as sequence while relaxing the consecutive arrival requirement. Hope this helps!!






        share|improve this answer













        Based on your comment I am composing below answer.
        Sequence construct in Siddhi will guarantee that no one can enter the state flow at a random point. As an example let's take below sample sequence query.



        from every e1=InputStream[state='X'], e2=InputStream[state'Y']
        select e1.state as initialState, e2.state as finalState
        insert into NextStream;


        So in here we are mandating X followed by a consecutive Y. If Y occurs before X sequence construct will handle that and discard Y. So whatever goes into NextStream is guaranteed to satisfy x -> Y state transition.



        More relaxed construct of sequence is pattern. It is same as sequence while relaxing the consecutive arrival requirement. Hope this helps!!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 9:23









        TishanTishan

        68049




        68049






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346871%2fsiddhi-query-for-event-prior-to-another-within-time-limit%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)