OpenRefine / OpenRefine

OpenRefine is a free, open source power tool for working with messy data and improving it
https://openrefine.org/
BSD 3-Clause "New" or "Revised" License
10.82k stars 1.95k forks source link

Variable columnNames is not available in Jython #4481

Open wetneb opened 2 years ago

wetneb commented 2 years ago

The variable columnNames is not available in Jython, whereas it is available in GREL. It is useful to iterate over all cells in a row, for instance with this expression: forEach(row.columnNames,cn,cells[cn].value) (see https://groups.google.com/g/openrefine/c/gV0bLUz7p7o)

Proposed solution

We could make this variable available in Jython too. It would also be good to document which variable names (and fields) are available in Jython, if this is really meant to differ from what is available in GREL.

Alternatives considered

Make sure all variables and fields offered in GREL are also available in Jython and Clojure.

Keetna commented 2 years ago

Hi @wetneb , Im new to opensource . Could you assign this task to me and assist me to get cleared on my first issue? Thanks.

wetneb commented 2 years ago

Hi @Keetna, thanks for volunteering! We have a guide for new contributors here, let me know if you get stuck at any stage: https://docs.openrefine.org/technical-reference/contributing#your-first-code-pull-request

Binita-tech commented 2 years ago

@wetneb, I would like to work on this issue, kindly assign it to me.

Binita-tech commented 2 years ago

I found columnNames variable in GREL here: image Now, I have to make available the same variable in Jython image Is this only documentaion work? Please correct me if I am wrong @wetneb

antoine2711 commented 2 years ago

Now, I have to make available the same variable in Jython

Yes @Binita-tech.

Is this only documentaion work? Please correct me if I am wrong @wetneb

It's both. Adding code so Jython can handle the variable, and adding the corresponding documentation.

For the documentation, you could also document all the variables available in Jython. But it is not required, another issue could be opened for that.

Regards, Antoine

jenny-Musah commented 1 year ago

Hi @wetneb, I am a new bee to open source and so I would just say I think would work I think creating a temporary CSV file that contains all the variables in GREL and then we export the CSV file from the GREL so that the Jython or Clojure code retrieves the variable value when the read the file.

Do you think it would work

wetneb commented 1 year ago

It sounds rather complicated and I do not think this is likely to work. I think this issue should be rather simple to fix once you have reviewed the existing Jython integration: it is just about adding another parameter to the Python function that is generated before evaluation.

jenny-Musah commented 1 year ago

Oh okay....except that I don't know where to find the code, I am still trying to understand the code base, please can I get the git hub file part to this code, so that i can try to make a contribution.

ostephens commented 1 year ago

I'm not very familiar with the Jython integration but I think the code that @wetneb is referring to is here https://github.com/OpenRefine/OpenRefine/blob/ab59b30a4527e844dd7ab37f2e56845b12effee0/extensions/jython/src/com/google/refine/jython/JythonEvaluable.java#L99

This (if I'm reading it correctly) creates a python function that accepts a set of arguments which correspond to the GREL variables that can then be used in the function. Then further down the file there is the evaluate method which defines the bindings

Others maybe able to confirm or correct my reading of the code

jenny-Musah commented 1 year ago

@ostephens Thanks

jenny-Musah commented 1 year ago

@wetneb, I would like to be assigned to this fix, if I understand what is going on, I should add a parameter called coloumnName, to the constructor "JythonEvaluable", The parameter should help the function loop through each cell, right?

wetneb commented 1 year ago

Adding a columnNames parameter in the JythonEvaluable sounds appropriate indeed. Good luck!

github-actions[bot] commented 1 year ago

Automatically unassigned after 45 days of inactivity.

MahmoudAbdelkhaleq commented 6 months ago

Hello @wetneb, I would like to work on this issue, kindly assign it to me.

github-actions[bot] commented 5 months ago

Automatically unassigned after 45 days of inactivity.

tfmorris commented 1 week ago

My testing indicates

grel:columnNames => null grel:row.columnNames => array of column names jython:return columnNames => NameError: global name 'columnNames' is not defined jython:return row.columnNames => array of columnNames jython:return row["columnNames"] => array of columnNames

so I think we have parity between GREL and Jython in this area. There is no columnNames variable at the top level for either language.

The current list of top level variables and their fields as available here: https://github.com/OpenRefine/OpenRefine/issues/2523#issuecomment-713835727

thadguidry commented 1 week ago

I just wanted to point out this little fact that - for the variable, we have our docs stating otherwise, with the non-plural form columnName and not plural columnNames , but then row gained a member field that IS plural with columnNames ?

image

wetneb commented 1 week ago

Yes, the difference in plural/singular seems to match the expected semantics:

So I think that's consistent.