Skip to content

Commit

Permalink
JENA-1468: Writing vars when table empty
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Jan 26, 2018
1 parent 94eb3fc commit 30eb931
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Expand Up @@ -106,6 +106,8 @@ public boolean equals(Object other) {
Table table = (Table)other ;
if ( table.size() != this.size() )
return false ;
if ( !table.getVars().equals(getVars()) )
return false ;
QueryIterator qIter1 = iterator(null) ;
QueryIterator qIter2 = table.iterator(null) ;
try {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List ;

import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.sparql.algebra.Table;
import org.apache.jena.sparql.core.Var ;
import org.apache.jena.sparql.engine.ExecutionContext ;
import org.apache.jena.sparql.engine.QueryIterator ;
Expand All @@ -31,6 +32,9 @@

public class TableEmpty extends TableBase
{
static public boolean isTableEmpty(Table table)
{ return (table instanceof TableEmpty) ; }

public TableEmpty()
{ }

Expand Down
Expand Up @@ -18,7 +18,7 @@

package org.apache.jena.sparql.algebra.table;

import java.util.ArrayList ;
import java.util.Collections;
import java.util.Iterator ;
import java.util.List ;

Expand All @@ -35,7 +35,7 @@ public class TableUnit extends TableBase
{
static public boolean isTableUnit(Table table)
{ return (table instanceof TableUnit) ; }

public TableUnit() {}

@Override
Expand All @@ -61,10 +61,9 @@ public void closeTable() { }
public boolean isEmpty() { return false ; }

@Override
public List<String> getVarNames() { return new ArrayList<>() ; }

public List<String> getVarNames() { return Collections.emptyList(); }
@Override
public List<Var> getVars() { return new ArrayList<>() ; }
public List<Var> getVars() { return Collections.emptyList(); }

@Override
public String toString() { return "TableUnit" ; }
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.apache.jena.sparql.algebra.OpPrefixesUsed ;
import org.apache.jena.sparql.algebra.OpVisitor ;
import org.apache.jena.sparql.algebra.op.* ;
import org.apache.jena.sparql.algebra.table.TableEmpty;
import org.apache.jena.sparql.algebra.table.TableUnit ;
import org.apache.jena.sparql.core.* ;
import org.apache.jena.sparql.expr.Expr ;
Expand Down Expand Up @@ -349,7 +350,7 @@ public void visit(OpTable opTable) {
return ;
}

if ( opTable.getTable().isEmpty() ) {
if ( TableEmpty.isTableEmpty(opTable.getTable()) ) {
start(opTable, NoNL) ;
out.print("empty") ;
finish(opTable) ;
Expand All @@ -358,8 +359,10 @@ public void visit(OpTable opTable) {

start(opTable, NoNL) ;
WriterNode.outputVars(out, opTable.getTable().getVars(), sContext) ;
out.println() ;
WriterTable.outputPlain(out, opTable.getTable(), sContext) ;
if ( ! opTable.getTable().isEmpty() ) {
out.println();
WriterTable.outputPlain(out, opTable.getTable(), sContext) ;
}
finish(opTable) ;
}

Expand Down

0 comments on commit 30eb931

Please sign in to comment.