Fix bug in join() GREL function
This commit is contained in:
parent
f3f6a2846b
commit
c9786d0f9a
@ -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");
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user