row.columnNames
forEach(row.columnNames,cn,cells[cn].value)
Merging all columns in a project
To merge all values across a row, you can use 'row.columnNames' (which retrieves all the column names in the project) with the 'cells' variable:
forEach(row.columnNames,cn,cells[cn].value).join("|")
If there are 'null' cells in the row, the row will still merge, but where the cells were null you will get the phrase "Cannot retrieve field from null|" If there are empty strings ("") in any cell in the row, these will be merged as empty strings.
To make null cells and cells with empty strings behave in the same way you can enhance the GREL given above with a check for null cells:
forEach(row.columnNames,cn,if(isNull(cells[cn]),"",cells[cn].value))
Facet for rows with a certain number of blank cells
If you want to find rows that have a certain number of blank cells, including 'all blank' or 'no blanks' you can create a custom facet:
Facet->Custom text facet (from any column in the project)
use the GREL:
filter(row.columnNames,cn,isBlank(cells[cn].value)).length()
This will give a facet with the number of blank (null or empty strings) cells in each row. If you want to limit by a particular number you can enhance the GREL with a check for a specific length:
Rows with more than one blank cell (true/false facet)
filter(row.columnNames,cn,isBlank(cells[cn].value)).length()>1
Rows with exactly one blank cell (true/false facet)
filter(row.columnNames,cn,isBlank(cells[cn].value)).length()==1
Rows with less than two blank cells (true/false facet)
filter(row.columnNames,cn,isBlank(cells[cn].value)).length()<2
--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
filter(row.columnNames,cn,or(cells[cn].value.startsWith(" "),cells[cn].value.endsWith(" ")))
id,var1,var2,var3
1,7,a,2017-06-19
2,4.3,xy,
3,,,2017-07-21
"INSERT INTO table ("+forEach(row.columnNames,cn,cn).join(", ")+") VALUES ("+forEach(row.columnNames,cn,if(isNumeric(cells[cn].value),cells[cn].value,"'"+cells[cn].value+"'")).join(", ").replace('Cannot retrieve field from null','NULL')+");"
INSERT INTO table (id, var1, var2, var3) VALUES (1, 7, 'a', '2017-06-19');
INSERT INTO table (id, var1, var2, var3) VALUES (2, '4.3', 'xy', NULL);
INSERT INTO table (id, var1, var2, var3) VALUES (3, NULL, NULL, '2017-07-21');
Wolf