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.ExpressionUtils;
import com.metaweb.gridworks.expr.MetaParser;
import com.metaweb.gridworks.expr.WrappedCell;
import com.metaweb.gridworks.history.Change;
import com.metaweb.gridworks.history.HistoryEntry;
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) {
Cell cell = row.getCell(cellIndex);
Cell newCell = null;
ExpressionUtils.bind(bindings, row, rowIndex, _baseColumnName, cell);
Serializable v = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
if (ExpressionUtils.isError(v)) {
if (_onError == OnError.SetToBlank) {
return false;
} else if (_onError == OnError.KeepOriginal) {
v = cell != null ? cell.value : null;
Object o = eval.evaluate(bindings);
if (o != null) {
if (o instanceof Cell) {
newCell = (Cell) o;
} else if (o instanceof WrappedCell) {
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) {
Cell newCell = new Cell(v, null);
if (newCell != null) {
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.ExpressionUtils;
import com.metaweb.gridworks.expr.MetaParser;
import com.metaweb.gridworks.expr.WrappedCell;
import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Cell;
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) {
Cell cell = row.getCell(cellIndex);
Cell newCell = null;
Object oldValue = cell != null ? cell.value : null;
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
Serializable newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
if (ExpressionUtils.isError(newValue)) {
if (_onError == OnError.KeepOriginal) {
return false;
} else if (_onError == OnError.SetToBlank) {
newValue = null;
}
}
Object o = eval.evaluate(bindings);
if (o != null) {
if (o instanceof Cell) {
newCell = (Cell) o;
} else if (o instanceof WrappedCell) {
newCell = ((WrappedCell) o).cell;
} else {
Serializable newValue = ExpressionUtils.wrapStorable(o);
if (ExpressionUtils.isError(newValue)) {
if (_onError == OnError.KeepOriginal) {
return false;
} else if (_onError == OnError.SetToBlank) {
newValue = null;
}
}
if (!ExpressionUtils.sameValue(oldValue, newValue)) {
Cell newCell = new Cell(newValue, (cell != null) ? cell.recon : null);
if (!ExpressionUtils.sameValue(oldValue, newValue)) {
newCell = new Cell(newValue, (cell != null) ? cell.recon : null);
if (_repeat) {
for (int i = 0; i < _repeatCount; i++) {
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, newCell);
if (_repeat) {
for (int i = 0; i < _repeatCount; i++) {
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, newCell);
newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
if (ExpressionUtils.isError(newValue)) {
break;
} 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);
cellChanges.add(cellChange);
if (newCell != null) {
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
cellChanges.add(cellChange);
}
}
return false;