Skip to content

Commit 2ab15b4

Browse files
committed
Added samples for the v2.0
1 parent 68fb06e commit 2ab15b4

21 files changed

+290
-283
lines changed

samples/RegexMatchNFSample/.externalToolBuilders/org.eclipse.jdt.core.javabuilder (10).launch

-6
This file was deleted.

samples/RegexMatchNFSample/sample/RegexMatchNFSample.spl

-75
This file was deleted.

samples/RegexMatchNFSample/sample/RegexMatchRESample.spl

-75
This file was deleted.

samples/RegexMatchNFSample/sample/RegexMatchXPSample.spl

-86
This file was deleted.

samples/RegexMatchSample/.externalToolBuilders/org.eclipse.jdt.core.javabuilder (12).launch

-6
This file was deleted.

samples/RegexMatchNFSample/.project samples/RegexNFSamples/.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>RegexMatchNFSample</name>
3+
<name>RegexNFSamples</name>
44
<comment></comment>
55
<projects>
66
</projects>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<info:toolkitInfoModel xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:info="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo">
33
<info:identity>
4-
<info:name>com.ibm.streamsx.regex.RegexMatchNFSample</info:name>
4+
<info:name>RegexNFSamples</info:name>
55
<info:description>Sample use of regex native functions.</info:description>
6-
<info:version>1.1.1</info:version>
6+
<info:version>2.0.0</info:version>
77
<info:requiredProductVersion>4.0</info:requiredProductVersion>
88
</info:identity>
99
<info:dependencies>
1010
<info:toolkit>
1111
<common:name>com.ibm.streamsx.regex</common:name>
12-
<common:version>1.0.0</common:version>
12+
<common:version>2.0.0</common:version>
1313
</info:toolkit>
1414
</info:dependencies>
1515
</info:toolkitInfoModel>

samples/RegexMatchNFSample/sample/RegexReplaceRESample.spl samples/RegexNFSamples/sample/RegexMatchRESample.spl

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ use com.ibm.streamsx.regex.re2::*;
1515
* * regexFullMatch: 'Hello world' matches '^Hello': false
1616
* * regexFullMatch: 'Hello world' matches 'Hello world$': true
1717
* * regexPartialMatch 2: 'Hello world' matches '': true
18-
* * WARN #splapptrc,J[0],P[0],Custom_2,REGEX M[Regex_re2.h:getRE2Options:28] - "Regular expression '' is empty, possibly 'regexCompile' was not called before."
19-
* * ERROR #splapplog,J[0],P[0],Custom_3,spl_pe M[PEImpl.cpp:logTerminatingException:1988] - CDISR5033E: An exception occurred during the execution of the Custom_3 operator. Processing element number 0 is terminating.
20-
* * ERROR #splapptrc,J[0],P[0],Custom_3,#splapptrc,J[0],P[0],Custom_3,spl_operator M[PEImpl.cpp:handleOperatorFailure:596] - CDISR5030E: An exception occurred during the execution of the Custom_3 operator. The exception is: "Regular expression '[' failed to compile - missing ]: ["
21-
* * ERROR #splapptrc,J[0],P[0],Custom_2,spl_operator M[PEImpl.cpp:process:1367] - CDISR5053E: Runtime failures occurred in the following operators: Custom_3.
22-
18+
* * WARN ... "Regular expression '' is empty, possibly 'regexCompile' was not called before."
19+
* * ERROR ... CDISR5033E: An exception occurred during the execution of the Custom_3 operator. Processing element number 0 is terminating.
20+
* * ERROR ... CDISR5030E: An exception occurred during the execution of the Custom_3 operator. The exception is: "Regular expression '\[' failed to compile - missing ]: \["
21+
* * ERROR ... CDISR5053E: Runtime failures occurred in the following operators: Custom_3.
2322
*/
2423
composite RegexMatchRESample
2524
{

samples/RegexMatchNFSample/sample/RegexReplaceXPSample.spl samples/RegexNFSamples/sample/RegexMatchXPSample.spl

+30-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ use com.ibm.streamsx.regex.xpressive::* ;
1414
* * regexPartialMatch: 'Hello world' matches '^Hello': true
1515
* * regexFullMatch: 'Hello world' matches '^Hello': false
1616
* * regexFullMatch: 'Hello world' matches 'Hello world$': true
17+
* * regexPartialMatch 2: 'Hello world' matches '': true
18+
* * WARN ... "Regular expression '' is empty, possibly 'regexCompile' was not called before."
19+
* * ERROR ... CDISR5033E: An exception occurred during the execution of the Custom_3 operator. Processing element number 0 is terminating.
20+
* * ERROR ... CDISR5030E: An exception occurred during the execution of the Custom_3 operator. The exception is: unexpected end of pattern found
21+
* * ERROR ... CDISR5053E: Runtime failures occurred in the following operators: Custom_3.
1722
*/
1823

19-
composite RegexReplaceXPSample
24+
composite RegexMatchXPSample
2025
{
2126
graph
2227
() as Custom_1 = Custom()
@@ -54,5 +59,28 @@ composite RegexReplaceXPSample
5459

5560
}
5661

57-
}
62+
() as Custom_2 = Custom()
63+
{
64+
logic
65+
onProcess :
66+
{
67+
block(1.0);
68+
// Fast partial match - regex pattern _1 is used, but not compiled first
69+
printString("regexPartialMatch 2: 'Hello world' matches '': ") ;
70+
println(regexPartialMatch("Hello world", RegexPattern._1)) ;
71+
}
72+
73+
}
5874

75+
() as Custom_3 = Custom()
76+
{
77+
logic
78+
onProcess :
79+
{
80+
block(2.0);
81+
// Compile and index erroneous regex pattern - error is thrown
82+
regexCompile("[", RegexPattern._1) ;
83+
}
84+
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace sample ;
2+
3+
use com.ibm.streamsx.regex::* ;
4+
use com.ibm.streamsx.regex.re2::*;
5+
6+
/**
7+
* Run functional tests using native functions.
8+
*
9+
* * Functional tests for compiled local/global replaces.
10+
*
11+
* The output:
12+
* * regexReplace: replaces first 'Hello' word with 'Hi': <Hi world, Hello>
13+
* * regexGlobalReplace: replaces all 'Hello' words with 'Hi': <Hi world, Hi>
14+
* * (replaced 2 times)
15+
* * regexExtract: 'foo' and 'bar' are extracted and replace placeholders in str2: <In domain 'bar', user 'foo' exists!>
16+
*/
17+
composite RegexReplaceRESample
18+
{
19+
graph
20+
() as Custom_1 = Custom()
21+
{
22+
logic
23+
state : {
24+
// regexCompile can be called within a state
25+
boolean _ = regexCompile("Hello", RegexPattern._1); // Compile and index regex pattern _1
26+
}
27+
onProcess :
28+
{
29+
// regexCompile can be called inside logic processing - nevertheless the compilation will run only once on the first call
30+
regexCompile("(.*)@([^.]*)", RegexPattern._2); // Compile and index regex pattern _2
31+
32+
// One replace - compiled regex pattern _1 is used
33+
mutable rstring str = "<Hello world, Hello>";
34+
printString("regexReplace: replaces first 'Hello' word with 'Hi': ") ;
35+
if( regexReplace(str, RegexPattern._1, "Hi"))
36+
printStringLn(str) ;
37+
38+
// Global replace - compiled regex pattern _1 is used
39+
mutable rstring str1 = "<Hello world, Hello>";
40+
printString("regexGlobalReplace: replaces all 'Hello' words with 'Hi': ") ;
41+
int32 count = regexGlobalReplace(str1, RegexPattern._1, "Hi");
42+
if(count > 0)
43+
printStringLn(str1 + "\n(replaced " + (rstring)count + " times)") ;
44+
45+
// Extract - compiled regex pattern _2 is used
46+
mutable rstring str2 = "<In domain '\\2', user '\\1' exists!>";
47+
printString("regexExtract: 'foo' and 'bar' are extracted and replace placeholders in str2: ") ;
48+
if( regexExtract("[email protected]", RegexPattern._2, str2))
49+
printStringLn(str2) ;
50+
}
51+
52+
}
53+
}

0 commit comments

Comments
 (0)