Search in sources :

Example 11 with WrappedRow

use of com.google.refine.expr.WrappedRow in project OpenRefine by OpenRefine.

the class CrossTests method crossFunctionOneArgumentTest1.

@Test
public void crossFunctionOneArgumentTest1() throws Exception {
    Row row = (((WrappedRow) ((HasFieldsListImpl) invoke("cross", 0, "")).get(0)).row);
    String address = row.getCell(1).value.toString();
    Assert.assertEquals(address, "mary");
}
Also used : HasFieldsListImpl(com.google.refine.expr.HasFieldsListImpl) WrappedRow(com.google.refine.expr.WrappedRow) Row(com.google.refine.model.Row) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with WrappedRow

use of com.google.refine.expr.WrappedRow in project OpenRefine by OpenRefine.

the class LookupCacheManager method computeLookup.

protected void computeLookup(ProjectLookup lookup) throws LookupException {
    if (lookup.targetProjectID < 0) {
        return;
    }
    Project targetProject = ProjectManager.singleton.getProject(lookup.targetProjectID);
    ProjectMetadata targetProjectMetadata = ProjectManager.singleton.getProjectMetadata(lookup.targetProjectID);
    if (targetProject == null) {
        return;
    }
    // if this is a lookup on the index column
    if (lookup.targetColumnName.equals(Cross.INDEX_COLUMN_NAME)) {
        for (int r = 0; r < targetProject.rows.size(); r++) {
            lookup.valueToRowIndices.put(String.valueOf(r), Collections.singletonList(r));
        }
        // return directly
        return;
    }
    Column targetColumn = targetProject.columnModel.getColumnByName(lookup.targetColumnName);
    if (targetColumn == null) {
        throw new LookupException("Unable to find column " + lookup.targetColumnName + " in project " + targetProjectMetadata.getName());
    }
    // We can't use for-each here, because we'll need the row index when creating WrappedRow
    int count = targetProject.rows.size();
    for (int r = 0; r < count; r++) {
        Row targetRow = targetProject.rows.get(r);
        Object value = targetRow.getCellValue(targetColumn.getCellIndex());
        if (ExpressionUtils.isNonBlankData(value)) {
            String valueStr = value.toString();
            lookup.valueToRowIndices.putIfAbsent(valueStr, new ArrayList<>());
            lookup.valueToRowIndices.get(valueStr).add(r);
        }
    }
}
Also used : Project(com.google.refine.model.Project) LookupException(com.google.refine.util.LookupException) Column(com.google.refine.model.Column) WrappedRow(com.google.refine.expr.WrappedRow) Row(com.google.refine.model.Row)

Example 13 with WrappedRow

use of com.google.refine.expr.WrappedRow in project OpenRefine by OpenRefine.

the class CrossTests method crossFunctionDoubleArgumentTest1.

@Test
public void crossFunctionDoubleArgumentTest1() throws Exception {
    Row row = (((WrappedRow) ((HasFieldsListImpl) invoke("cross", 3.14f, "My Address Book", "friend")).get(0)).row);
    String address = row.getCell(1).value.toString();
    Assert.assertEquals(address, "double");
}
Also used : HasFieldsListImpl(com.google.refine.expr.HasFieldsListImpl) WrappedRow(com.google.refine.expr.WrappedRow) Row(com.google.refine.model.Row) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 14 with WrappedRow

use of com.google.refine.expr.WrappedRow in project OpenRefine by OpenRefine.

the class CrossTests method crossFunctionSameColumnTest.

@Test
public void crossFunctionSameColumnTest() throws Exception {
    Project project = (Project) bindings.get("project");
    Cell c = project.rows.get(0).cells.get(1);
    WrappedCell lookup = new WrappedCell(project, "recipient", c);
    Row row = (((WrappedRow) ((HasFieldsListImpl) invoke("cross", lookup, "My Address Book", "friend")).get(0)).row);
    String address = row.getCell(1).value.toString();
    Assert.assertEquals(address, "50 Broadway Ave.");
}
Also used : Project(com.google.refine.model.Project) WrappedCell(com.google.refine.expr.WrappedCell) HasFieldsListImpl(com.google.refine.expr.HasFieldsListImpl) WrappedRow(com.google.refine.expr.WrappedRow) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) WrappedCell(com.google.refine.expr.WrappedCell) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 15 with WrappedRow

use of com.google.refine.expr.WrappedRow in project OpenRefine by OpenRefine.

the class CrossTests method crossFunctionDoubleArgumentTest2.

@Test
public void crossFunctionDoubleArgumentTest2() throws Exception {
    Row row = (((WrappedRow) ((HasFieldsListImpl) invoke("cross", "3.14", "My Address Book", "friend")).get(0)).row);
    String address = row.getCell(1).value.toString();
    Assert.assertEquals(address, "double");
}
Also used : HasFieldsListImpl(com.google.refine.expr.HasFieldsListImpl) WrappedRow(com.google.refine.expr.WrappedRow) Row(com.google.refine.model.Row) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

WrappedRow (com.google.refine.expr.WrappedRow)26 Row (com.google.refine.model.Row)26 RefineTest (com.google.refine.RefineTest)25 HasFieldsListImpl (com.google.refine.expr.HasFieldsListImpl)25 BeforeTest (org.testng.annotations.BeforeTest)25 Test (org.testng.annotations.Test)25 Project (com.google.refine.model.Project)6 WrappedCell (com.google.refine.expr.WrappedCell)5 Cell (com.google.refine.model.Cell)5 Column (com.google.refine.model.Column)1 LookupException (com.google.refine.util.LookupException)1