Skip to content

Commit

Permalink
Changes done for v1.1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Senthil Nathan committed Oct 17, 2021
1 parent 4019bfc commit 6835266
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 91 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## v1.1.3
* Oct/16/2021
* 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.

## v1.1.2
* Oct/16/2021
* 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.
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if(error == 0) {
// It is a void function that returns nothing.
```

**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.
**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.

```
// This namespace usage declaration is needed at the top of an application.
Expand All @@ -122,6 +122,7 @@ type Test_t = boolean a, int32 b, uint64 c, float32 d, float64 e,
// Create two tuples that are based on the same schema.
mutable Test_t myTuple1 = {};
mutable Test_t myTuple2 = {};
mutable list<rstring> matchingAttributes = [];
mutable list<rstring> differingAttributes = [];
// Populate the tuple with some data.
Expand Down Expand Up @@ -157,24 +158,29 @@ block(2.0);
myTuple2.k.o = getTimestamp();
// Compare them now.
compare_tuple_attributes(myTuple1, myTuple2, differingAttributes,
error, $EVAL_PREDICATE_TRACING);
compare_tuple_attributes(myTuple1, myTuple2,
matchingAttributes, differingAttributes,
error, $EVAL_PREDICATE_TRACING);
if(error == 0) {
printStringLn("Compare tuple attributes function returned successfully. " +
"differingAttributes = " + (rstring)differingAttributes);
"matchingAttributes = " + (rstring)matchingAttributes +
", differingAttributes = " + (rstring)differingAttributes);
} else {
printStringLn("Compare tuple attributes function returned an error. Error=" + (rstring)error);
printStringLn("Compare tuple attributes function returned an error. Error=" +
(rstring)error);
}
}
// Following is the usage description for the compare_tuple_attributes function.
//
// Arg1: Your tuple1
// Arg2: Your tuple2
// Arg3: A mutable variable of list<string> type in which the
// attribute names that have a match in their values will be returned.
// Arg4: A mutable variable of list<string> type in which the
// attribute names that differ in their values will be returned.
// Arg4: A mutable int32 variable to receive non-zero error code if any.
// Arg5: A boolean value to enable debug tracing inside this function.
// Arg5: A mutable int32 variable to receive non-zero error code if any.
// Arg6: A boolean value to enable debug tracing inside this function.
// It is a void function that returns nothing.
```

Expand Down
20 changes: 14 additions & 6 deletions com.ibm.streamsx.eval_predicate/EvalPredicateExample.spl
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,11 @@ composite EvalPredicateExample {
// Arg1: Your tuple1
// Arg2: Your tuple2
// Arg3: A mutable variable of list<string> type in which the
// attribute names that have a match in their values will be returned.
// Arg4: A mutable variable of list<string> type in which the
// attribute names that differ in their values will be returned.
// Arg4: A mutable int32 variable to receive non-zero error code if any.
// Arg5: A boolean value to enable debug tracing inside this function.
// Arg5: A mutable int32 variable to receive non-zero error code if any.
// Arg6: A boolean value to enable debug tracing inside this function.
//
// 2.7
// Compare two tuples that have no differing attribute values.
Expand All @@ -420,6 +422,7 @@ composite EvalPredicateExample {
// Create two tuples that are based on the same schema.
mutable Test_t myTuple1 = {};
mutable Test_t myTuple2 = {};
mutable list<rstring> matchingAttributes = [];
mutable list<rstring> differingAttributes = [];

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

// Compare them now.
compare_tuple_attributes(myTuple1, myTuple2,
differingAttributes, error, $EVAL_PREDICATE_TRACING);
matchingAttributes, differingAttributes,
error, $EVAL_PREDICATE_TRACING);

if(error == 0) {
printStringLn("Testcase 2.7: Compare tuple attributes function returned successfully. " +
"differingAttributes = " + (rstring)differingAttributes);
", matchingAttributes = " + (rstring)matchingAttributes +
", differingAttributes = " + (rstring)differingAttributes);
} else {
printStringLn("Testcase 2.7: Compare tuple attributes function returned an error. Error=" + (rstring)error);
}
Expand All @@ -470,14 +475,17 @@ composite EvalPredicateExample {
myTuple2.k.o = getTimestamp();

// Clear the list.
matchingAttributes = (list<rstring>)[];
differingAttributes = (list<rstring>)[];
// Compare them now.
compare_tuple_attributes(myTuple1, myTuple2,
differingAttributes, error, $EVAL_PREDICATE_TRACING);
matchingAttributes, differingAttributes,
error, $EVAL_PREDICATE_TRACING);

if(error == 0) {
printStringLn("Testcase 2.8: Compare tuple attributes function returned successfully. " +
"differingAttributes = " + (rstring)differingAttributes);
", matchingAttributes = " + (rstring)matchingAttributes +
", differingAttributes = " + (rstring)differingAttributes);
} else {
printStringLn("Testcase 2.8: Compare tuple attributes function returned an error. Error=" + (rstring)error);
}
Expand Down
28 changes: 18 additions & 10 deletions com.ibm.streamsx.eval_predicate/FunctionalTests.spl
Original file line number Diff line number Diff line change
Expand Up @@ -9059,9 +9059,11 @@ composite FunctionalTests {
// Arg1: Your tuple1
// Arg2: Your tuple2
// Arg3: A mutable variable of list<string> type in which the
// attribute names that have a match in their values will be returned.
// Arg4: A mutable variable of list<string> type in which the
// attribute names that differ in their values will be returned.
// Arg4: A mutable int32 variable to receive non-zero error code if any.
// Arg5: A boolean value to enable debug tracing inside this function.
// Arg5: A mutable int32 variable to receive non-zero error code if any.
// Arg6: A boolean value to enable debug tracing inside this function.
//
// C1.49
// Compare two tuples that have no differing attribute values.
Expand All @@ -9076,6 +9078,7 @@ composite FunctionalTests {
// Create two tuples that are based on the same schema.
mutable Test_t myTuple1 = {};
mutable Test_t myTuple2 = {};
mutable list<rstring> matchingAttributes = [];
mutable list<rstring> differingAttributes = [];

// Populate the tuple with some data.
Expand All @@ -9093,19 +9096,21 @@ composite FunctionalTests {
myTuple1.k.m.y = 936.27;
myTuple1.k.m.z = "String inside a nested tuple.";
myTuple1.k.m.l = [67, 78, 89];
myTuple1.k.n = {1:true, 2:false, 3:true};
myTuple1.k.n = {1:true, 2:false, 3:true};
myTuple1.k.o = getTimestamp();

// Make the second tuple same as the first tuple.
myTuple2 = myTuple1;

// Compare them now.
compare_tuple_attributes(myTuple1, myTuple2,
differingAttributes, error, $EVAL_PREDICATE_TRACING);
matchingAttributes, differingAttributes,
error, $EVAL_PREDICATE_TRACING);

if(error == 0) {
printStringLn("Testcase C1.49: Compare tuple attributes function returned successfully. " +
"differingAttributes = " + (rstring)differingAttributes);
", matchingAttributes = " + (rstring)matchingAttributes +
", differingAttributes = " + (rstring)differingAttributes);
} else {
printStringLn("Testcase C1.49: Compare tuple attributes function returned an error. Error=" + (rstring)error);
}
Expand All @@ -9120,20 +9125,23 @@ composite FunctionalTests {
myTuple2.i = {10:'Ten', 9:'Nine', 8:'Eight'};
myTuple2.k.m.y = 27.93;
myTuple2.k.m.z = "Different string inside a nested tuple.";
myTuple2.k.n = {1:true, 2:true, 3:true};
myTuple2.k.n = {1:true, 2:true, 3:true};
// Wait for 2 seconds for time to change.
block(2.0);
myTuple2.k.o = getTimestamp();

// Clear the list.
matchingAttributes = (list<rstring>)[];
differingAttributes = (list<rstring>)[];
// Compare them now.
compare_tuple_attributes(myTuple1, myTuple2,
differingAttributes, error, $EVAL_PREDICATE_TRACING);
matchingAttributes, differingAttributes,
error, $EVAL_PREDICATE_TRACING);

if(error == 0) {
printStringLn("Testcase C1.50: Compare tuple attributes function returned successfully. " +
"differingAttributes = " + (rstring)differingAttributes);
", matchingAttributes = " + (rstring)matchingAttributes +
", differingAttributes = " + (rstring)differingAttributes);
} else {
printStringLn("Testcase C1.50: Compare tuple attributes function returned an error. Error=" + (rstring)error);
}
Expand Down
5 changes: 3 additions & 2 deletions com.ibm.streamsx.eval_predicate/native.function/function.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ It fetches the value of a user given attribute name if it is present in the user

<function>
<description>
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.
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.
@param myTuple1 First of the two user given tuples to be compared. Type: Tuple
@param myTuple2 Second of the two user given tuples to be compared. Type: Tuple
@param matchingAttributes A mutable list variable that will contain the attribute names that have matching values. Type: list&lt;rstring&gt;
@param differingAttributes A mutable list variable that will contain the attribute names that have differing values. Type: list&lt;rstring&gt;
@param error A mutable variable that will contain a non-zero error code if an error occurs. Type: int32
@param trace A boolean value to enable tracing inside this function. Type: boolean
@return It returns nothing. Type: void
</description>
<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>
<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>
</function>
</functions>

Expand Down
Loading

0 comments on commit 6835266

Please sign in to comment.