EvalEx icon indicating copy to clipboard operation
EvalEx copied to clipboard

Determine evaluation result type without evaluating

Open michelkaeser opened this issue 1 year ago • 2 comments

I have a use-case where it would be highly beneficial if there would be a possibility to determine the result type an expression will yield (if executed successfully).

Is this already possible with the existing API? I tried to use the AST API but could not find a way.

michelkaeser avatar Apr 05 '24 07:04 michelkaeser

I think that is impossible because of conditionals (IF). Conditionals might return any type in one of their branches, and you'll only know which if you evaluate the condition.

But I might be wrong here.

RobertZenz avatar Apr 05 '24 13:04 RobertZenz

For expressions that have no IF and now also SWITCH function, it should be possible.

It could be done externally, using the AST by more or less using the logic in evaluateSubtree(). Instead of executing the calculation, the result would just be the data type. One would have to take care of some special cases, like adding strings to numbers or durations to date-times etc.

Another (more cleaner) way would require to change the function and operator interfaces, adding a method e.g. determineResultDataType(). Rest would be the same as above, but it would have the advantage of determine the data type would be also in the function/operator class.

uklimaschewski avatar May 26 '24 08:05 uklimaschewski