protected void emitDataBlockValue(Node n, int line, int col) { currentColumn++ ; if ( currentColumn >= variables.size() ) // Exception will be thrown later when we have the complete row count. return ; Var v = variables.get(currentColumn) ; if ( n != null ) currentValueRow().add(v, n) ; }
/** Merge two bindings, assuming they are compatible. */ public static Binding merge(Binding bind1, Binding bind2) { // Create binding from LHS BindingMap b2 = BindingFactory.create(bind1); Iterator<Var> vIter = bind2.vars(); // Add any variables from the RHS for ( ; vIter.hasNext() ; ) { Var v = vIter.next(); if ( !b2.contains(v) ) b2.add(v, bind2.get(v)); else { // Checking! Node n1 = bind1.get(v); Node n2 = bind2.get(v); if ( !n1.equals(n2) ) Log.warn(BindingUtils.class, "merge: Mismatch : " + n1 + " != " + n2); } } return b2; }
static protected void addBinding(BindingMap binding, Var var, Node value) { Node n = binding.get(var); if ( n != null ) { // Same - silently skip. if ( n.equals(value) ) return; Log.warn(SPARQLResult.class, String.format("Multiple occurences of a binding for variable '%s' with different values - ignored", var.getName())); return; } binding.add(var, value); }
@Override public Binding accept(Binding binding) { BindingMap b = BindingFactory.create(binding); for ( Var v : exprs.getVars() ) { // if "binding", not "b" used, we get (Lisp) "let" // semantics, not the desired "let*" semantics Node n = exprs.get(v, b, getExecContext()); if ( n == null ) // Expression failed to evaluate - no assignment continue; // Check is already has a value; if so, must be sameValueAs if ( b.contains(v) ) { // Optimization may linearize to push a stream through an (extend). if ( false && mustBeNewVar ) throw new QueryExecException("Already set: " + v); Node n2 = b.get(v); if ( !n2.sameValueAs(n) ) //throw new QueryExecException("Already set: "+v) ; // Error in single assignment. return null ; continue ; } b.add(v, n) ; } return b ; }
@Override public Binding convert(Binding b) { if ( parentBinding == null || parentBinding.isEmpty() ) return b ; // This is the result. Could have BindingBase.setParent etc. BindingMap b2 = BindingFactory.create(parentBinding) ; // Copy the resultSet bindings to the combined result binding with checking. for ( Iterator<Var> iter = b.vars() ; iter.hasNext(); ) { Var v = iter.next(); Node n = b.get(v) ; if ( b2.contains(v) ) { Node n2 = b2.get(v) ; if ( n2.equals(n) ) Log.warn(this, "Binding already for "+v+" (same value)" ) ; else { Log.error(this, "Binding already for "+v+" (different values)" ) ; throw new ARQInternalErrorException("Incompatible bindings for "+v) ; } } b2.add(v, n) ; } return b2 ; } }
public static void addAll(BindingMap dest, Binding src) { Iterator<Var> iter = src.vars(); for ( ; iter.hasNext() ; ) { Var v = iter.next(); Node n = src.get(v); dest.add(v, n); } }
/** Merge two bindings, the outer and inner, projecting the inner with the give variables. * This is what happens in substitutIon execution, with a inner select-project. */ private static Binding ensure(List<Var> vars, Binding outer, Binding inner) { // A specialised BindingUtils.merge that does project as well. // Reduce small object churn. BindingMap b2 = BindingFactory.create(outer) ; Iterator<Var> vIter = (vars != null) ? vars.iterator() : inner.vars() ; // Add any variables from the RHS for ( ; vIter.hasNext() ; ) { Var v = vIter.next() ; Node n2 = inner.get(v) ; if ( n2 == null ) continue ; if ( ! b2.contains(v) ) b2.add(v, inner.get(v)) ; else { // Checking! Node n1 = outer.get(v) ; if ( ! n1.equals(n2) ) Log.warn(BindingUtils.class, "merge: Mismatch : "+n1+" != "+n2); } } return b2 ; } }
static protected void addBinding(BindingMap binding, Var var, Node value) { Node n = binding.get(var); if ( n != null ) { // Same - silently skip. if ( n.equals(value) ) return; Log.warn(ResultsStAX.class, String.format("Multiple occurences of a binding for variable '%s' with different values - ignored", var.getName())); return; } binding.add(var, value); }
@Override public Binding apply(List<String> row) { if ( row.size() != vars.size() ) FmtLog.warn(log, "Row %d: Length=%d: expected=%d", count, row.size(), vars.size()) ; BindingMap binding = BindingFactory.create() ; // Check. for (int i = 0 ; i < vars.size() ; i++ ) { Var v = vars.get(i) ; String field = (i<row.size()) ? row.get(i) : "" ; Node n = NodeFactory.createLiteral(field) ; binding.add(v, n); } count++ ; return binding ; }} ; Iterator<Binding> bindings = Iter.map(parser.iterator(), transform) ;
/** * Create a new Binding as a copy of an existing one. Additionally, it guarantees to * touch each element of the binding */ public static Binding copy(Binding b) { Iterator<Var> vIter = b.vars(); BindingMap b2 = create(); while (vIter.hasNext()) { Var v = vIter.next(); b2.add(v, b.get(v)); } return b2; } }
private static QueryIterator findIndexMember(Graph graph, Binding binding, Node listNode, Var varIndex, Var varMember, ExecutionContext execCxt) { // Iterate over list List<Node> members = GraphList.members(new GNode(graph, listNode)) ; List<Binding> bindings = new ArrayList<>() ; for ( int i = 0 ; i < members.size() ; i++ ) { Node idx = NodeFactoryExtra.intToNode(i) ; Node member = members.get(i) ; BindingMap b = BindingFactory.create(binding) ; b.add(varIndex, idx) ; b.add(varMember, member) ; bindings.add(b) ; } return new QueryIterPlainWrapper(bindings.iterator(), execCxt) ; } }
public RdfViewTemplate copySubstitute(Map<Node, Node> map) { BindingMap tmp = new BindingHashMap(); for(Entry<Node, Node> entry : map.entrySet()) { tmp.add((Var)entry.getKey(), entry.getValue()); } RdfViewTemplate result = new RdfViewTemplate( QuadUtils.copySubstitute(quadPattern, map), QuadUtils.copySubstitute(binding, map)); return result; }
@Override protected Binding moveToNextBinding() { Binding b = super.moveToNextBinding(); if (this.varMapping == null) return b; // Apply remapping BindingMap binding = BindingFactory.create(); Iterator<Var> vs = b.vars(); while (vs.hasNext()) { Var v = vs.next(); Node value = b.get(v); // Only remap non-null variables for which there is a mapping if (value == null) continue; if (this.varMapping.containsKey(v)) { binding.add(this.varMapping.get(v), value); } } return binding; }
private boolean parseNextBinding() { String line; try { 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 CSV results - " + e.getMessage()); } if ( line.isEmpty() ) { // 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 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) ; return true ; } binding = parseLine(vars, line) ; return true ; }
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), NodeFactory.createLiteral(terms.get(i))) ; return binding ;