You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2012/06/30 02:01:44 UTC
svn commit: r1355605 - in
/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset:
CSVInputIterator.java TSVInputIterator.java
Author: rvesse
Date: Sat Jun 30 00:01:42 2012
New Revision: 1355605
URL: http://svn.apache.org/viewvc?rev=1355605&view=rev
Log:
Further clean up of error reporting for TSVInputIterator and adds similar error reporting to CSVInputIterator
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/CSVInputIterator.java
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVInputIterator.java
Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/CSVInputIterator.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/CSVInputIterator.java?rev=1355605&r1=1355604&r2=1355605&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/CSVInputIterator.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/CSVInputIterator.java Sat Jun 30 00:01:42 2012
@@ -47,6 +47,7 @@ public class CSVInputIterator extends Qu
private BindingMap binding;
private int expectedItems;
private List<Var> vars;
+ private long lineNum = 1;
/**
* Creates a new CSV Input Iterator
@@ -90,9 +91,10 @@ public class CSVInputIterator extends Qu
line = this.reader.readLine();
//Once EOF has been reached we'll see null for this call so we can return false because there are no further bindings
if (line == null) return false;
+ this.lineNum++;
}
catch (IOException e)
- { throw new QueryException("Error parsing TSV results - " + e.getMessage()); }
+ { throw new QueryException("Error parsing CSV results - " + e.getMessage()); }
if ( line.isEmpty() )
{
@@ -100,7 +102,7 @@ public class CSVInputIterator extends Qu
// Only valid when we expect zero/one values as otherwise we should get a sequence of tab characters
// which means a non-empty string which we handle normally
if (expectedItems > 1)
- throw new QueryException(String.format("Error Parsing CSV results - A result row had 0/1 values when %d were expected", expectedItems));
+ throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row had 0/1 values when %d were expected", this.lineNum, expectedItems));
binding = BindingFactory.create() ;
if ( expectedItems == 1 )
binding.add(vars.get(0), NodeConst.emptyString) ;
@@ -112,7 +114,7 @@ public class CSVInputIterator extends Qu
}
- private static BindingMap parseLine(List<Var> vars, String line)
+ private BindingMap parseLine(List<Var> vars, String line)
{
BindingMap binding = BindingFactory.create() ;
List<String> terms = new ArrayList<String>() ;
@@ -137,12 +139,12 @@ public class CSVInputIterator extends Qu
s.append(ch) ;
}
if ( ch != qCh )
- throw new QueryException("Error Parsing CSV results - Unterminated quoted string");
+ throw new QueryException(String.format("Error Parsing CSV results at Line %d - Unterminated quoted string", this.lineNum));
if ( idx < line.length() )
{
ch = line.charAt(idx) ;
if ( ch != ',' )
- throw new QueryException("Error Parsing CSV results - Expected comma after quote") ;
+ throw new QueryException(String.format("Error Parsing CSV results at Line %d - Expected comma after quote", this.lineNum)) ;
}
}
else
@@ -173,7 +175,7 @@ public class CSVInputIterator extends Qu
}
if ( terms.size() != vars.size() )
- throw new QueryException("Error Parsing CSV results - Number of items does not match number of variables: "+StrUtils.strjoin(",", terms)) ;
+ throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row '%s' has %d items when %d was expected", this.lineNum, line, terms.size(), vars.size())) ;
for ( int i = 0 ; i < vars.size() ; i++ )
binding.add(vars.get(i), Node.createLiteral(terms.get(i))) ;
return binding ;
Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVInputIterator.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVInputIterator.java?rev=1355605&r1=1355604&r2=1355605&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVInputIterator.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/TSVInputIterator.java Sat Jun 30 00:01:42 2012
@@ -99,7 +99,7 @@ public class TSVInputIterator extends Qu
// Empty input line - no bindings.
// Only valid when we expect zero/one values as otherwise we should get a sequence of tab characters
// which means a non-empty string which we handle normally
- if (expectedItems > 1) throw new QueryException(String.format("Error Parsing TSV results at Line " + this.lineNum + " - A result row had 0/1 values when %d were expected", expectedItems));
+ if (expectedItems > 1) throw new QueryException(String.format("Error Parsing TSV results at Line %d - The result row had 0/1 values when %d were expected", this.lineNum, expectedItems));
this.binding = BindingFactory.create() ;
return true ;
}
@@ -107,27 +107,27 @@ public class TSVInputIterator extends Qu
String[] tokens = TSVInput.pattern.split(line, -1);
if (tokens.length != expectedItems)
- throw new QueryException(String.format("Error Parsing TSV results at Line " + this.lineNum + " - A result row had %d values instead of the expected %d.", tokens.length, expectedItems));
+ throw new QueryException(String.format("Error Parsing TSV results at Line %d - The result row '%s' has %d values instead of the expected %d.", this.lineNum, line, tokens.length, expectedItems));
this.binding = BindingFactory.create();
- for ( int i = 0; i < tokens.length; i++ )
+ try
{
- String token = tokens[i];
-
- //If we see an empty string this denotes an unbound value
- if (token.equals("")) continue;
-
- try
- {
- //Bound value so parse it and add to the binding
- Node node = NodeFactory.parseNode(token, null);
- this.binding.add(this.vars.get(i), node);
- } catch (Exception e) {
- throw new QueryException(String.format("Error Parsing TSV results at Line " + this.lineNum + " - %s is not a valid encoding of a Node", token));
- }
- }
+ for ( int i = 0; i < tokens.length; i++ )
+ {
+ String token = tokens[i];
+
+ //If we see an empty string this denotes an unbound value
+ if (token.equals("")) continue;
+
+ //Bound value so parse it and add to the binding
+ Node node = NodeFactory.parseNode(token, null);
+ this.binding.add(this.vars.get(i), node);
+ }
+ } catch (Exception e) {
+ throw new QueryException(String.format("Error Parsing TSV results at Line %d - The result row '%s' contains an invalid encoding of a Node", this.lineNum, line));
+ }
return true;
}