Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-2242

Include VALUES clause in string when stringifying a WhereBuilder

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Jena 4.3.2
    • Jena 4.4.0
    • QueryBuilder
    • None

    Description

      Currently when stringifying a WhereBuilder (e.g. for debugging), any VALUES clause is not included in the output of .toString:

      import java.util.ArrayList;
      import java.util.HashMap;
      
      import org.apache.jena.graph.Node;
      import org.apache.jena.grpah.Triple;
      import org.apache.jena.arq.querybuilder.Converters;
      
      import org.apache.jena.arq.querybuilder.WhereBuilder;
       
      // Node creation
      Node svarNode = Converters.checkVar(NodeFactory.createVariable("s"));
      Node pvarNode = Converters.checkVar(NodeFactory.createVariable("p"));
      Node ovarNode = Converters.checkVar(NodeFactory.createVariable("o"));
      
      // Values map creation
      ArrayList<Node> subjColl = new ArrayList<>();
      subjColl.add(NodeFactory.createURI("http://example.org#subject"));
      
      HashMap<Node, ArrayList<Node>> valMap = new HashMap<>();
      valMap.put(svarNode, subjColl);
      
      // WhereBuilder creation
      WhereBuilder wb = new WhereBuilder();
      wb.addWhere(svarNode, pvarNode, ovarNode);
      wb.addWhereValueVars(valMap);
      
      wb.toString();
      
      // WHERE { ?s ?p ?o }
      

      It is only when you add the WhereBuilder to another builder, e.g. a ConstructBuilder, when you are able to visualize the VALUES clause:

      import org.apache.jena.arq.querybuilder.ConstructBuilder;
      
      ConstructBuilder cb = new ConstructBuilder();
      cb.addConstruct(new Triple(svarNode, pvarNode, ovarNode));
      cb.addWhere(wb);
      
      cb.toString();
      
      // CONSTRUCT 
      //   { 
      //     ?s ?p ?o .
      //   }
      // WHERE
      //   { ?s  ?p  ?o
      //     VALUES ( ?s ) { ( <http://example.org#subject> ) }
      //   }
      

      Ideally we would like to visualize the VALUES clause by including it in the result string while stringifying the WhereBuilder, not just with the ConstructBuilder. This would improve the development experience by allowing us to focus on debugging the WHERE clause, without having to consider the containing query or update.

      Attachments

        Issue Links

          Activity

            People

              claude Claude Warren
              kqian Kelvin Qian
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: