diff --git a/main/src/com/google/refine/InterProjectModel.java b/main/src/com/google/refine/InterProjectModel.java index 529ee19c9..295042612 100644 --- a/main/src/com/google/refine/InterProjectModel.java +++ b/main/src/com/google/refine/InterProjectModel.java @@ -88,6 +88,15 @@ public class InterProjectModel { protected Map _joins = new HashMap(); + /** + * Compute the ProjectJoin based on combination key, return the cached one from the HashMap if already computed + * + * @param fromProject + * @param fromColumn + * @param toProject + * @param toColumn + * @return + */ public ProjectJoin getJoin(String fromProject, String fromColumn, String toProject, String toColumn) { String key = fromProject + ";" + fromColumn + ";" + toProject + ";" + toColumn; if (!_joins.containsKey(key)) { diff --git a/main/src/com/google/refine/expr/functions/Cross.java b/main/src/com/google/refine/expr/functions/Cross.java index 0dfb6b783..e04ed5e0a 100644 --- a/main/src/com/google/refine/expr/functions/Cross.java +++ b/main/src/com/google/refine/expr/functions/Cross.java @@ -47,39 +47,39 @@ import com.google.refine.grel.Function; import com.google.refine.model.Project; public class Cross implements Function { - + @Override public Object call(Properties bindings, Object[] args) { if (args.length == 3) { // from project is implied - Object wrappedCell = args[0]; // from cell + Object v = args[0]; // from cell Object toProjectName = args[1]; Object toColumnName = args[2]; - if (wrappedCell != null && wrappedCell instanceof WrappedCell && + if (v != null && v instanceof String && toProjectName != null && toProjectName instanceof String && toColumnName != null && toColumnName instanceof String) { ProjectJoin join = ProjectManager.singleton.getInterProjectModel().getJoin( ProjectManager.singleton.getProjectMetadata(((Project) bindings.get("project")).id).getName(), - ((WrappedCell) wrappedCell).columnName, + (String) bindings.get("columnName"), (String) toProjectName, (String) toColumnName ); - return join.getRows(((WrappedCell) wrappedCell).cell.value); + return join.getRows((String)v); } } - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a cell, a project name to join with, and a column name in that project"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string, a project name to join with, and a column name in that project"); } - + @Override public void write(JSONWriter writer, Properties options) throws JSONException { writer.object(); - writer.key("description"); writer.value("TODO"); + writer.key("description"); writer.value("join with anothe project by column"); writer.key("params"); writer.value("cell c, string projectName, string columnName"); writer.key("returns"); writer.value("array"); writer.endObject(); diff --git a/main/src/com/google/refine/model/changes/MassReconChange.java b/main/src/com/google/refine/model/changes/MassReconChange.java index 8556a4705..5e8eb2a13 100644 --- a/main/src/com/google/refine/model/changes/MassReconChange.java +++ b/main/src/com/google/refine/model/changes/MassReconChange.java @@ -37,12 +37,14 @@ import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Properties; import org.json.JSONException; import org.json.JSONWriter; +import com.google.refine.ProjectManager; import com.google.refine.history.Change; import com.google.refine.model.Cell; import com.google.refine.model.Project; @@ -71,6 +73,7 @@ public class MassReconChange implements Change { protected void switchRecons(Project project, Map reconMap) { synchronized (project) { + HashSet flushedColumn = new HashSet(); for (Row row : project.rows) { for (int c = 0; c < row.cells.size(); c++) { Cell cell = row.cells.get(c); @@ -78,6 +81,14 @@ public class MassReconChange implements Change { Recon recon = cell.recon; if (reconMap.containsKey(recon.id)) { + // skip the flushing if already done + String columnName = project.columnModel.getColumnByCellIndex(c).getName(); + if (!flushedColumn.contains(columnName)) { + ProjectManager.singleton.getInterProjectModel().flushJoinsInvolvingProjectColumn(project.id, + columnName); + flushedColumn.add(columnName); + } + row.setCell(c, new Cell(cell.value, reconMap.get(recon.id))); } } diff --git a/main/src/com/google/refine/model/changes/MassRowColumnChange.java b/main/src/com/google/refine/model/changes/MassRowColumnChange.java index 979f7a548..871df7587 100644 --- a/main/src/com/google/refine/model/changes/MassRowColumnChange.java +++ b/main/src/com/google/refine/model/changes/MassRowColumnChange.java @@ -41,6 +41,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Properties; +import com.google.refine.ProjectManager; import com.google.refine.history.Change; import com.google.refine.model.Column; import com.google.refine.model.ColumnGroup; @@ -80,6 +81,8 @@ public class MassRowColumnChange implements Change { project.rows.clear(); project.rows.addAll(_newRows); + ProjectManager.singleton.getInterProjectModel().flushJoinsInvolvingProject(project.id); + project.update(); } } @@ -96,6 +99,8 @@ public class MassRowColumnChange implements Change { project.rows.clear(); project.rows.addAll(_oldRows); + ProjectManager.singleton.getInterProjectModel().flushJoinsInvolvingProject(project.id); + project.update(); } }