public static Table transform(Table table, NodeTransform transform) { // Non-streaming rewrite List<Var> vars = transformVars(transform, table.getVars()) ; Iterator<Binding> iter = table.rows() ; List<Binding> newRows = new ArrayList<>() ; for ( ; iter.hasNext() ; ) { Binding b = iter.next() ; Binding b2 = transform(b, transform) ; newRows.add(b2) ; } return new TableData(vars, newRows) ; }
public static Table transform(Table table, NodeTransform transform) { List<Var> oldVars = table.getVars(); List<Var> newVars = new ArrayList<Var>(oldVars.size()); for(Var o : oldVars) { Var n = (Var)transform.apply(o); newVars.add(n); } //List<Binding> newBindings = new ArrayList<Binding>(table.size()); Table result = new TableN(newVars); Iterator<Binding> it = table.rows(); while(it.hasNext()) { Binding o = it.next(); Binding n = BindingUtils.transformKeys(o, transform); result.addBinding(n); } return result; }
private static void dump(Table table) { System.out.println("Table: "+Lib.className(table)) ; QueryIterator qIter = table.iterator(null) ; ResultSet rs = new ResultSetStream(table.getVarNames(), null, table.iterator(null)) ; ResultSetFormatter.out(rs) ; } }
private Table joinWorker(Table tableLeft, Table tableRight, boolean leftJoin, ExprList conditions) { QueryIterator left = tableLeft.iterator(execCxt) ; JoinType joinType = (leftJoin? JoinType.LEFT : JoinType.INNER ) ; QueryIterator qIter = TableJoin.joinWorker(left, tableRight, joinType, conditions, execCxt) ; tableLeft.close() ; tableRight.close() ; // qIter and left should be properly closed by use or called code. return new TableN(qIter) ; }
@Override public Binding apply(Table input) { Binding result = Iterators.getNext(input.rows(), null); return result; }
@Override public void visit(OpTable opTable) { // Only the variables with values in the tables // (When building, undefs didn't get into bindings so no variable // mentioned) Table t = opTable.getTable() ; // Treat as unknown position unknownAcc.addAll(t.getVars()) ; }
private static Table buildTable(Map<Var, Set<NodeValue>> possibleValues) { if (possibleValues.size() == 0) return TableFactory.createEmpty(); Table table = TableFactory.create(); // Although each filter condition must apply for a row to be accepted // they are actually independent since only one condition needs to fail // for the filter to reject the row. Thus for each unique variable/value // combination a single row must be produced for (Var v : possibleValues.keySet()) { for (NodeValue value : possibleValues.get(v)) { BindingMap b = BindingFactory.create(); b.add(v, value.asNode()); table.addBinding(b); } } return table; } }
@Override public Op transform(OpTable opTable) { if ( opTable.isJoinIdentity() ) return opTable; Table table = opTable.getTable(); if ( table.isEmpty() ) return opTable; if ( TableUnit.isTableUnit(table) ) return opTable; if ( table.getVars().size() == 0 ) return opTable; Table table2 = NodeTransformLib.transform(table, transform); return OpTable.create(table2); }
@Override public boolean equals(Object other) { if ( this == other ) return true ; if ( !(other instanceof Table) ) return false ; 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 { for (; qIter1.hasNext();) { Binding bind1 = qIter1.nextBinding() ; Binding bind2 = qIter2.nextBinding() ; if ( !BindingBase.equals(bind1, bind2) ) return false ; } return true ; } finally { qIter1.close() ; qIter2.close() ; } }
@Override protected Binding getNextSlot(Binding bindingLeft) { boolean accept = true ; for ( Iterator<Binding> iter = tableRight.iterator(null) ; iter.hasNext() ; ) { Binding bindingRight = iter.next() ; if ( Algebra.compatible(bindingLeft, bindingRight) ) { accept = false ; break ; } } if ( accept ) return bindingLeft ; return null ; } }
@Override public void visit(OpTable opTable) { // This will go in a group so simply forget it. if ( opTable.isJoinIdentity() ) return ; // Put in a VALUES // This may be related to the grpup of the overall query. ElementData el = new ElementData() ; el.getVars().addAll(opTable.getTable().getVars()) ; QueryIterator qIter = opTable.getTable().iterator(null) ; while (qIter.hasNext()) el.getRows().add(qIter.next()) ; qIter.close() ; currentGroup().addElement(el) ; }
table.addBinding(b) ; lastBinding = b ; count++ ; if ( table.size() == 1 )
private Table diffWorker(Table tableLeft, Table tableRight) { QueryIterator left = tableLeft.iterator(execCxt) ; TableN r = new TableN() ; for ( ; left.hasNext() ; ) { Binding b = left.nextBinding() ; if ( tableRight.contains(b) ) r.addBinding(b) ; } tableLeft.close() ; tableRight.close() ; return r ; }
private static ResultSet results(String... rows) { String str = "(table "+String.join("", rows)+")" ; return SSE.parseTable(str).toResultSet() ; }
private boolean isTableEmpty(Op op) { if (op instanceof OpTable) { return ((OpTable) op).getTable().isEmpty(); } else { return false; } }
@Override public T apply(Table table) { Acc<T> acc = agg.createAccumulator(); table.rows().forEachRemaining(acc::accumulate); T result = acc.getValue(); return result; }
@Override public void visit(OpTable opTable) { defines.addAll(opTable.getTable().getVars()); }
public static void addToTables(Tables tables, Quad quad) { Node g = quad.getGraph(); Table defaultGraphTable = tables.getDefaultGraphTable(); Table namedGraphTable = tables.getNamedGraphTable(); if(Quad.defaultGraphNodeGenerated.equals(g)) { Triple triple = quad.asTriple(); Binding binding = createBinding(triple); defaultGraphTable.addBinding(binding); } else { Binding binding = createBinding(quad); namedGraphTable.addBinding(binding); } }
@Override public void visit(OpTable opTable) { if ( TableUnit.isTableUnit(opTable.getTable()) ) { start(opTable, NoNL) ; out.print("unit") ; finish(opTable) ; return ; } if ( TableEmpty.isTableEmpty(opTable.getTable()) ) { start(opTable, NoNL) ; out.print("empty") ; finish(opTable) ; return ; } start(opTable, NoNL) ; WriterNode.outputVars(out, opTable.getTable().getVars(), sContext) ; if ( ! opTable.getTable().isEmpty() ) { out.println(); WriterTable.outputPlain(out, opTable.getTable(), sContext) ; } finish(opTable) ; }