Skip to content

Commit 25767b5

Browse files
committed
Redesigned native functions implementation.
1 parent 90e9290 commit 25767b5

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<info:toolkitInfoModel xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common"
3-
xmlns:info="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo">
4-
<info:identity>
5-
<info:name>com.ibm.streamsx.regex.RegexMatchNFSample</info:name>
6-
<info:description>Sample use of regex native functions.</info:description>
7-
<info:version>1.0.0</info:version>
8-
<info:requiredProductVersion>3.1.0</info:requiredProductVersion>
9-
</info:identity>
10-
<info:dependencies>
11-
<info:toolkit>
12-
<common:name>com.ibm.streamsx.regex</common:name>
13-
<common:version>1.0.0</common:version>
14-
</info:toolkit>
15-
</info:dependencies>
2+
<info:toolkitInfoModel xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:info="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo">
3+
<info:identity>
4+
<info:name>com.ibm.streamsx.regex.RegexMatchNFSample</info:name>
5+
<info:description>Sample use of regex native functions.</info:description>
6+
<info:version>1.0.1</info:version>
7+
<info:requiredProductVersion>3.2.1</info:requiredProductVersion>
8+
</info:identity>
9+
<info:dependencies>
10+
<info:toolkit>
11+
<common:name>com.ibm.streamsx.regex</common:name>
12+
<common:version>1.0.0</common:version>
13+
</info:toolkit>
14+
</info:dependencies>
1615
</info:toolkitInfoModel>

samples/RegexMatchNFSample/sample/RegexMatchNFSample.spl

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,44 @@ use com.ibm.streamsx.regex.re2::*;
55
/**
66
* Run functional tests using native functions.
77
*
8-
* * Functional tests for simple, partial and full matches.
8+
* * Functional tests for interpreted and compiled partial/full matches.
99
*
1010
* The output:
11-
* * regexSimpleMatch: 'Hello world' matches '^Hello': true
12-
* * regexSimpleMatch: 'Hello world' matches 'Hello$': false
1311
* * regexPartialMatch: 'Hello world' matches '^Hello': true
12+
* * regexFullMatch: 'Hello world' matches '^Hello': true
1413
* * regexPartialMatch: 'Hello world' matches '^Hello': true
15-
* * regexPartialMatch: 'Hello world' matches 'Hello$': true
1614
* * regexFullMatch: 'Hello world' matches '^Hello': false
17-
* * regexFullMatch: 'Hello world' matches '^Hello world': false
15+
* * regexFullMatch: 'Hello world' matches 'Hello world$': true
1816
*/
1917
composite RegexMatchNFSample {
2018
graph
2119
()as Custom_1 = Custom(){
2220
logic
2321
onProcess : {
24-
// Simple partial match - regex pattern is interpreted on each call
25-
// The usage is similar to SPL regex functions
26-
printString("regexSimpleMatch: 'Hello world' matches '^Hello': ");
27-
println(regexSimpleMatch("Hello world", "^Hello"));
28-
29-
printString("regexSimpleMatch: 'Hello world' matches 'Hello$': ");
30-
println(regexSimpleMatch("Hello world", "Hello$"));
22+
// Compile and index regex pattern, additionally increase max memory allocated
23+
regexCompile("^Hello", RegexPattern._1);
24+
regexCompile("Hello world$", RegexPattern._2);
25+
regexCompile(".*VERY_BIG_PATTERN.*", RegexPattern._3, 10000000);
3126

32-
// Fast partial match - regex pattern is compiled on the first call
33-
// Each subsequent call will use the compiled version even if the new pattern given
27+
// Simple partial match (similar to SPL regex functions) - regex pattern is interpreted on each call
3428
printString("regexPartialMatch: 'Hello world' matches '^Hello': ");
3529
println(regexPartialMatch("Hello world", "^Hello"));
3630

31+
// Simple full match (the whole string is matched) - regex pattern is interpreted on each call
32+
printString("regexFullMatch: 'Hello world' matches '^Hello world': ");
33+
println(regexFullMatch("Hello world", "^Hello world"));
34+
35+
// Fast partial match - compiled regex pattern 1 is used
3736
printString("regexPartialMatch: 'Hello world' matches '^Hello': ");
38-
println(regexPartialMatch("Hello world"));
37+
println(regexPartialMatch("Hello world", RegexPattern._1));
3938

40-
printString("regexPartialMatch: 'Hello world' matches 'Hello$': ");
41-
println(regexPartialMatch("Hello world", "Hello$")); // Still using compiled '^Hello' pattern
42-
43-
// Fast full match is similar to the partial match, but requires to match the whole string
44-
// Existing regex pattern still applies as it was compiled on previous call
39+
// Fast full match - compiled regex pattern 1 is used
4540
printString("regexFullMatch: 'Hello world' matches '^Hello': ");
46-
println(regexFullMatch("Hello world"));
41+
println(regexFullMatch("Hello world", RegexPattern._1));
4742

48-
printString("regexFullMatch: 'Hello world' matches '^Hello world': ");
49-
println(regexFullMatch("Hello world", "^Hello world")); // new pattern is not used
50-
43+
// Fast full match - compiled regex pattern 2 is used
44+
printString("regexFullMatch: 'Hello world' matches 'Hello world$': ");
45+
println(regexFullMatch("Hello world", RegexPattern._2));
5146
}
5247

5348
}

0 commit comments

Comments
 (0)