From a32f515cdb0021ed601cb4f25906cfe0e8c0435c Mon Sep 17 00:00:00 2001 From: Jonathan L Kaus Date: Wed, 28 Mar 2018 20:26:59 +0000 Subject: [PATCH] Update TextFilter operator to support inverted matching --- .../TextFilter/TextFilter.xml | 49 ++++++++++++++++--- .../TextFilter/TextFilter_cpp.cgt | 7 +++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter.xml b/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter.xml index bc54b9d0..a8caae07 100644 --- a/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter.xml +++ b/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter.xml @@ -23,17 +23,38 @@ others. All Rights Reserved. false inputTextAttr - Specifies the input attribute(s) containing the text that the filter will be applied against. -The supported data types for this attribute are `rstring` and `list<rstring>`. + +Specifies the input attribute(s) containing the text that the filter will be +applied against. The supported data types for this attribute are `rstring` +and `list<rstring>`. + false false Expression 1 + + invertMatch + +If set to true, the meaning of the filter is basically inverted. If any of the +specified input attribute(s) of a tuple match the current state of the filter, +the tuple will NOT be passed through. Only tuples that do not match the filter +will be passed through. The default setting is false, where only tuples that DO +match the filter are passed through. + + true + false + Constant + boolean + 1 + - Ingests tuples containing text and filters the data based on the text. The `inputTextAttr` parameter specifies the attribute containing the text. + +Ingests tuples containing text and filters the data based on the text. The +`inputTextAttr` parameter specifies the attribute containing the text. + false NonWindowed @@ -43,9 +64,17 @@ The supported data types for this attribute are `rstring` and `list<rstring>` false - Control port that takes in tuples containing IPv4 addresses in CIDR format for use in the filter operation. All packets that match one of the input address ranges are passed through the filter. + +Control port that takes in tuples containing regex fragments for use in the +filter operation. By default, all packets that match any of the fragments are +passed through the filter. -This control port can be used to dynamically update the list of addresses being filtered. Each time a tuple is received containing an address it is saved in a temporary list that is applied after a window punctuation is received. This input port expects a tuple containing a single attribute of type `rstring` which is an IPv4 address in CIDR format (e.g. 192.168.0.0/24). +This control port can be used to dynamically update the list of regex fragments +in the filter. Each time a tuple is received containing a fragment it is added +to a temporary regex string being built up, which is compiled and applied after +a window punctuation is received. The regex fragments should be in ERE form, +and are combined with a simple '|'. + false NonWindowed @@ -57,7 +86,15 @@ This control port can be used to dynamically update the list of addresses being - Submits a tuple for each input tuple received on input port 0 if one or more of the attributes defined in the inputIPAttr paramater match an IPv4 address that has been input on the control port. + +By default, submits a tuple for each input tuple received on input port 0 if one +or more of the attributes defined in the inputTextAttr parameter match the regex +built up from the fragments sent in on the control port. + +If invertMatch is set, submits a tuple for each input tuple received on input +port 0 only if NONE of the attributes defined on the inputTextAttr parameter +match the built up regex. + Nonexistent true true diff --git a/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter_cpp.cgt b/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter_cpp.cgt index 6faa604d..dd67c863 100644 --- a/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter_cpp.cgt +++ b/com.ibm.streamsx.network/com.ibm.streamsx.network.filter/TextFilter/TextFilter_cpp.cgt @@ -40,6 +40,9 @@ if(defined $inputPort1) { # get C++ expressions for getting the values of this operator's parameters my $inputTextAttrParamCppValue = $model->getParameterByName("inputTextAttr")->getValueAt(0)->getCppExpression(); +my $invertMatch = $model->getParameterByName("invertMatch"); +$invertMatch = $invertMatch ? $invertMatch->getValueAt(0)->getSPLExpression() eq "true" : undef; + %> <%SPL::CodeGen::implementationPrologue($model);%> @@ -114,7 +117,11 @@ void MY_OPERATOR::process(Tuple const & tuple, uint32_t port) { textMatch = lookupText(<%=$inputTextAttrParamCppValue%>); } +<% if(!$invertMatch) { %> if(textMatch) { +<% } else { %> + if(!textMatch) { +<% } %> // <% # CodeGenX::copyOutputAttributesFromInputAttributes("outTuple", $model->getOutputPortAt(0), $model->getInputPortAt(0)); %> ; // <% # CodeGenX::assignOutputAttributeValues("outTuple", $model->getOutputPortAt(0)); %> ; // SPLAPPTRC(L_TRACE, "submitting outTuple=" << outTuple, TEXT_FILTER);