Fixed issue 16: Column name collision when adding data from Freebase.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@804 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
4cf476630e
commit
fa2be33709
@ -77,6 +77,31 @@ public class ColumnModel implements Jsonizable {
|
||||
internalInitialize();
|
||||
}
|
||||
|
||||
synchronized public void addColumn(int index, Column column, boolean avoidNameCollision) throws ModelException {
|
||||
String baseName = column.getName();
|
||||
|
||||
if (_nameToColumn.containsKey(baseName)) {
|
||||
if (!avoidNameCollision) {
|
||||
throw new ModelException("Duplicated column name");
|
||||
}
|
||||
}
|
||||
|
||||
String name = baseName;
|
||||
int i = 1;
|
||||
while (true) {
|
||||
if (_nameToColumn.containsKey(name)) {
|
||||
i++;
|
||||
name = baseName + i;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
column.setName(name);
|
||||
columns.add(index, column);
|
||||
_nameToColumn.put(name, column); // so the next call can check
|
||||
}
|
||||
|
||||
public Column getColumnByName(String name) {
|
||||
return _nameToColumn.get(name);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.metaweb.gridworks.model;
|
||||
|
||||
public class ModelException extends Exception {
|
||||
private static final long serialVersionUID = -168448967638065467L;
|
||||
|
||||
public ModelException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ModelException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ModelException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ModelException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,7 @@ import org.json.JSONWriter;
|
||||
import com.metaweb.gridworks.history.Change;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.ModelException;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.ReconCandidate;
|
||||
@ -172,7 +173,14 @@ public class DataExtensionChange implements Change {
|
||||
column.setReconConfig(new DataExtensionReconConfig(_columnTypes.get(i)));
|
||||
column.setReconStats(ReconStats.create(project, cellIndex));
|
||||
|
||||
project.columnModel.columns.add(_columnInsertIndex + i, column);
|
||||
try {
|
||||
project.columnModel.addColumn(_columnInsertIndex + i, column, true);
|
||||
|
||||
// the column might have been renamed to avoid collision
|
||||
_columnNames.set(i, column.getName());
|
||||
} catch (ModelException e) {
|
||||
// won't get here since we set the avoid collision flag
|
||||
}
|
||||
}
|
||||
|
||||
project.columnModel.update();
|
||||
|
Loading…
Reference in New Issue
Block a user