In column addition and text transform operations, for expressions that evaluate to cells or wrapped cells, use the whole cells as the result cells. This effectively copies their recon objects as well.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@568 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-04-29 19:44:39 +00:00
parent c56a578166
commit cf01dcd965
2 changed files with 61 additions and 34 deletions

View File

@ -15,6 +15,7 @@ import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.Evaluable;
import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.expr.MetaParser; import com.metaweb.gridworks.expr.MetaParser;
import com.metaweb.gridworks.expr.WrappedCell;
import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.history.Change;
import com.metaweb.gridworks.history.HistoryEntry; import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.AbstractOperation;
@ -136,21 +137,33 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
public boolean visit(Project project, int rowIndex, Row row, boolean includeContextual, boolean includeDependent) { public boolean visit(Project project, int rowIndex, Row row, boolean includeContextual, boolean includeDependent) {
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
Cell newCell = null;
ExpressionUtils.bind(bindings, row, rowIndex, _baseColumnName, cell); ExpressionUtils.bind(bindings, row, rowIndex, _baseColumnName, cell);
Serializable v = ExpressionUtils.wrapStorable(eval.evaluate(bindings)); Object o = eval.evaluate(bindings);
if (ExpressionUtils.isError(v)) { if (o != null) {
if (_onError == OnError.SetToBlank) { if (o instanceof Cell) {
return false; newCell = (Cell) o;
} else if (_onError == OnError.KeepOriginal) { } else if (o instanceof WrappedCell) {
v = cell != null ? cell.value : null; newCell = ((WrappedCell) o).cell;
} else {
Serializable v = ExpressionUtils.wrapStorable(o);
if (ExpressionUtils.isError(v)) {
if (_onError == OnError.SetToBlank) {
return false;
} else if (_onError == OnError.KeepOriginal) {
v = cell != null ? cell.value : null;
}
}
if (v != null) {
newCell = new Cell(v, null);
}
} }
} }
if (v != null) { if (newCell != null) {
Cell newCell = new Cell(v, null);
cellsAtRows.add(new CellAtRow(rowIndex, newCell)); cellsAtRows.add(new CellAtRow(rowIndex, newCell));
} }

View File

@ -12,6 +12,7 @@ import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.Evaluable;
import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.expr.MetaParser; import com.metaweb.gridworks.expr.MetaParser;
import com.metaweb.gridworks.expr.WrappedCell;
import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Column;
@ -120,39 +121,52 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
public boolean visit(Project project, int rowIndex, Row row, boolean includeContextual, boolean includeDependent) { public boolean visit(Project project, int rowIndex, Row row, boolean includeContextual, boolean includeDependent) {
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
Cell newCell = null;
Object oldValue = cell != null ? cell.value : null; Object oldValue = cell != null ? cell.value : null;
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
Serializable newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings)); Object o = eval.evaluate(bindings);
if (ExpressionUtils.isError(newValue)) { if (o != null) {
if (_onError == OnError.KeepOriginal) { if (o instanceof Cell) {
return false; newCell = (Cell) o;
} else if (_onError == OnError.SetToBlank) { } else if (o instanceof WrappedCell) {
newValue = null; newCell = ((WrappedCell) o).cell;
} } else {
} Serializable newValue = ExpressionUtils.wrapStorable(o);
if (ExpressionUtils.isError(newValue)) {
if (!ExpressionUtils.sameValue(oldValue, newValue)) { if (_onError == OnError.KeepOriginal) {
Cell newCell = new Cell(newValue, (cell != null) ? cell.recon : null); return false;
} else if (_onError == OnError.SetToBlank) {
if (_repeat) { newValue = null;
for (int i = 0; i < _repeatCount; i++) { }
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, newCell); }
if (!ExpressionUtils.sameValue(oldValue, newValue)) {
newCell = new Cell(newValue, (cell != null) ? cell.recon : null);
newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings)); if (_repeat) {
if (ExpressionUtils.isError(newValue)) { for (int i = 0; i < _repeatCount; i++) {
break; ExpressionUtils.bind(bindings, row, rowIndex, _columnName, newCell);
} else if (ExpressionUtils.sameValue(newCell.value, newValue)) {
break; newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
if (ExpressionUtils.isError(newValue)) {
break;
} else if (ExpressionUtils.sameValue(newCell.value, newValue)) {
break;
}
newCell = new Cell(newValue, newCell.recon);
}
} }
newCell = new Cell(newValue, newCell.recon);
} }
} }
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell); if (newCell != null) {
cellChanges.add(cellChange); CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
cellChanges.add(cellChange);
}
} }
return false; return false;