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.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.google.refine.expr.EvalError;
|
import com.google.refine.expr.EvalError;
|
||||||
import com.google.refine.expr.ExpressionUtils;
|
import com.google.refine.expr.ExpressionUtils;
|
||||||
|
import com.google.refine.expr.util.JsonValueConverter;
|
||||||
import com.google.refine.grel.ControlFunctionRegistry;
|
import com.google.refine.grel.ControlFunctionRegistry;
|
||||||
import com.google.refine.grel.Function;
|
import com.google.refine.grel.Function;
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ public class Join implements Function {
|
|||||||
sb.append(separator);
|
sb.append(separator);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
sb.append(a.get(i).toString());
|
sb.append(JsonValueConverter.convert(a.get(i)).toString());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
|
||||||
" cannot retrieve element " + i + " of array");
|
" cannot retrieve element " + i + " of array");
|
||||||
|
@ -180,6 +180,12 @@ public class GrelTests extends RefineTest {
|
|||||||
Assert.assertNull(eval.evaluate(bindings));
|
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
|
@Test
|
||||||
public void testGetFieldFromNull() throws ParsingException {
|
public void testGetFieldFromNull() throws ParsingException {
|
||||||
String test = "null.value";
|
String test = "null.value";
|
||||||
|
Loading…
Reference in New Issue
Block a user