I've decided to go in a slightly different direction with this. After refamilarizing myself with StreamOperations, it became clear that operations are meant to modify tuples. For example, the ReplaceOperation replaces some field value with some other value via the
function. Newer operations like the BooleanOperation extends that with an evaluate() function, but I find it's not quite as clear as it could be.
Bringing this back to the problem we want to solve: we want to evaluate some value based on a tuple. This isn't meant to modify a tuple but instead to calculate new values from other values that exist within tuple. This is true whether we are adding, multiplying, determining equality, greater than, or choosing with an if/else. We are evaluating, but not modifying, the tuple.
To solve this problem, I'm introducing a new set of classes called StreamEvaluators. StreamEvaluators follow the same functional expression structure as everything else within the streaming sphere and define the function
public Object evaluate(Tuple)
. The object returned from this function is the result of the evaluation against the tuple. For example, the result returned for the expresssion
is the result of field a added to field b. The datatype of the returned result is determined by the evaluator and the source field types. For example,
could reasonably return a Number, either Long or Double, while
could reasonably return a Boolean, while
could reasonably return any type.
StreamEvaluators come in two basic flavors - those that can contain other evaluators and those that can't.
add(a,b) sub(add(a,b),c) mult(if(gt("a",b),a,b),c) if(eq(a,b),val(34),c) if(eq(a,b),val(foo),c) if(eq(a,null),b,c)
There are a couple pieces of note in here.
As a result of this, the class structure is turning into this.
ComplexEvaluator NumberEvaluator AbsoluteValueEvaluator AddEvaluator DivideEvaluator MultiplyEvaluator SubtractEvaluator BooleanEvaluator AndEvaluator EqualsEvaluator GreaterThanEqualToEvaluator
SimpleEvaluator ValueEvaluator FieldEvaluator
StreamEvaluators will become a type of parameter supported by the SelectStream and executed after the execution of operations in that select clause. The result of the evaluation will be put into the tuple under the 'as' field name.
select(...,add(a,b) as aPlusb)