Skip to content

Commit 429c40a

Browse files
author
Senthil Nathan
committed
Changes done for v1.0.2.
1 parent 97d6593 commit 429c40a

File tree

6 files changed

+696
-46
lines changed

6 files changed

+696
-46
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Changes
22

3-
## v1.0.0
4-
* Apr/05/2021
5-
* Very first release of this toolkit that was tested to support the use of set, list, map and nested tuple attributes in a rule expression.
3+
## v1.0.2
4+
* Apr/15/2021
5+
* Added support for the use of list<TUPLE> in a rule expression.
66

77
## v1.0.1
88
* Apr/12/2021
99
* Added support for multilevel parenthesis i.e. nested rule expressions.
10+
11+
## v1.0.0
12+
* Apr/05/2021
13+
* Very first release of this toolkit that was tested to support the use of set, list, map and nested tuple attributes in a rule expression.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ This toolkit came into existence for a specific need with which a large enterpri
7575

7676
e. No bitwise operations are supported at this time.
7777

78-
5. It allows a rule expression that can refer to boolean, integer, float, string, set, list, map and other nested tuple attributes.
78+
5. It allows a rule expression that can refer to boolean, integer, float, string, set, list, map and other nested tuple attributes. In addition to having many built-in data types inside a collection, it allows list<TUPLE> by having user defined custom tuple data types inside a list.
7979

8080
6. It allows certain level of subexpression chaining in a rule.
8181

com.ibm.streamsx.eval_predicate/EvalPredicateExample.spl

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/*
99
==================================================================
1010
First created on: Mar/05/2021
11-
Last modified on: Apr/11/2021
11+
Last modified on: Apr/15/2021
1212

1313
This is an example application that shows how to use the
1414
eval_predicate function to evaluate an SPL expression a.k.a
@@ -51,7 +51,7 @@ issue in the IBMStreams GitHub or contact the author of this toolkit.
5151

5252
boolean, int32, uint32, int64, uint64, float32, float64, rstring,
5353
set<int32>, set<int64>, set<float32>, set<float64>, set<rstring>,
54-
list<int32>, list<int64>, list<float32>, list<float64>, list<rstring>,
54+
list<int32>, list<int64>, list<float32>, list<float64>, list<rstring>, list<TUPLE>,
5555
map<rstring,int32>, map<int32,rstring>, map<rstring,int64>, map<int64,rstring>,
5656
map<rstring,float32>, map<float32,rstring>, map<rstring,float64>,
5757
map<float64,rstring>, map<rstring,rstring>, map<int32,int32>, map<int32,int64>,
@@ -128,7 +128,7 @@ composite EvalPredicateExample {
128128
// evaluate different kinds of expressions.
129129
//
130130
// 1) A simple flat schema with no nesting.
131-
Ticker_t = rstring symbol, float32 price, uint32 quantity, boolean buyOrSell;
131+
Ticker_t = rstring symbol, float32 price, uint32 quantity, boolean buyOrSell;
132132

133133
// 2) A schema with multilevel types with no nesting.
134134
Person_t = rstring name, rstring title,
@@ -146,9 +146,13 @@ composite EvalPredicateExample {
146146
CityDetails_t = tuple<GeoCoords_t geo, CityInfo_t info> location, Weather_t weather;
147147
City_t = rstring name, CityDetails_t details, Demography_t stats,
148148
int32 rank, list<int32> roadwayNumbers, map<rstring, int32> housingNumbers;
149+
150+
// 4) Another simple flat schema with no nesting.
151+
AccuWeather_t = rstring city, float64 humidity,
152+
map<int64, float64> hourlyTemperatureMap, boolean sunnyDay;
149153

150154
graph
151-
// Kickstart this application with a dummy signal.
155+
// Start this application with a dummy signal.
152156
(stream<boolean dummy> Signal as S) as SignalGenerator = Beacon() {
153157
param
154158
iterations: 1;
@@ -505,6 +509,50 @@ composite EvalPredicateExample {
505509
} else {
506510
printStringLn("Testcase 3.12: Evaluation execution failed. Error=" + (rstring)error);
507511
}
512+
513+
// ============== TESTCASE GROUP 4 ==============
514+
mutable AccuWeather_t myWeather = {};
515+
myWeather.city = "New York";
516+
myWeather.humidity = 12.87;
517+
insertM(myWeather.hourlyTemperatureMap,
518+
333343l, 87.355);
519+
insertM(myWeather.hourlyTemperatureMap,
520+
443536l, 84.31);
521+
insertM(myWeather.hourlyTemperatureMap,
522+
592311l, 85.72);
523+
insertM(myWeather.hourlyTemperatureMap,
524+
693127l, 86.128);
525+
insertM(myWeather.hourlyTemperatureMap,
526+
729841l, 85.853);
527+
myWeather.sunnyDay = true;
528+
529+
type AccuWeatherTestData_t = list<AccuWeather_t> weatherList;
530+
mutable AccuWeatherTestData_t accuWeatherTestData = {};
531+
appendM(accuWeatherTestData.weatherList, myWeather);
532+
533+
// Evaluate an expression (i.e. rule).
534+
// Arg1: Expression string i.e. your custom rule.
535+
// Arg2: Your tuple
536+
// Arg3: A mutable int32 variable to receive a non-zero eval error code if any.
537+
// (You can refer to top of the impl/include/eval_predicate.h file in the
538+
// streamsx.eval_predicate toolkit for the meaning of a given error code.)
539+
// Arg4: A boolean value to enable debug tracing inside this function.
540+
// It returns true if the expression's evaluation criteria is met.
541+
// It returns false and error=0 if the expression's evaluation criteria is not met.
542+
// It returns a non-zero error when there is an evaluation execution failure.
543+
//
544+
// 4.1
545+
// Usage of list<TUPLE>
546+
rule = "(((weatherList[0].sunnyDay == false) || (weatherList[0].city contains 'York') || (weatherList[0].humidity <= 12.87)) && ((weatherList[0].hourlyTemperatureMap[592311] != 89.16)) && weatherList[0].sunnyDay == true)";
547+
result = eval_predicate(rule, accuWeatherTestData, error, $EVAL_PREDICATE_TRACING);
548+
549+
if(result == true) {
550+
printStringLn("Testcase 4.1: Evaluation criteria is met.");
551+
} else if(result == false && error == 0) {
552+
printStringLn("Testcase 4.1: Evaluation criteria is not met.");
553+
} else {
554+
printStringLn("Testcase 4.1: Evaluation execution failed. Error=" + (rstring)error);
555+
}
508556
} // End of onTuple S
509557
} // End of the Custom operator.
510558
} // End of the main composite.

com.ibm.streamsx.eval_predicate/FunctionalTests.spl

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/*
99
==================================================================
1010
First created on: Mar/28/2021
11-
Last modified on: Apr/11/2021
11+
Last modified on: Apr/15/2021
1212

1313
This application is meant for doing several hundred
1414
functional tests to provide as much coverage as possible to
@@ -67,7 +67,11 @@ composite FunctionalTests {
6767
Ticker_t = rstring symbol, float32 price, uint32 quantity,
6868
boolean buyOrSell, map<boolean, int32> myMap1;
6969

70-
// 2) A made up arbitrary schema with multilevel types and
70+
// 2) Another simple flat schema with no nesting.
71+
Weather_t = rstring city, float64 humidity,
72+
map<int64, float64> hourlyTemperatureMap, boolean sunnyDay;
73+
74+
// 3) A made up arbitrary schema with multilevel types and
7175
// nesting that includes primitive and collection data types such as
7276
// sets, lists and maps. Main idea here is to have tuple types that can
7377
// include all the SPL typed attributes needed for testing the
@@ -115,10 +119,11 @@ composite FunctionalTests {
115119

116120
GroupC_t = tuple<FloatWorld_t fw> reals;
117121

118-
TestData_t = rstring testId, GroupA_t a, GroupB_t b, GroupC_t c;
122+
TestData_t = rstring testId, GroupA_t a,
123+
GroupB_t b, GroupC_t c, list<Weather_t> weatherList;
119124

120125
graph
121-
// Kickstart this application with a dummy signal.
126+
// Start this application with a dummy signal.
122127
(stream<boolean dummy> Signal as S) as SignalGenerator = Beacon() {
123128
param
124129
iterations: 1;
@@ -142,6 +147,21 @@ composite FunctionalTests {
142147
// Send this tuple out.
143148
submit(myTicker, MT);
144149
// -------------------------
150+
mutable Weather_t myWeather = {};
151+
myWeather.city = "New York";
152+
myWeather.humidity = 12.87;
153+
insertM(myWeather.hourlyTemperatureMap,
154+
333343l, 87.355);
155+
insertM(myWeather.hourlyTemperatureMap,
156+
443536l, 84.31);
157+
insertM(myWeather.hourlyTemperatureMap,
158+
592311l, 85.72);
159+
insertM(myWeather.hourlyTemperatureMap,
160+
693127l, 86.128);
161+
insertM(myWeather.hourlyTemperatureMap,
162+
729841l, 85.853);
163+
myWeather.sunnyDay = true;
164+
// -------------------------
145165
// Create the comprehensive test data tuple now.
146166
mutable TestData_t myTestData = {};
147167
myTestData.testId = "Happy Path";
@@ -242,6 +262,8 @@ composite FunctionalTests {
242262
myTestData.c.reals.fw.s =
243263
{59.09 : 60.14, 61.28 : 62.37, 63.15 : 64.65};
244264
// -------------------------
265+
appendM(myTestData.weatherList, myWeather);
266+
// -------------------------
245267
// Send this tuple out.
246268
submit(myTestData, MTD);
247269
} // End of onTuple S.
@@ -6067,6 +6089,19 @@ composite FunctionalTests {
60676089
printStringLn("Testcase A51.6: Evaluation execution failed. Error=" + (rstring)error);
60686090
}
60696091
// -------------------------
6092+
6093+
// A52.1 (list<TUPLE>)
6094+
_rule = "(((b.digital.sw.productNameToGuid['You Chat'] notStartsWith '4345-8fd3-72550428159e') || (weatherList[0].city contains 'York') || (weatherList[0].humidity <= 12.87) || (c.reals.fw.s[61.28] - 2.37 == 60.00)) && ((a.transport.cars.rpmRange contains 8700) && (b.digital.sw.productNameToRevenue['Streams'] == 945438131.84) && (weatherList[0].hourlyTemperatureMap[592311] != 89.16)) && weatherList[0].sunnyDay == true)";
6095+
result = eval_predicate(_rule, _myTestData, error, $EVAL_PREDICATE_TRACING);
6096+
6097+
if(result == true) {
6098+
printStringLn("Testcase A52.1: Evaluation criteria is met.");
6099+
} else if(result == false && error == 0) {
6100+
printStringLn("Testcase A52.1: Evaluation criteria is not met.");
6101+
} else {
6102+
printStringLn("Testcase A52.1: Evaluation execution failed. Error=" + (rstring)error);
6103+
}
6104+
// -------------------------
60706105
} // End of onTuple MTD.
60716106
} // End of the HappyPathSink operator.
60726107

@@ -6098,7 +6133,6 @@ composite FunctionalTests {
60986133
mutable boolean result = false;
60996134
printStringLn("");
61006135
printStringLn("");
6101-
61026136
// Before we do anything here, we will do quick tests of
61036137
// the built-in evalPredicate native function available
61046138
// in the IBM Streams product to see where it works fine
@@ -7231,6 +7265,32 @@ composite FunctionalTests {
72317265
printStringLn("Testcase B78.1: Evaluation execution failed. Error=" + (rstring)error);
72327266
}
72337267
// -------------------------
7268+
7269+
// B79.1 (OPEN_SQUARE_BRACKET_NOT_FOUND_AFTER_LIST_OF_TUPLE 117)
7270+
_rule = "weatherList 0.city contains 'York'";
7271+
result = eval_predicate(_rule, _myTestData, error, $EVAL_PREDICATE_TRACING);
7272+
7273+
if(result == true) {
7274+
printStringLn("Testcase B79.1: Evaluation criteria is met.");
7275+
} else if(result == false && error == 0) {
7276+
printStringLn("Testcase B79.1: Evaluation criteria is not met.");
7277+
} else {
7278+
printStringLn("Testcase B79.1: Evaluation execution failed. Error=" + (rstring)error);
7279+
}
7280+
// -------------------------
7281+
7282+
// B80.1 (NO_PERIOD_FOUND_AFTER_LIST_OF_TUPLE 119)
7283+
_rule = "(weatherList[0] hourlyTemperatureMap[592311] != 89.16)";
7284+
result = eval_predicate(_rule, _myTestData, error, $EVAL_PREDICATE_TRACING);
7285+
7286+
if(result == true) {
7287+
printStringLn("Testcase B80.1: Evaluation criteria is met.");
7288+
} else if(result == false && error == 0) {
7289+
printStringLn("Testcase B80.1: Evaluation criteria is not met.");
7290+
} else {
7291+
printStringLn("Testcase B80.1: Evaluation execution failed. Error=" + (rstring)error);
7292+
}
7293+
// -------------------------
72347294
} // End of onTuple MTD.
72357295
} // End of the UnhappyPathSink operator.
72367296
} // End of main composite.

0 commit comments

Comments
 (0)