Hello! I’m using Version 3.4.1, and trying to add a column based on an existing column. (The original contains a list, and I’m trying to select the last item.) The preview shows the result I’m expecting, but when the column is created, the cells are empty. My (possibly inelegant) grel is:
value.split(", “).slice(length(value.split(”, "))-1)
Any ideas how I can get the actual result to resemble the preview result?
Thanks!
Jen
P.S. If I ask it to store error:
“Object [ ] value not storable”
Hello! I’m using Version 3.4.1, and trying to add a column based on an existing column. (The original contains a list, and I’m trying to select the last item.) The preview shows the result I’m expecting, but when the column is created, the cells are empty. My (possibly inelegant) grel is:
value.split(", “).slice(length(value.split(”, "))-1)
Any ideas how I can get the actual result to resemble the preview result?
Your expression creates an array which can't be stored in a cell (it can only be used for intermediary values). You can simplify things by using negative indexes to index relative to the end of the array. Try the following:
value.split(", “)[-1]
Tom
Ah, I understand. Thanks very much! I have a lot to learn about the distinctions among different kinds of objects.
Object[] value not storable
@jhammock Yeah, that's not helpful at all to you is it? What if we changed the output to say something like the below Stored Error?
@tfmorris We could do better, I tried to improve it, but cannot get this code to work in ExpressionUtils.java to work:
static public Serializable wrapStorable(Object v) {
if (v instanceof ArrayNode) {
return ((ArrayNode) v).toString();
} else if (v instanceof ObjectNode) {
return ((ObjectNode) v).toString();
} else if (v.getClass().isArray()) {
return new EvalError(
"Stored Error: Your expression created an Array."
+ "Only Number, String, Boolean, OffsetDateTime can be stored in a cell."
+ "HINT: try appending to your expression: .join(',') to store as a String.");
} else {
return isStorable(v) ? (Serializable) v : new EvalError(v.getClass().getSimpleName() + " value not storable");
}
}
@thadguidry I dig the detailed error message. Given that HINT, I might not have learned the streamlined solution @tfmorris provided, but it did work for my case, and I can see it would generalize for other people finishing with an array.