Fix bug in join() GREL function

This commit is contained in:
Antonin Delpeuch 2018-11-19 16:42:41 +00:00
parent f3f6a2846b
commit c9786d0f9a
2 changed files with 8 additions and 1 deletions

View File

@ -41,6 +41,7 @@ import org.json.JSONException;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.expr.util.JsonValueConverter;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
@ -75,7 +76,7 @@ public class Join implements Function {
sb.append(separator);
}
try {
sb.append(a.get(i).toString());
sb.append(JsonValueConverter.convert(a.get(i)).toString());
} catch (JSONException e) {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
" cannot retrieve element " + i + " of array");

View File

@ -180,6 +180,12 @@ public class GrelTests extends RefineTest {
Assert.assertNull(eval.evaluate(bindings));
}
@Test
public void testJoinJsonArray() throws ParsingException {
String test[] = { "\"{\\\"values\\\":[\\\"one\\\",\\\"two\\\",\\\"three\\\"]}\".parseJson().values.join(\",\")", "one,two,three" };
parseEval(bindings, test);
}
@Test
public void testGetFieldFromNull() throws ParsingException {
String test = "null.value";