|
8 | 8 | /*
|
9 | 9 | ==================================================================
|
10 | 10 | First created on: Mar/05/2021
|
11 |
| -Last modified on: Apr/18/2021 |
| 11 | +Last modified on: Apr/23/2021 |
12 | 12 |
|
13 | 13 | This is an example application that shows how to use the
|
14 | 14 | eval_predicate function to evaluate an SPL expression a.k.a
|
@@ -86,6 +86,13 @@ Following expressions use nested parenthesis.
|
86 | 86 | ((a == "hi" || c endsWith 'pqr') && (b contains "xyz")) || (g[4] > 6.7 || id % 8 == 3)
|
87 | 87 | (((a == 'hi') || (x <= 5) || (t == 3.14) || (p > 7)) && ((j == 3) && (y < 1) && (r == 9)) && s endsWith 'Nation')
|
88 | 88 |
|
| 89 | +In addition to showing how to do rule expression processing, |
| 90 | +this example also shows another feature of the eval_predicate |
| 91 | +toolkit i.e. how to get a value of a specific tuple attribute as |
| 92 | +that is expressed via a user provided string input. |
| 93 | +In this example, you can search for get_tuple_attribute_value to |
| 94 | +see 10 different test cases on that topic. |
| 95 | + |
89 | 96 | How can you use this new eval_predicate function?
|
90 | 97 | -------------------------------------------------
|
91 | 98 | Any other application that wants to use this function must
|
@@ -124,6 +131,13 @@ composite EvalPredicateExample {
|
124 | 131 | expression<boolean> $EVAL_PREDICATE_TRACING :
|
125 | 132 | (boolean)getSubmissionTimeValue("EvalPredicateTracing", "false");
|
126 | 133 |
|
| 134 | + // This constant can be used to specify whether the |
| 135 | + // value of the tuple attribute fetched via the |
| 136 | + // get_tuple_attribute_value should be displayed on |
| 137 | + // the console or not. |
| 138 | + expression<boolean> $DISPLAY_FETCHED_ATTRIBUTE_VALUE : |
| 139 | + (boolean)getSubmissionTimeValue("DisplayFetchedAttributeValue", "true"); |
| 140 | + |
127 | 141 | type
|
128 | 142 | // These are types or schema of the tuples that we will use to
|
129 | 143 | // evaluate different kinds of expressions.
|
@@ -165,6 +179,7 @@ composite EvalPredicateExample {
|
165 | 179 | logic
|
166 | 180 | onTuple S: {
|
167 | 181 | mutable rstring rule = "";
|
| 182 | + mutable rstring attributeName = ""; |
168 | 183 | mutable int32 error = 0;
|
169 | 184 | mutable boolean result = false;
|
170 | 185 |
|
@@ -322,6 +337,49 @@ composite EvalPredicateExample {
|
322 | 337 | } else {
|
323 | 338 | printStringLn("Testcase 2.4: Evaluation execution failed. Error=" + (rstring)error);
|
324 | 339 | }
|
| 340 | + |
| 341 | + // Get the value of a given tuple attribute name. |
| 342 | + // Arg1: Fully qualified attribute name |
| 343 | + // Arg2: Your tuple |
| 344 | + // Arg3: A mutable variable of an appropriate type in which the |
| 345 | + // value of a given attribute will be returned. |
| 346 | + // Arg4: A mutable int32 variable to receive non-zero error code if any. |
| 347 | + // Arg5: A boolean value to enable debug tracing inside this function. |
| 348 | + // It is a void method that returns nothing. |
| 349 | + // |
| 350 | + // 2.5 |
| 351 | + // Get an int32 value of a given tuple attribute name. |
| 352 | + attributeName = "employee.id"; |
| 353 | + mutable int32 employeeId = 0; |
| 354 | + get_tuple_attribute_value(attributeName, myEmployee, |
| 355 | + employeeId, error, $EVAL_PREDICATE_TRACING); |
| 356 | + |
| 357 | + if(error == 0) { |
| 358 | + printStringLn("Testcase 2.5: Tuple attribute value was fetched successfully."); |
| 359 | + |
| 360 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 361 | + printStringLn(attributeName + "=" + (rstring)employeeId); |
| 362 | + } |
| 363 | + } else { |
| 364 | + printStringLn("Testcase 2.5: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 365 | + } |
| 366 | + |
| 367 | + // 2.6 |
| 368 | + // Get the full set<rstring> value of a given tuple attribute name. |
| 369 | + attributeName = "employee.skills"; |
| 370 | + mutable set<rstring> employeeSkills = {}; |
| 371 | + get_tuple_attribute_value(attributeName, myEmployee, |
| 372 | + employeeSkills, error, $EVAL_PREDICATE_TRACING); |
| 373 | + |
| 374 | + if(error == 0) { |
| 375 | + printStringLn("Testcase 2.6: Tuple attribute value was fetched successfully."); |
| 376 | + |
| 377 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 378 | + printStringLn(attributeName + "=" + (rstring)employeeSkills); |
| 379 | + } |
| 380 | + } else { |
| 381 | + printStringLn("Testcase 2.6: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 382 | + } |
325 | 383 |
|
326 | 384 | // ============== TESTCASE GROUP 3 ==============
|
327 | 385 | mutable City_t myCity = {};
|
@@ -524,7 +582,118 @@ composite EvalPredicateExample {
|
524 | 582 | } else {
|
525 | 583 | printStringLn("Testcase 3.13: Evaluation execution failed. Error=" + (rstring)error);
|
526 | 584 | }
|
| 585 | + |
| 586 | + // Get the value of a given tuple attribute name. |
| 587 | + // Arg1: Fully qualified attribute name |
| 588 | + // Arg2: Your tuple |
| 589 | + // Arg3: A mutable variable of an appropriate type in which the |
| 590 | + // value of a given attribute will be returned. |
| 591 | + // Arg4: A mutable int32 variable to receive non-zero error code if any. |
| 592 | + // Arg5: A boolean value to enable debug tracing inside this function. |
| 593 | + // It is a void method that returns nothing. |
| 594 | + // |
| 595 | + // 3.14 |
| 596 | + // Get an rstring value of a given tuple attribute name. |
| 597 | + attributeName = "name"; |
| 598 | + mutable rstring cityName = ""; |
| 599 | + get_tuple_attribute_value(attributeName, myCity, |
| 600 | + cityName, error, $EVAL_PREDICATE_TRACING); |
| 601 | + |
| 602 | + if(error == 0) { |
| 603 | + printStringLn("Testcase 3.14: Tuple attribute value was fetched successfully."); |
| 604 | + |
| 605 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 606 | + printStringLn(attributeName + "=" + (rstring)cityName); |
| 607 | + } |
| 608 | + } else { |
| 609 | + printStringLn("Testcase 3.14: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 610 | + } |
| 611 | + |
| 612 | + // 3.15 |
| 613 | + // Get a float32 value of a given tuple attribute name. |
| 614 | + attributeName = "details.location.geo.latitude"; |
| 615 | + mutable float32 latitude = (float32)0.0; |
| 616 | + get_tuple_attribute_value(attributeName, myCity, |
| 617 | + latitude, error, $EVAL_PREDICATE_TRACING); |
| 618 | + |
| 619 | + if(error == 0) { |
| 620 | + printStringLn("Testcase 3.15: Tuple attribute value was fetched successfully."); |
| 621 | + |
| 622 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 623 | + printStringLn(attributeName + "=" + (rstring)latitude); |
| 624 | + } |
| 625 | + } else { |
| 626 | + printStringLn("Testcase 3.15: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 627 | + } |
| 628 | + |
| 629 | + // 3.16 |
| 630 | + // Get a list<rstring>[idx] value of a given tuple attribute name. |
| 631 | + attributeName = "details.location.info.businesses[2]"; |
| 632 | + mutable rstring businessName = ""; |
| 633 | + get_tuple_attribute_value(attributeName, myCity, |
| 634 | + businessName, error, $EVAL_PREDICATE_TRACING); |
| 635 | + |
| 636 | + if(error == 0) { |
| 637 | + printStringLn("Testcase 3.16: Tuple attribute value was fetched successfully."); |
| 638 | + |
| 639 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 640 | + printStringLn(attributeName + "=" + (rstring)businessName); |
| 641 | + } |
| 642 | + } else { |
| 643 | + printStringLn("Testcase 3.16: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 644 | + } |
| 645 | + |
| 646 | + // 3.17 |
| 647 | + // Get a map<rstring,rstring>[key] value of a given tuple attribute name. |
| 648 | + attributeName = "details.location.info.officials['Mayor']"; |
| 649 | + mutable rstring mayor = ""; |
| 650 | + get_tuple_attribute_value(attributeName, myCity, |
| 651 | + mayor, error, $EVAL_PREDICATE_TRACING); |
| 652 | + |
| 653 | + if(error == 0) { |
| 654 | + printStringLn("Testcase 3.17: Tuple attribute value was fetched successfully."); |
| 655 | + |
| 656 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 657 | + printStringLn(attributeName + "=" + (rstring)mayor); |
| 658 | + } |
| 659 | + } else { |
| 660 | + printStringLn("Testcase 3.17: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 661 | + } |
| 662 | + |
| 663 | + // 3.18 |
| 664 | + // Get the entire list<rstring> value of a given tuple attribute name. |
| 665 | + attributeName = "roadwayNumbers"; |
| 666 | + mutable list<int32> routeNumbers = []; |
| 667 | + get_tuple_attribute_value(attributeName, myCity, |
| 668 | + routeNumbers, error, $EVAL_PREDICATE_TRACING); |
| 669 | + |
| 670 | + if(error == 0) { |
| 671 | + printStringLn("Testcase 3.18: Tuple attribute value was fetched successfully."); |
| 672 | + |
| 673 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 674 | + printStringLn(attributeName + "=" + (rstring)routeNumbers); |
| 675 | + } |
| 676 | + } else { |
| 677 | + printStringLn("Testcase 3.18: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 678 | + } |
| 679 | + |
| 680 | + // 3.19 |
| 681 | + // Get the entire map<rstring,rstring> value of a given tuple attribute name. |
| 682 | + attributeName = "housingNumbers"; |
| 683 | + mutable map<rstring,int32> housingReport = {}; |
| 684 | + get_tuple_attribute_value(attributeName, myCity, |
| 685 | + housingReport, error, $EVAL_PREDICATE_TRACING); |
527 | 686 |
|
| 687 | + if(error == 0) { |
| 688 | + printStringLn("Testcase 3.19: Tuple attribute value was fetched successfully."); |
| 689 | + |
| 690 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 691 | + printStringLn(attributeName + "=" + (rstring)housingReport); |
| 692 | + } |
| 693 | + } else { |
| 694 | + printStringLn("Testcase 3.19: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 695 | + } |
| 696 | + |
528 | 697 | // ============== TESTCASE GROUP 4 ==============
|
529 | 698 | mutable AccuWeather_t myWeather = {};
|
530 | 699 | myWeather.city = "New York";
|
@@ -583,6 +752,48 @@ composite EvalPredicateExample {
|
583 | 752 | printStringLn("Testcase 4.2: Evaluation execution failed. Error=" + (rstring)error);
|
584 | 753 | }
|
585 | 754 |
|
| 755 | + // Get the value of a given tuple attribute name. |
| 756 | + // Arg1: Fully qualified attribute name |
| 757 | + // Arg2: Your tuple |
| 758 | + // Arg3: A mutable variable of an appropriate type in which the |
| 759 | + // value of a given attribute will be returned. |
| 760 | + // Arg4: A mutable int32 variable to receive non-zero error code if any. |
| 761 | + // Arg5: A boolean value to enable debug tracing inside this function. |
| 762 | + // It is a void method that returns nothing. |
| 763 | + // |
| 764 | + // 4.3 |
| 765 | + // Get a list<TUPLE>[idx] value of a given tuple attribute name. |
| 766 | + attributeName = "weatherList[0].hourlyTemperatureMap"; |
| 767 | + mutable map<int64, float64> myTemperatureMap = {}; |
| 768 | + get_tuple_attribute_value(attributeName, accuWeatherTestData, |
| 769 | + myTemperatureMap, error, $EVAL_PREDICATE_TRACING); |
| 770 | + |
| 771 | + if(error == 0) { |
| 772 | + printStringLn("Testcase 4.3: Tuple attribute value was fetched successfully."); |
| 773 | + |
| 774 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 775 | + printStringLn(attributeName + "=" + (rstring)myTemperatureMap); |
| 776 | + } |
| 777 | + } else { |
| 778 | + printStringLn("Testcase 4.3: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 779 | + } |
| 780 | + |
| 781 | + // 4.4 |
| 782 | + // Get the entire list<TUPLE> value of a given tuple attribute name. |
| 783 | + attributeName = "weatherList"; |
| 784 | + mutable list<AccuWeather_t> myWeatherList = []; |
| 785 | + get_tuple_attribute_value(attributeName, accuWeatherTestData, |
| 786 | + myWeatherList, error, $EVAL_PREDICATE_TRACING); |
| 787 | + |
| 788 | + if(error == 0) { |
| 789 | + printStringLn("Testcase 4.4: Tuple attribute value was fetched successfully."); |
| 790 | + |
| 791 | + if($DISPLAY_FETCHED_ATTRIBUTE_VALUE == true) { |
| 792 | + printStringLn(attributeName + "=" + (rstring)myWeatherList); |
| 793 | + } |
| 794 | + } else { |
| 795 | + printStringLn("Testcase 4.4: Tuple attribute value was not fetched successfully. Error=" + (rstring)error); |
| 796 | + } |
586 | 797 | } // End of onTuple S
|
587 | 798 | } // End of the Custom operator.
|
588 | 799 | } // End of the main composite.
|
0 commit comments