Is it possible to use the Flink CEP library on its...
# random
t
Is it possible to use the Flink CEP library on its own? The Flink CEP patterns are implemented as a state machine, can a sequence of objects be tested against this pattern outside the Flink context?
n
You could refer to
org.apache.flink.cep.nfa.compiler.NFACompilerTest
.
t
I was actually looking at that, and got the idea to use it from that class. But not sure if this is intended to be used in this way. I'm not seeing an @Internal annotation or anything, so guess it can be used,
Will give it a shot, thanks @Nicholas Jiang
n
flink-cep module has little annotation. You could regard the interface as public.
BTW, if you have any question on CEP, I will give you some answer and suggestion.
🙏 1
t
My main question is how can I add and remove CEP patterns dynamically? @Nicholas Jiang As far as I know, this is not yet supported in Flink. Hence, my approach so far has been to use Flink to read 2 sources : my business events, and new patterns. Then I'm using a broadcast to broadcast patterns to all operator instances, and then have an operator that is calling an inhouse built pattern matcher on the business events. I do not like building my own pattern matcher when Flink CEP already exists, so seeing how I can use this library in a dynamic way.
By dynamic I mean add and remove patterns without redeploying.
n
You could follow the FLIP-200, in which proposal the pattern is serializable JSON string.
IMO, you could modify the
Pattern
class to implement the
Serializable
interface, in which implementation you need to modify related class to implement the
Serializable
.
t
Thanks for this information.
So from my understanding, most of the work will be to replicate what CEPOperator is doing to handle more than 1 pattern, by keeping a list of NFA and NFA states and iterate over them for each event.
n
Right. Like
PatternProcessorOperator
, which handles the
Pattern
list sent from the
PatternProcessorCoorindator
.
t
Looks like the ververica is a commercial feature and doesn't have the entire codebase.
Will give this a shot, and see how it goes. Thanks for your help.
n
Yes. But the brief changes are mentioned in FLiP-200. You can implement according to this by yourself, which works are small.
y
@Nicholas Jiang thanks, very helpful!
t
Is there any implementation documentation available somewhere for CEPOperator? Seeing all kinds of states being maintained and updated - not sure I understand the code well. @Nicholas Jiang
n
No. What is your understand for CEPOperator?
t
I do not really know what is the difference between the computationStates and partialMatches? Do I have to keep both in a my custom oerpator?
n
ComputationStates stores the matched result and partialMatches stores the partial result of pattern match.