Add debugging info - mostly toString() methods for types missing them
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2343 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
b2781bda3f
commit
ab950689dd
@ -39,6 +39,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.refine.ProjectMetadata;
|
import com.google.refine.ProjectMetadata;
|
||||||
import com.google.refine.expr.ExpressionUtils;
|
import com.google.refine.expr.ExpressionUtils;
|
||||||
@ -51,6 +53,7 @@ import com.google.refine.model.Row;
|
|||||||
import com.google.refine.util.JSONUtilities;
|
import com.google.refine.util.JSONUtilities;
|
||||||
|
|
||||||
abstract public class TabularImportingParserBase extends ImportingParserBase {
|
abstract public class TabularImportingParserBase extends ImportingParserBase {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger("ImportingParserBase");
|
||||||
static public interface TableDataReader {
|
static public interface TableDataReader {
|
||||||
public List<Object> getNextRowOfCells() throws IOException;
|
public List<Object> getNextRowOfCells() throws IOException;
|
||||||
}
|
}
|
||||||
@ -114,6 +117,7 @@ abstract public class TabularImportingParserBase extends ImportingParserBase {
|
|||||||
0, new Column(project.columnModel.allocateNewCellIndex(), fileNameColumnName), false);
|
0, new Column(project.columnModel.allocateNewCellIndex(), fileNameColumnName), false);
|
||||||
} catch (ModelException e) {
|
} catch (ModelException e) {
|
||||||
// Ignore: We already checked for duplicate name.
|
// Ignore: We already checked for duplicate name.
|
||||||
|
logger.info("ModelException",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ public class ImportColumnGroup extends ImportVertical {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("name=%s, columns={%s}, subgroups={{%s}}",
|
return String.format("name=%s, nextRowIndex=%d, columns={%s}, subgroups={{%s}}",
|
||||||
name,StringUtils.join(columns.keySet(), ','),
|
name,nextRowIndex,StringUtils.join(columns.keySet(), ','),
|
||||||
StringUtils.join(subgroups.keySet(),','));
|
StringUtils.join(subgroups.keySet(),','));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,4 +5,9 @@ abstract class ImportVertical {
|
|||||||
public int nonBlankCount;
|
public int nonBlankCount;
|
||||||
|
|
||||||
abstract void tabulate();
|
abstract void tabulate();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name + ":" + nonBlankCount;
|
||||||
|
}
|
||||||
}
|
}
|
@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
package com.google.refine.importers.tree;
|
package com.google.refine.importers.tree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -276,7 +277,7 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
ImportColumnGroup rootColumnGroup,
|
ImportColumnGroup rootColumnGroup,
|
||||||
int limit
|
int limit
|
||||||
) throws TreeReaderException {
|
) throws TreeReaderException {
|
||||||
logger.trace("findRecord(Project, TreeReader, String[], int, ImportColumnGroup");
|
logger.trace("findRecord(Project, TreeReader, String[], int, ImportColumnGroup - path:"+Arrays.toString(recordPath));
|
||||||
|
|
||||||
if(parser.current() == Token.Ignorable){//XMLStreamConstants.START_DOCUMENT){
|
if(parser.current() == Token.Ignorable){//XMLStreamConstants.START_DOCUMENT){
|
||||||
logger.warn("Cannot use findRecord method for START_DOCUMENT event");
|
logger.warn("Cannot use findRecord method for START_DOCUMENT event");
|
||||||
@ -342,12 +343,12 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
logger.trace("processRecord(Project,TreeReader,ImportColumnGroup)");
|
logger.trace("processRecord(Project,TreeReader,ImportColumnGroup)");
|
||||||
ImportRecord record = new ImportRecord();
|
ImportRecord record = new ImportRecord();
|
||||||
|
|
||||||
processSubRecord(project, parser, rootColumnGroup, record);
|
processSubRecord(project, parser, rootColumnGroup, record, 0);
|
||||||
addImportRecordToProject(record, project);
|
addImportRecordToProject(record, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* processRecord parses Tree data for a single element and it's sub-elements,
|
* processFieldAsRecord parses Tree data for a single element and it's sub-elements,
|
||||||
* adding the parsed data as a row to the project
|
* adding the parsed data as a row to the project
|
||||||
* @param project
|
* @param project
|
||||||
* @param parser
|
* @param parser
|
||||||
@ -408,9 +409,10 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
Project project,
|
Project project,
|
||||||
TreeReader parser,
|
TreeReader parser,
|
||||||
ImportColumnGroup columnGroup,
|
ImportColumnGroup columnGroup,
|
||||||
ImportRecord record
|
ImportRecord record,
|
||||||
|
int level
|
||||||
) throws TreeReaderException {
|
) throws TreeReaderException {
|
||||||
logger.trace("processSubRecord(Project,TreeReader,ImportColumnGroup,ImportRecord)");
|
logger.trace("processSubRecord(Project,TreeReader,ImportColumnGroup,ImportRecord) lvl:"+level+" "+columnGroup);
|
||||||
|
|
||||||
if(parser.current() == Token.Ignorable) {
|
if(parser.current() == Token.Ignorable) {
|
||||||
return;
|
return;
|
||||||
@ -444,7 +446,8 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
project,
|
project,
|
||||||
parser,
|
parser,
|
||||||
thisColumnGroup,
|
thisColumnGroup,
|
||||||
record
|
record,
|
||||||
|
level+1
|
||||||
);
|
);
|
||||||
} else if (//eventType == XMLStreamConstants.CDATA ||
|
} else if (//eventType == XMLStreamConstants.CDATA ||
|
||||||
eventType == Token.Value) { //XMLStreamConstants.CHARACTERS) {
|
eventType == Token.Value) { //XMLStreamConstants.CHARACTERS) {
|
||||||
@ -464,6 +467,8 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
}
|
}
|
||||||
} else if (eventType == Token.EndEntity) {
|
} else if (eventType == Token.EndEntity) {
|
||||||
break;
|
break;
|
||||||
|
} else if (eventType == Token.Ignorable) {
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
logger.info("unknown event type " + eventType);
|
logger.info("unknown event type " + eventType);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
package com.google.refine.model;
|
package com.google.refine.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -41,11 +42,15 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.refine.Jsonizable;
|
import com.google.refine.Jsonizable;
|
||||||
import com.google.refine.expr.ExpressionUtils;
|
import com.google.refine.expr.ExpressionUtils;
|
||||||
|
|
||||||
public class RecordModel implements Jsonizable {
|
public class RecordModel implements Jsonizable {
|
||||||
|
final static Logger logger = LoggerFactory.getLogger("RecordModel");
|
||||||
|
|
||||||
final static public class CellDependency {
|
final static public class CellDependency {
|
||||||
final public int rowIndex;
|
final public int rowIndex;
|
||||||
final public int cellIndex;
|
final public int cellIndex;
|
||||||
@ -57,7 +62,7 @@ public class RecordModel implements Jsonizable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return rowIndex+":"+cellIndex;
|
return rowIndex+","+cellIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +70,11 @@ public class RecordModel implements Jsonizable {
|
|||||||
public int recordIndex;
|
public int recordIndex;
|
||||||
public CellDependency[] cellDependencies;
|
public CellDependency[] cellDependencies;
|
||||||
public List<Integer> contextRows;
|
public List<Integer> contextRows;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Idx: "+recordIndex+" CellDeps: "+Arrays.toString(cellDependencies)+" Rows:"+contextRows;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<RowDependency> _rowDependencies;
|
protected List<RowDependency> _rowDependencies;
|
||||||
@ -232,8 +242,22 @@ public class RecordModel implements Jsonizable {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dumpKeyedGroups(keyedGroups, columnModel); // for debug
|
||||||
|
|
||||||
return keyedGroups;
|
return keyedGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// debugging helper
|
||||||
|
private void dumpKeyedGroups(List<KeyedGroup> groups, ColumnModel columnModel) {
|
||||||
|
for (KeyedGroup g : groups) {
|
||||||
|
String keyColName = columnModel.getColumnByCellIndex(g.keyCellIndex).getName();
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for (int ci : g.cellIndices) {
|
||||||
|
sb.append(columnModel.getColumnByCellIndex(ci).getName()).append(',');
|
||||||
|
}
|
||||||
|
logger.trace("KeyedGroup " + keyColName + "::" + sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void addRootKeyedGroup(ColumnModel columnModel, List<KeyedGroup> keyedGroups) {
|
protected void addRootKeyedGroup(ColumnModel columnModel, List<KeyedGroup> keyedGroups) {
|
||||||
int count = columnModel.getMaxCellIndex() + 1;
|
int count = columnModel.getMaxCellIndex() + 1;
|
||||||
|
@ -47,8 +47,8 @@ public class XmlImportUtilitiesStub extends XmlImportUtilities {
|
|||||||
return super.detectRecordElement(parser, tag);
|
return super.detectRecordElement(parser, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessSubRecordWrapper(Project project, TreeReader parser, ImportColumnGroup columnGroup, ImportRecord record) throws Exception{
|
public void ProcessSubRecordWrapper(Project project, TreeReader parser, ImportColumnGroup columnGroup, ImportRecord record, int level) throws Exception{
|
||||||
super.processSubRecord(project, parser, columnGroup, record);
|
super.processSubRecord(project, parser, columnGroup, record, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findRecordWrapper(Project project, TreeReader parser, String[] recordPath, int pathIndex, ImportColumnGroup rootColumnGroup) throws Exception{
|
public void findRecordWrapper(Project project, TreeReader parser, String[] recordPath, int pathIndex, ImportColumnGroup rootColumnGroup) throws Exception{
|
||||||
|
@ -370,7 +370,7 @@ public class XmlImportUtilitiesTests extends RefineTest {
|
|||||||
ParserSkip();
|
ParserSkip();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SUT.ProcessSubRecordWrapper(project, parser, columnGroup, record);
|
SUT.ProcessSubRecordWrapper(project, parser, columnGroup, record,0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user