Skip to content

Commit 6835266

Browse files
author
Senthil Nathan
committed
Changes done for v1.1.3.
1 parent 4019bfc commit 6835266

File tree

7 files changed

+129
-91
lines changed

7 files changed

+129
-91
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.3
4+
* Oct/16/2021
5+
* 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.
6+
37
## v1.1.2
48
* Oct/16/2021
59
* Added a new function compare_tuple_attributes to compare the attribute values of two tuples that are based on the same schema and then give back a list containing the attribute names that have differing values in the two tuples being compared.

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if(error == 0) {
106106
// It is a void function that returns nothing.
107107
```
108108

109-
**compare_tuple_attributes** is another C++ native function provided via this toolkit. This function compares the attribute values of two tuples that are based on the same schema. It will give back a list containing attribute names that have differing values in the two tuples being compared. It supports primitive types (int32, float64, rstring etc.) as well as collection types (set, list and map). It also allows flat tuples as well as deeply nested tuples to be compared.
109+
**compare_tuple_attributes** is another C++ native function provided via this toolkit. This function compares the attribute values of two tuples that are based on the same schema. It will give back a list containing attribute names that have matching values and another list containing attribute names that have differing values in the two tuples being compared. It supports primitive types (int32, float64, rstring etc.) as well as collection types (set, list and map). It allows flat tuples as well as deeply nested tuples to be compared.
110110

111111
```
112112
// This namespace usage declaration is needed at the top of an application.
@@ -122,6 +122,7 @@ type Test_t = boolean a, int32 b, uint64 c, float32 d, float64 e,
122122
// Create two tuples that are based on the same schema.
123123
mutable Test_t myTuple1 = {};
124124
mutable Test_t myTuple2 = {};
125+
mutable list<rstring> matchingAttributes = [];
125126
mutable list<rstring> differingAttributes = [];
126127
127128
// Populate the tuple with some data.
@@ -157,24 +158,29 @@ block(2.0);
157158
myTuple2.k.o = getTimestamp();
158159
159160
// Compare them now.
160-
compare_tuple_attributes(myTuple1, myTuple2, differingAttributes,
161-
error, $EVAL_PREDICATE_TRACING);
161+
compare_tuple_attributes(myTuple1, myTuple2,
162+
matchingAttributes, differingAttributes,
163+
error, $EVAL_PREDICATE_TRACING);
162164
163165
if(error == 0) {
164166
printStringLn("Compare tuple attributes function returned successfully. " +
165-
"differingAttributes = " + (rstring)differingAttributes);
167+
"matchingAttributes = " + (rstring)matchingAttributes +
168+
", differingAttributes = " + (rstring)differingAttributes);
166169
} else {
167-
printStringLn("Compare tuple attributes function returned an error. Error=" + (rstring)error);
170+
printStringLn("Compare tuple attributes function returned an error. Error=" +
171+
(rstring)error);
168172
}
169173
}
170174
// Following is the usage description for the compare_tuple_attributes function.
171175
//
172176
// Arg1: Your tuple1
173177
// Arg2: Your tuple2
174178
// Arg3: A mutable variable of list<string> type in which the
179+
// attribute names that have a match in their values will be returned.
180+
// Arg4: A mutable variable of list<string> type in which the
175181
// attribute names that differ in their values will be returned.
176-
// Arg4: A mutable int32 variable to receive non-zero error code if any.
177-
// Arg5: A boolean value to enable debug tracing inside this function.
182+
// Arg5: A mutable int32 variable to receive non-zero error code if any.
183+
// Arg6: A boolean value to enable debug tracing inside this function.
178184
// It is a void function that returns nothing.
179185
```
180186

com.ibm.streamsx.eval_predicate/EvalPredicateExample.spl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ composite EvalPredicateExample {
403403
// Arg1: Your tuple1
404404
// Arg2: Your tuple2
405405
// Arg3: A mutable variable of list<string> type in which the
406+
// attribute names that have a match in their values will be returned.
407+
// Arg4: A mutable variable of list<string> type in which the
406408
// attribute names that differ in their values will be returned.
407-
// Arg4: A mutable int32 variable to receive non-zero error code if any.
408-
// Arg5: A boolean value to enable debug tracing inside this function.
409+
// Arg5: A mutable int32 variable to receive non-zero error code if any.
410+
// Arg6: A boolean value to enable debug tracing inside this function.
409411
//
410412
// 2.7
411413
// Compare two tuples that have no differing attribute values.
@@ -420,6 +422,7 @@ composite EvalPredicateExample {
420422
// Create two tuples that are based on the same schema.
421423
mutable Test_t myTuple1 = {};
422424
mutable Test_t myTuple2 = {};
425+
mutable list<rstring> matchingAttributes = [];
423426
mutable list<rstring> differingAttributes = [];
424427

425428
// Populate the tuple with some data.
@@ -445,11 +448,13 @@ composite EvalPredicateExample {
445448

446449
// Compare them now.
447450
compare_tuple_attributes(myTuple1, myTuple2,
448-
differingAttributes, error, $EVAL_PREDICATE_TRACING);
451+
matchingAttributes, differingAttributes,
452+
error, $EVAL_PREDICATE_TRACING);
449453

450454
if(error == 0) {
451455
printStringLn("Testcase 2.7: Compare tuple attributes function returned successfully. " +
452-
"differingAttributes = " + (rstring)differingAttributes);
456+
", matchingAttributes = " + (rstring)matchingAttributes +
457+
", differingAttributes = " + (rstring)differingAttributes);
453458
} else {
454459
printStringLn("Testcase 2.7: Compare tuple attributes function returned an error. Error=" + (rstring)error);
455460
}
@@ -470,14 +475,17 @@ composite EvalPredicateExample {
470475
myTuple2.k.o = getTimestamp();
471476

472477
// Clear the list.
478+
matchingAttributes = (list<rstring>)[];
473479
differingAttributes = (list<rstring>)[];
474480
// Compare them now.
475481
compare_tuple_attributes(myTuple1, myTuple2,
476-
differingAttributes, error, $EVAL_PREDICATE_TRACING);
482+
matchingAttributes, differingAttributes,
483+
error, $EVAL_PREDICATE_TRACING);
477484

478485
if(error == 0) {
479486
printStringLn("Testcase 2.8: Compare tuple attributes function returned successfully. " +
480-
"differingAttributes = " + (rstring)differingAttributes);
487+
", matchingAttributes = " + (rstring)matchingAttributes +
488+
", differingAttributes = " + (rstring)differingAttributes);
481489
} else {
482490
printStringLn("Testcase 2.8: Compare tuple attributes function returned an error. Error=" + (rstring)error);
483491
}

com.ibm.streamsx.eval_predicate/FunctionalTests.spl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9059,9 +9059,11 @@ composite FunctionalTests {
90599059
// Arg1: Your tuple1
90609060
// Arg2: Your tuple2
90619061
// Arg3: A mutable variable of list<string> type in which the
9062+
// attribute names that have a match in their values will be returned.
9063+
// Arg4: A mutable variable of list<string> type in which the
90629064
// attribute names that differ in their values will be returned.
9063-
// Arg4: A mutable int32 variable to receive non-zero error code if any.
9064-
// Arg5: A boolean value to enable debug tracing inside this function.
9065+
// Arg5: A mutable int32 variable to receive non-zero error code if any.
9066+
// Arg6: A boolean value to enable debug tracing inside this function.
90659067
//
90669068
// C1.49
90679069
// Compare two tuples that have no differing attribute values.
@@ -9076,6 +9078,7 @@ composite FunctionalTests {
90769078
// Create two tuples that are based on the same schema.
90779079
mutable Test_t myTuple1 = {};
90789080
mutable Test_t myTuple2 = {};
9081+
mutable list<rstring> matchingAttributes = [];
90799082
mutable list<rstring> differingAttributes = [];
90809083

90819084
// Populate the tuple with some data.
@@ -9093,19 +9096,21 @@ composite FunctionalTests {
90939096
myTuple1.k.m.y = 936.27;
90949097
myTuple1.k.m.z = "String inside a nested tuple.";
90959098
myTuple1.k.m.l = [67, 78, 89];
9096-
myTuple1.k.n = {1:true, 2:false, 3:true};
9099+
myTuple1.k.n = {1:true, 2:false, 3:true};
90979100
myTuple1.k.o = getTimestamp();
9098-
9101+
90999102
// Make the second tuple same as the first tuple.
91009103
myTuple2 = myTuple1;
91019104

91029105
// Compare them now.
91039106
compare_tuple_attributes(myTuple1, myTuple2,
9104-
differingAttributes, error, $EVAL_PREDICATE_TRACING);
9107+
matchingAttributes, differingAttributes,
9108+
error, $EVAL_PREDICATE_TRACING);
91059109

91069110
if(error == 0) {
91079111
printStringLn("Testcase C1.49: Compare tuple attributes function returned successfully. " +
9108-
"differingAttributes = " + (rstring)differingAttributes);
9112+
", matchingAttributes = " + (rstring)matchingAttributes +
9113+
", differingAttributes = " + (rstring)differingAttributes);
91099114
} else {
91109115
printStringLn("Testcase C1.49: Compare tuple attributes function returned an error. Error=" + (rstring)error);
91119116
}
@@ -9120,20 +9125,23 @@ composite FunctionalTests {
91209125
myTuple2.i = {10:'Ten', 9:'Nine', 8:'Eight'};
91219126
myTuple2.k.m.y = 27.93;
91229127
myTuple2.k.m.z = "Different string inside a nested tuple.";
9123-
myTuple2.k.n = {1:true, 2:true, 3:true};
9128+
myTuple2.k.n = {1:true, 2:true, 3:true};
91249129
// Wait for 2 seconds for time to change.
91259130
block(2.0);
91269131
myTuple2.k.o = getTimestamp();
9127-
9132+
91289133
// Clear the list.
9134+
matchingAttributes = (list<rstring>)[];
91299135
differingAttributes = (list<rstring>)[];
91309136
// Compare them now.
91319137
compare_tuple_attributes(myTuple1, myTuple2,
9132-
differingAttributes, error, $EVAL_PREDICATE_TRACING);
9138+
matchingAttributes, differingAttributes,
9139+
error, $EVAL_PREDICATE_TRACING);
91339140

91349141
if(error == 0) {
91359142
printStringLn("Testcase C1.50: Compare tuple attributes function returned successfully. " +
9136-
"differingAttributes = " + (rstring)differingAttributes);
9143+
", matchingAttributes = " + (rstring)matchingAttributes +
9144+
", differingAttributes = " + (rstring)differingAttributes);
91379145
} else {
91389146
printStringLn("Testcase C1.50: Compare tuple attributes function returned an error. Error=" + (rstring)error);
91399147
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ It fetches the value of a user given attribute name if it is present in the user
3131

3232
<function>
3333
<description>
34-
It compares the attribute values of two tuples that are made of the same schema and returns a list containing the attribute names that have differing values.
34+
It compares the attribute values of two tuples that are made of the same schema and returns a list containing the attribute names that have matching values and another list containing the attribute names that have differing values.
3535
@param myTuple1 First of the two user given tuples to be compared. Type: Tuple
3636
@param myTuple2 Second of the two user given tuples to be compared. Type: Tuple
37+
@param matchingAttributes A mutable list variable that will contain the attribute names that have matching values. Type: list&lt;rstring&gt;
3738
@param differingAttributes A mutable list variable that will contain the attribute names that have differing values. Type: list&lt;rstring&gt;
3839
@param error A mutable variable that will contain a non-zero error code if an error occurs. Type: int32
3940
@param trace A boolean value to enable tracing inside this function. Type: boolean
4041
@return It returns nothing. Type: void
4142
</description>
42-
<prototype>&lt;tuple T1> public void compare_tuple_attributes(T1 myTuple1, T1 myTuple2, mutable list&lt;rstring&gt; differingAttributes, mutable int32 error, boolean trace)</prototype>
43+
<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>
4344
</function>
4445
</functions>
4546

0 commit comments

Comments
 (0)