Merge pull request #1692 from OpenRefine/issue1689

Fix exception when sorting the empty string numerically
This commit is contained in:
Antonin Delpeuch 2018-08-30 08:09:20 +02:00 committed by GitHub
commit 94b6b1f945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 2 deletions

View File

@ -53,7 +53,7 @@ public class BooleanCriterion extends Criterion {
return s_error; return s_error;
} }
} }
return value; return null;
} }
@Override @Override

View File

@ -66,7 +66,7 @@ public class NumberCriterion extends Criterion {
} }
return s_error; return s_error;
} }
return value; return null;
} }
@Override @Override

View File

@ -0,0 +1,53 @@
package com.google.refine.tests.operations.row;
import java.util.Properties;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.ProjectManager;
import com.google.refine.browsing.Engine.Mode;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Cell;
import com.google.refine.model.Project;
import com.google.refine.operations.row.RowReorderOperation;
import com.google.refine.process.Process;
import com.google.refine.tests.RefineTest;
public class RowReorderOperationTests extends RefineTest {
Project project = null;
@BeforeMethod
public void setUp() {
project = createCSVProject(
"key,first\n"+
"8,b\n"+
",d\n"+
"2,f\n"+
"1,h\n");
}
@AfterMethod
public void tearDown() {
ProjectManager.singleton.deleteProject(project.id);
}
@Test
public void testSortEmptyString() throws Exception {
project.rows.get(1).cells.set(0, new Cell("", null));
AbstractOperation op = new RowReorderOperation(
Mode.RowBased,
new JSONObject("{\"criteria\":[{\"column\":\"key\",\"valueType\":\"number\",\"reverse\":false,\"blankPosition\":2,\"errorPosition\":1}]}"));
Process process = op.createProcess(project, new Properties());
process.performImmediate();
Assert.assertEquals("h", project.rows.get(0).cells.get(1).value);
Assert.assertEquals("f", project.rows.get(1).cells.get(1).value);
Assert.assertEquals("b", project.rows.get(2).cells.get(1).value);
Assert.assertEquals("d", project.rows.get(3).cells.get(1).value);
}
}