Skip to content

Commit 80b0806

Browse files
author
Senthil Nathan
committed
Changes done for v1.1.4.
1 parent 6835266 commit 80b0806

File tree

7 files changed

+175
-13
lines changed

7 files changed

+175
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## v1.1.4
4+
* Jan/07/2023
5+
* Added a new function get_tuple_schema_and_attribute_info to fetch the tuple schema literal string along with the tuple attribute information map with fully qualified tuple attribute names and their SPL type names as key/value pairs in that map.
6+
37
## v1.1.3
48
* Oct/16/2021
59
* Enhanced the compare_tuple_attributes function to give back two lists i.e. one with the attribute names that have matching values and another with the attribute names that have differing values.

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,39 @@ if(error == 0) {
184184
// It is a void function that returns nothing.
185185
```
186186

187+
**get_tuple_schema_and_attribute_info** is another C++ native function provided via this toolkit. This function fetches the tuple schema literal string along with the tuple attribute information as a map with fully qualified tuple attribute names and their SPL type names as key/value pairs in that map.
188+
189+
```
190+
// This namespace usage declaration is needed at the top of an application.
191+
use com.ibm.streamsx.eval_predicate::*;
192+
193+
mutable rstring tupleSchema = "";
194+
mutable map<rstring, rstring> attributeInfo = {};
195+
196+
get_tuple_schema_and_attribute_info(myTuple1, tupleSchema,
197+
attributeInfo, error, $EVAL_PREDICATE_TRACING);
198+
199+
if(error == 0) {
200+
printStringLn("Get tuple schema function returned successfully. " +
201+
", tupleSchema = " + tupleSchema +
202+
", attributeInfo = " + (rstring)attributeInfo);
203+
} else {
204+
printStringLn("Get tuple schema function returned an error. Error=" + (rstring)error);
205+
}
206+
207+
// Following is the usage description for the get_tuple_schema_and_attribute_info function.
208+
// Arg1: Your tuple
209+
// Arg2: A mutable variable of rstring type in which the
210+
// tuple schema literal string will be returned.
211+
// Arg3: A mutable variable of map<string, rstring> type in which the
212+
// tuple attribute information will be returned. Map keys will
213+
// carry the fully qualified tuple attribute names and the
214+
// map values will carry the SPL type name of the attributes.
215+
// Arg4: A mutable int32 variable to receive non-zero error code if any.
216+
// Arg5: A boolean value to enable debug tracing inside this function.
217+
// It is a void function that returns nothing.
218+
```
219+
187220
## Design considerations
188221
This toolkit came into existence for a specific need with which a large enterprise customer approached the author of this toolkit. There is already a built-in function named *evalPredicate* that is available in the official IBM Streams product. However, that function has certain limitations. To fill that gap, this toolkit with its own **eval_predicate** function is being made available freely via the publicly accessible IBMStreams GitHub. The **eval_predicate** function from this toolkit differs from the *evalPredicate* built-in function in the IBM Streams product in the following ways.
189222

com.ibm.streamsx.eval_predicate/EvalPredicateExample.spl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
==============================================
33
# Licensed Materials - Property of IBM
4-
# Copyright IBM Corp. 2021
4+
# Copyright IBM Corp. 2021, 2023
55
==============================================
66
*/
77

88
/*
99
==================================================================
1010
First created on: Mar/05/2021
11-
Last modified on: Oct/16/2021
11+
Last modified on: Jan/07/2023
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
@@ -109,6 +109,12 @@ attribute names that differ in their values. In this example,
109109
you can search for compare_tuple_attributes to see a few
110110
test cases on that topic.
111111

112+
Another feature available in the eval_predicate toolkit is to
113+
get the schema literal string of a given tuple along with the
114+
fully qualified attribute names and their SPL type names.
115+
In this example, you can search for get_tuple_schema_and_attribute_info
116+
to see a few test cases on that topic.
117+
112118
How can you use this new eval_predicate function?
113119
-------------------------------------------------
114120
Any other application that wants to use this function must
@@ -489,6 +495,30 @@ composite EvalPredicateExample {
489495
} else {
490496
printStringLn("Testcase 2.8: Compare tuple attributes function returned an error. Error=" + (rstring)error);
491497
}
498+
499+
// 2.9
500+
// Get tuple schema literal string along with its attribute information.
501+
//
502+
mutable rstring tupleSchema = "";
503+
mutable map<rstring, rstring> attributeInfo = {};
504+
505+
// Call the specific function that can do this for us.
506+
// It will return the tuple schema literal string in the
507+
// mutable string variable passed as a second function argument.
508+
// It will return the tuple attribute information in the
509+
// mutable map variable passed as a third function argument.
510+
// This map's keys will hold the fully qualified tuple attribute names.
511+
// This map's values will hold the SPL type names of the tuple attribute names.
512+
get_tuple_schema_and_attribute_info(myTuple1, tupleSchema,
513+
attributeInfo, error, $EVAL_PREDICATE_TRACING);
514+
515+
if(error == 0) {
516+
printStringLn("Testcase 2.9: Get tuple schema function returned successfully. " +
517+
", tupleSchema = " + tupleSchema +
518+
", attributeInfo = " + (rstring)attributeInfo);
519+
} else {
520+
printStringLn("Testcase 2.9: Get tuple schema function returned an error. Error=" + (rstring)error);
521+
}
492522

493523
// ============== TESTCASE GROUP 3 ==============
494524
mutable City_t myCity = {};

com.ibm.streamsx.eval_predicate/FunctionalTests.spl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
==============================================
33
# Licensed Materials - Property of IBM
4-
# Copyright IBM Corp. 2021
4+
# Copyright IBM Corp. 2021, 2023
55
==============================================
66
*/
77

88
/*
99
==================================================================
1010
First created on: Mar/28/2021
11-
Last modified on: Oct/16/2021
11+
Last modified on: Jan/07/2023
1212

1313
This application is meant for doing several hundred
1414
functional tests to provide as much coverage as possible to
@@ -47,6 +47,12 @@ attribute names that differ in their values. In this example,
4747
you can search for compare_tuple_attributes to see a few
4848
test cases on that topic.
4949

50+
Another feature available in the eval_predicate toolkit is to
51+
get the schema literal string of a given tuple along with the
52+
fully qualified attribute names and their SPL type names.
53+
In this example, you can search for get_tuple_schema_and_attribute_info
54+
to see a few test cases on that topic.
55+
5056
How can you build this test application?
5157
----------------------------------------
5258
1) If you are a command line person, you can use the
@@ -9146,6 +9152,30 @@ composite FunctionalTests {
91469152
printStringLn("Testcase C1.50: Compare tuple attributes function returned an error. Error=" + (rstring)error);
91479153
}
91489154

9155+
// C1.51
9156+
// Get tuple schema literal string along with its attribute information.
9157+
//
9158+
mutable rstring tupleSchema = "";
9159+
mutable map<rstring, rstring> attributeInfo = {};
9160+
9161+
// Call the specific function that can do this for us.
9162+
// It will return the tuple schema literal string in the
9163+
// mutable string variable passed as a second function argument.
9164+
// It will return the tuple attribute information in the
9165+
// mutable map variable passed as a third function argument.
9166+
// This map's keys will hold the fully qualified tuple attribute names.
9167+
// This map's values will hold the SPL type names of the tuple attribute names.
9168+
get_tuple_schema_and_attribute_info(myTuple1, tupleSchema,
9169+
attributeInfo, error, $EVAL_PREDICATE_TRACING);
9170+
9171+
if(error == 0) {
9172+
printStringLn("Testcase C1.51: Get tuple schema function returned successfully. " +
9173+
", tupleSchema = " + tupleSchema +
9174+
", attributeInfo = " + (rstring)attributeInfo);
9175+
} else {
9176+
printStringLn("Testcase C1.51: Get tuple schema function returned an error. Error=" + (rstring)error);
9177+
}
9178+
91499179
// -------------------------
91509180

91519181
// Let us add below a few test cases for the

com.ibm.streamsx.eval_predicate/native.function/function.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ It compares the attribute values of two tuples that are made of the same schema
4242
</description>
4343
<prototype>&lt;tuple T1> public void compare_tuple_attributes(T1 myTuple1, T1 myTuple2, mutable list&lt;rstring&gt; matchingAttributes, mutable list&lt;rstring&gt; differingAttributes, mutable int32 error, boolean trace)</prototype>
4444
</function>
45+
46+
<function>
47+
<description>
48+
It fetches the schema literal string of a given tuple along with the information about all of its attributes.
49+
@param myTuple A user defined tuple for which schema and attribute information will be obtained. Type: Tuple
50+
@param schema A mutable variable in which the complete schema literal string of a given tuple will be returned. Type: rstring
51+
@param attributeInfo A mutable map variable in which information about the tuple attributes will be returned. Map key will carry the fully qualified name of a given tuple attribute and map value will carry the SPL type name of that attribute. Type: map&lt;rstring, rstring&gt;
52+
@param error A mutable variable that will contain a non-zero error code if an error occurs. Type: int32
53+
@param trace A boolean value to enable tracing inside this function. Type: boolean
54+
@return It returns nothing. Type: void
55+
</description>
56+
<prototype>&lt;tuple T1> public void get_tuple_schema_and_attribute_info(T1 myTuple, mutable rstring schema, mutable map&lt;rstring, rstring&gt; attributeInfo, mutable int32 error, boolean trace)</prototype>
57+
</function>
4558
</functions>
4659

4760
<dependencies>

impl/include/eval_predicate.h

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/*
22
==============================================
33
# Licensed Materials - Property of IBM
4-
# Copyright IBM Corp. 2021
4+
# Copyright IBM Corp. 2021, 2023
55
==============================================
66
*/
77
/*
88
============================================================
99
First created on: Mar/05/2021
10-
Last modified on: Oct/16/2021
10+
Last modified on: Jan/07/2023
11+
Author(s): Senthil Nathan (sen@us.ibm.com)
1112
1213
This toolkit's public GitHub URL:
1314
https://github.com/IBMStreams/streamsx.eval_predicate
@@ -377,7 +378,7 @@ namespace eval_predicate_functions {
377378
// subexpressions present in a fully validated expression.
378379
// It is important to understand the structure of this map which
379380
// is explained in great detail throughout this file.
380-
// One such explanation is available around line 643 of this file.
381+
// One such explanation is available around line 663 of this file.
381382
SPL::map<rstring, SPL::list<rstring> > subexpressionsMap;
382383

383384
// This list provides the subexpression map keys in sorted order.
@@ -536,6 +537,13 @@ namespace eval_predicate_functions {
536537
SPL::list<rstring> & matchingAttributes,
537538
SPL::list<rstring> & differingAttributes,
538539
int32 & error, boolean trace);
540+
// This method fetches the tuple schema literal string and the
541+
// tuple attribute information map with fully qualified tuple
542+
// attribute names and values as key/value pairs.
543+
template<class T1>
544+
void get_tuple_schema_and_attribute_info(T1 const & myTuple,
545+
rstring & schema, SPL::map<rstring, rstring> & attributeInfo,
546+
int32 & error, boolean trace);
539547
// ====================================================================
540548

541549
// Evaluate a given expression.
@@ -562,7 +570,7 @@ namespace eval_predicate_functions {
562570
return(false);
563571
}
564572

565-
// Get the string literal of a given tuple.
573+
// Get the schema literal string of a given tuple.
566574
// Example of myTuple's schema:
567575
// myTuple=tuple<rstring name,tuple<tuple<tuple<float32 latitude,float32 longitude> geo,tuple<rstring state,rstring zipCode,map<rstring,rstring> officials,list<rstring> businesses> info> location,tuple<float32 temperature,float32 humidity> weather> details,tuple<int32 population,int32 numberOfSchools,int32 numberOfHospitals> stats,int32 rank,list<int32> roadwayNumbers,map<rstring,int32> housingNumbers>
568576
//
@@ -652,7 +660,6 @@ namespace eval_predicate_functions {
652660
// user provided tuple and display its attribute names and values.
653661
traceTupleAtttributeNamesAndValues(myTuple, tupleAttributesMap, trace);
654662

655-
// Note: The space below between > > is a must. Otherwise, compiler will give an error.
656663
// This map's key is a subexpression id.
657664
// Subexpression id will go something like this:
658665
// 1.1, 1.2, 2.1, 2.2, 2.3, 2.4, 3.1, 3.2, 4.1, 4.2, 4.3, 5.1
@@ -701,6 +708,7 @@ namespace eval_predicate_functions {
701708
// Intra subexpression logical operator - When N/A, it will have an empty string.
702709
// ... - The sequence above repeats for this subexpression.
703710
//
711+
// Note: The space below between > > is a must. Otherwise, compiler will give an error.
704712
SPL::map<rstring, SPL::list<rstring> > subexpressionsMap;
705713
// Store the logical operators within the nested sub-expressions.
706714
// Key for this map will be id of the nested subexpression that
@@ -798,7 +806,7 @@ namespace eval_predicate_functions {
798806
// ====================================================================
799807

800808
// ====================================================================
801-
// This function receives a Tuple as input and returns a tuple literal string.
809+
// This function receives a Tuple as input and returns a tuple schema literal string.
802810
// We will later parse the tuple literal string to create a map of all the
803811
// attributes in a user given tuple.
804812
// Example of myTuple's schema that will be returned by this function:
@@ -10674,6 +10682,50 @@ namespace eval_predicate_functions {
1067410682
}
1067510683
} // End of for loop.
1067610684
} // End of compare_tuple_attributes
10685+
10686+
// This method fetches the tuple schema literal string and the
10687+
// tuple attribute information map with fully qualified tuple
10688+
// attribute names and their SPL type names as key/value
10689+
// pairs in that map.
10690+
//
10691+
// Get the tuple schema literal string along with the tuple attribute information.
10692+
// Arg1: Your tuple
10693+
// Arg2: A mutable variable of rstring type in which the
10694+
// tuple schema literal string will be returned.
10695+
// Arg3: A mutable variable of map<string, rstring> type in which the
10696+
// tuple attribute information will be returned. Map keys will
10697+
// carry the fully qualified tuple attribute names and the
10698+
// map values will carry the SPL type name of the attributes.
10699+
// Arg4: A mutable int32 variable to receive non-zero error code if any.
10700+
// Arg5: A boolean value to enable debug tracing inside this function.
10701+
// It is a void method that returns nothing.
10702+
//
10703+
template<class T1>
10704+
void get_tuple_schema_and_attribute_info(T1 const & myTuple,
10705+
rstring & schema, SPL::map<rstring, rstring> & attributeInfo,
10706+
int32 & error, boolean trace) {
10707+
error = ALL_CLEAR;
10708+
10709+
// Get the schema literal string of a given tuple.
10710+
// Example of myTuple's schema:
10711+
// myTuple=tuple<rstring name,tuple<tuple<tuple<float32 latitude,float32 longitude> geo,tuple<rstring state,rstring zipCode,map<rstring,rstring> officials,list<rstring> businesses> info> location,tuple<float32 temperature,float32 humidity> weather> details,tuple<int32 population,int32 numberOfSchools,int32 numberOfHospitals> stats,int32 rank,list<int32> roadwayNumbers,map<rstring,int32> housingNumbers>
10712+
//
10713+
schema = "";
10714+
schema = getSPLTypeName(myTuple, trace);
10715+
10716+
if(schema == "") {
10717+
// This should never occur. If it happens in
10718+
// extremely rare cases, we have to investigate the
10719+
// tuple literal schema generation function.
10720+
error = TUPLE_LITERAL_SCHEMA_GENERATION_ERROR;
10721+
return;
10722+
}
10723+
10724+
// Let us parse the individual attributes of the given tuple and
10725+
// store them in a user provided map.
10726+
Functions::Collections::clearM(attributeInfo);
10727+
parseTupleAttributes(schema, attributeInfo, error, trace);
10728+
} // End of get_tuple_schema_and_attribute_info
1067710729
// ====================================================================
1067810730
} // End of namespace eval_predicate_functions
1067910731
// ====================================================================
@@ -10694,8 +10746,8 @@ last hurrah in my technical contributions to the incomparable IBM Streams.
1069410746
I will be thrilled to get another chance to associate with this wonderful
1069510747
product if it finds a new home for further development either inside or
1069610748
outside of IBM. Until then, I will continue to reminisce this unforgettable
10697-
journey made possible by the passionate researchers, engineers and managers
10698-
who are all simply world class.
10749+
journey made possible by the passionate researchers, engineers, managers and
10750+
customers who are all simply world class.
1069910751
1070010752
It will take many more years for some other company or an open-source group to
1070110753
roll out a full-featured product that can be a true match for IBM Streams.

info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<info:identity>
55
<info:name>eval_predicate</info:name>
66
<info:description>Toolkit for user defined rule (expression) processing</info:description>
7-
<info:version>1.1.3</info:version>
7+
<info:version>1.1.4</info:version>
88
<info:requiredProductVersion>4.2.1.6</info:requiredProductVersion>
99
</info:identity>
1010
<info:dependencies/>

0 commit comments

Comments
 (0)