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");
|
||||
|
@ -179,6 +179,12 @@ public class GrelTests extends RefineTest {
|
||||
Evaluable eval = MetaParser.parse("grel:" + test);
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user