GREL functions do not evaluate existing errors

7 views
Skip to first unread message

Jan Chaloupecky

unread,
Nov 6, 2022, 6:45:17 PM11/6/22
to OpenRefine Development
Hi,

I noticed that a GREL function will not be called at all if any of its parameters is an existing error value (EvalError). In this case, the EvalError is returned without calling the GREL function.

I believe it's due to this early return FunctionCallExpr.java#L64 

To reproduce it, import the following csv:

my_source,my_result
1,
A,

- apply a GREL transformation (Edit Cells > Transform ..)  "toNumber(cells.my_source.value)" on the column my_result 
- select onError: store error

-> the my_result has an error on the second row "Unable to parse as number" (which is expected)

Now, try a new transformation on the my_result cell and use any function which takes the value of my_source as parameter. The function will never be called for the row which has already and error.

So this essentially prevents any custom Grel functions to perform any processing on error values.

In my case, I implemented and registered a custom function from which I do return a EvalError in some cases. This is useful to indicate to the user that something is wrong.

My function takes as parameter the column which resulted in a previous run. This allows me to do faster processing in case a correct value is already present and do the processing only in case of missing or error values. So the call os something like

my_function("foo bar", cells.my_result.value)

However, my function is never called for rows where  my_result was previously set to an  EvalError.

The workaround could be to use a if condition like so

my_function("foo bar", if(isError(cells.my_result.value), null, cells.my_result.value))

but that's a bit cumbersome to use.


Is this the expected behaviour during the Grel evaluation?

thanks in advance 
Cheers
Jan


Tom Morris

unread,
Nov 7, 2022, 11:26:51 AM11/7/22
to openref...@googlegroups.com
On Sun, Nov 6, 2022 at 6:45 PM Jan Chaloupecky <jan.cha...@gmail.com> wrote:

I noticed that a GREL function will not be called at all if any of its parameters is an existing error value (EvalError). In this case, the EvalError is returned without calling the GREL function.

I believe it's due to this early return FunctionCallExpr.java#L64 

... 
Is this the expected behaviour during the Grel evaluation?

Given that the "git blame" annotations for the code that you found show that it's been operating that way for 13 years, I'd say that yes, it is expected behavior.

I think the much more common scenario this is intended to address is when you have multiple functions nested or chained. If OpenRefine were to continue processing and propagating the error to additional functions, the error would probably change into something entirely unrelated to the original problem, making it much more difficult to debug. By truncating processing at the first error, the error is immediately returned to the user.

If using the if() control is cumbersome, the other OpenRefine-ish way to do the conditionalization would be to use a facet on the error.

As an aside, I'm not sure I fully understand the design of your function, but it seems a little indirect to be passing a column name rather than just a cell value.

Tom

Jan Chaloupecky

unread,
Nov 7, 2022, 11:51:25 AM11/7/22
to openref...@googlegroups.com
Hi Tom,
thanks for your answer. 13 years seems indeed like an exptected behavior :)

My function does not take a column name as paramater but it’s value

It’s just in some cases I use “create new column based on this column” in which case I pass simply “value” and in other cases I use the Transform .. in which case I pass another column.value

anyway,
thanks for your reply

cheers
Jan

On 7. Nov 2022, at 17:26, Tom Morris <tfmo...@gmail.com> wrote:


--
You received this message because you are subscribed to a topic in the Google Groups "OpenRefine Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openrefine-dev/JFX7-oKm2xw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openrefine-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine-dev/CAE9vqEG2uqbozS8N1vDNbOo05wPefjYC%3DaEuBidYMoGKsqVHRA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages