The issue is that in convertIntoTable, the varNames are taken from the QuerySolution. But suppose you have selected from a variable that has no bindings for the query. Then it will not be included in the results that are provided because it is in no solution. Also, the ordering of variables is not guaranteed in the QuerySolution instances. Instead use the varnames parsed from the XML head element.
List<String> varnames = results.getResultVars();
private static StringMatrix convertIntoTable(
PrefixMapping prefixMap, ResultSet results) {
StringMatrix table = new StringMatrix();
int rowCount = 0;
--> List resultVarNames = results.getResultVars()
while (results.hasNext()) {
rowCount++;
QuerySolution soln = results.nextSolution();
The issue is that in convertIntoTable, the varNames are taken from the QuerySolution. But suppose you have selected from a variable that has no bindings for the query. Then it will not be included in the results that are provided because it is in no solution. Also, the ordering of variables is not guaranteed in the QuerySolution instances. Instead use the varnames parsed from the XML head element.
private static StringMatrix convertIntoTable( PrefixMapping prefixMap, ResultSet results) { StringMatrix table = new StringMatrix(); int rowCount = 0; --> List resultVarNames = results.getResultVars()
while (results.hasNext()) {
rowCount++;
QuerySolution soln = results.nextSolution();
not this: Iterator varNames = soln.varNames();
instead:
Iterator varNames = resultVarNames.iterator();