C++ Native Functions: com.teracloud.streams.evalpredicate

This page documents native functions that can be invoked from SPL, including the SPL interfaces that can be used to invoke each of the native functions.

Functions

<tuple T1> public void compare_tuple_attributes(T1 myTuple1, T1 myTuple2, mutable list<rstring> matchingAttributes, mutable list<rstring> differingAttributes, mutable int32 error, boolean trace)

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.

Example

mutable int32 err;
mutable list<rstring> match;
mutable list<rstring> differ;
  
tuple<rstring name, uint8 age> myTuple1 = { "John", 42 };
tuple<rstring name, uint8 age> myTuple2 = { "John", 25 };

compare_tuple_attributes(myTuple1, myTuple2, match, differ, err, false);

// matchingAttributes contains 'name'
// differingAttributes contains 'age'
Parameters
myTuple1

First of the two user given tuples to be compared.

myTuple2

Second of the two user given tuples to be compared.

matchingAttributes

A mutable list variable to store the attribute names that have matching values.

differingAttributes

A mutable list variable to store the attribute names that have differing values.

error

A mutable variable to store a non-zero error code if an error occurs.

trace

A boolean value to enable tracing inside this function.

<tuple T> public boolean eval_predicate(rstring expr, T myTuple, mutable int32 error, boolean trace)

Evaluates a user-defined rule (i.e. expression) represented as an rstring using the given tuple.

Note: The standard toolkit offers a function named evalPredicate. This function differs in the following way:
  1. Expressions accessing map elements are supported
  2. Expressions accessing nested tuple attributes are supported
  3. Operational verbs for rstring, set, list and map are supported.
Expressions support the following operations:
  • Relational operations: ==, !=, <, <=, >, >=
  • Arithmetic operations: +, -, *, /, %
  • Special operations for rstring, set, list and map: contains, startsWith, endsWith, notContains, notStartsWith, notEndsWith, in
    • For case insensitive (CI) string operations, these operational verbs can be used: containsCI, startsWithCI, endsWithCI, notContainsCI, notStartsWithCI, notEndsWithCI, inCI, equalsCI, notEqualsCI
  • Size operations for set, list and map: sizeEQ, sizeNE, sizeLT, sizeLE, sizeGT, sizeGE

Note: No bitwise operations are supported at this time.

Zero, single level, or multilevel (nested) parentheses can also be used to group subexpressions. Within a given subexpression, you must use the same logical operators.

Supported types

Following are the data types currently allowed in an expression (rule):


boolean, int32, uint32, int64, uint64, float32, float64, rstring,
set<int32>, set<int64>, set<float32>, set<float64>, set<rstring>,
list<int32>, list<int64>, list<float32>, list<float64>, list<rstring>, list<TUPLE>, 
map<rstring,int32>, map<int32,rstring>, map<rstring,int64>, map<int64,rstring>,
map<rstring,float32>, map<float32,rstring>, map<rstring,float64>,
map<float64,rstring>, map<rstring,rstring>, map<int32,int32>, map<int32,int64>, 
map<int64,int32>, map<int64,int64>, map<int32,float32>, map<int32,float64>, 
map<int64,float32>, map<int64,float64>, map<float32,int32>, map<float32,int64>, 
map<float64,int32>, map<float64,int64>, map<float32,float32>, map<float32,float64>, 
map<float64,float32>, map<float64,float64> and nested tuple references
pointing to any of the attributes made using the types shown above.

Examples

The following examples are valid expressions:


// Zero parentheses present
a == "hi" && b contains "xyz" && g[4] > 6.7 && id % 8 == 3

// Single level parentheses used
(a == "hi") && (b contains "xyz" || g[4] > 6.7 || id % 8 == 3)
(a == "hi") && (b contains "xyz") && (g[4] > 6.7) && (id % 8 == 3)

// Nested parentheses used
(a == "hi") && ((b contains "xyz" || g[4] > 6.7) && id % 8 == 3)
(a == "hi") && (b contains "xyz" && (g[4] > 6.7 || id % 8 == 3))
(a == "hi") && ((b contains "xyz") || (g[4] > 6.7) || (id % 8 == 3))
(a == "hi") && ((b contains "xyz") || (g[4] > 6.7 || id % 8 == 3))
((a == "hi" || c endsWith 'pqr') && (b contains "xyz")) || (g[4] > 6.7 || id % 8 == 3)
(((a == 'hi') || (x <= 5) || (t == 3.14) || (p > 7)) && ((j == 3) && (y < 1) && (r == 9)) && s endsWith 'Nation')

The following example showcases how to call the function:


tuple<rstring name, float32 price> myTicker = {};
mutable int32 err;

// Evaluate an expression (i.e. rule).
result = eval_predicate("(price == -476.18)", myTicker, err, false);
Parameters
expr

User defined rule (expression) to be evaluated i.e. processed.

myTuple

A user defined tuple whose attributes the rule (expression) should refer to.

error

A mutable variable that will contain a non-zero error code if a rule processing error occurs.

trace

A boolean value to enable tracing inside this function.

Returns

true when the rule evaluation (i.e. processing) is successful. Otherwise, false.

<tuple T1, any T2> public void get_tuple_attribute_value(rstring attributeName, T1 myTuple, mutable T2 value, mutable int32 error, boolean trace)

Fetches the value of a user given attribute name if it is present in the user given tuple.

Example

mutable int32 err;
mutable rstring obtainedName;
  
tuple<rstring name, uint8 age> myTuple = { "John", 42 }

get_tuple_attribute_value("name", myTuple, obtainedName, err, false);

// obtainedName contains "John"
Parameters
attributeName

A user given fully qualified attribute name.

myTuple

A user defined tuple in which the user given attribute is present.

value

A mutable variable in which the value of a user given attribute will be returned.

error

A mutable variable that will contain a non-zero error code if an error occurs.

trace

A boolean value to enable tracing inside this function.

<tuple T1> public void get_tuple_schema_and_attribute_info(T1 myTuple, mutable rstring schema, mutable map<rstring, rstring> attributeInfo, mutable int32 error, boolean trace)

Fetches the schema literal string of a given tuple along with the information about all of its attributes.

Example

mutable int32 err;
mutable rstring obtainedSchema;
mutable map<rstring,rstring> attributesMap;
  
tuple<rstring name, uint8 age> myTuple = { "John", 42 };

get_tuple_schema_and_attribute_info(myTuple, obtainedSchema, attributesMap, err, false);

// obtainedSchema contains "tuple<rstring name, uint8 age>"
// attributesMap contains {"name": "rstring"}, {"age": "uint8"}
Parameters
myTuple

A user defined tuple for which schema and attribute information will be obtained.

schema

A mutable variable in which the complete schema literal string of a given tuple will be returned.

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.

error

A mutable variable that will contain a non-zero error code if an error occurs.

trace

A boolean value to enable tracing inside this function.