Package lupos.datastructures.queryresult

Examples of lupos.datastructures.queryresult.QueryResult


    ctp.add(tp);
    this.setTriplePatterns(ctp);
    final Collection<Variable> cv = new LinkedList<Variable>();
    cv.add(v);
    this.setCollationOrder(RDF3XOperatorGraphGenerator.getCollationOrder(tp, cv));
    final QueryResult qr = this.join(this.root.dataset);
    if (qr == null) {
      this.setTriplePatterns(ztp);
      return null;
    }
    final Iterator<Bindings> itb = qr.oneTimeIterator();
    if (!itb.hasNext()) {
      this.setTriplePatterns(ztp);
      return null;
    }
    final Literal min = itb.next().get(v);
View Full Code Here


  }

  @Override
  public QueryResult join(final Collection<Indices> indicesC){
    try{
      QueryResult queryResult = QueryResult.createInstance();
      queryResult.add(this.bindingsFactory.createInstance());
      // move over the collection of the provided triple patterns
      for (final TriplePattern tp : this.triplePatterns) {

        final QueryResult zQueryResult = queryResult;

        final Iterator<Bindings> itb = new ImmutableIterator<Bindings>() {
          Iterator<Bindings> oldBindings = zQueryResult.oneTimeIterator();
          Bindings currentBindings = null;
          Iterator<Triple> newTriples = null;
          Bindings next = null;

          @Override
          public boolean hasNext() {
            if (this.next != null) {
              return true;
            }
            this.next = this.computeNext();
            return (this.next != null);
          }

          @Override
          public Bindings next() {
            if (this.next != null) {
              final Bindings znext = this.next;
              this.next = null;
              return znext;
            }
            return this.computeNext();
          }

          public Bindings computeNext() {
            while ((this.newTriples == null || !this.newTriples.hasNext()) && this.oldBindings.hasNext()) {
              this.retrieveNewTriples();
            }
            if (this.newTriples == null || !this.newTriples.hasNext()) {
              return null;
            }
            final Triple triple = this.newTriples.next();
            final Bindings cB = this.currentBindings.clone();
            for (int i = 0; i < 3; i++) {
              if (tp.getPos(i).isVariable()) {
                final Literal l = cB.get((Variable) tp.getPos(i));
                if (l != null) {
                  if (!triple.getPos(i).equals(l)) {
                    return this.computeNext();
                  }
                } else {
                  cB.add((Variable) tp.getPos(i), triple.getPos(i));
                }
              }
            }
            cB.addTriple(triple);
            return cB;
          }

          private void retrieveNewTriples() {
            this.currentBindings = this.oldBindings.next();

            final StringBuffer key = new StringBuffer();
            int mapPattern = MAP_PATTERN.NONE.ordinal();

            // compute a key which is as restrictive as possible
            // to cut down the amount of triple pattern which
            // have
            // to be processed to produce the result
            if (MemoryIndexScan.this.computeKey4Maps(this.currentBindings, key, tp.getPos(0))) {
              mapPattern += MAP_PATTERN.SMAP.ordinal();
            }
            if (MemoryIndexScan.this.computeKey4Maps(this.currentBindings, key, tp.getPos(1))) {
              mapPattern += MAP_PATTERN.PMAP.ordinal();
            }
            if (MemoryIndexScan.this.computeKey4Maps(this.currentBindings, key, tp.getPos(2))) {
              mapPattern += MAP_PATTERN.OMAP.ordinal();
            }
            this.newTriples = MemoryIndexScan.this.getFromMap(MAP_PATTERN.values()[mapPattern], key.toString(), indicesC);
          }
        };

        // use a "fresh" object to gather the result of the join
        // operation
        // when using the current triple pattern and the previous query
        // results
        final QueryResult qresult = QueryResult.createInstance(itb);

        // replace the previous query results with the new ones
        queryResult.release();
        queryResult = qresult;
      }
View Full Code Here

    return b;
  }

  @Override
  public Message preProcessMessage(final EndOfEvaluationMessage msg) {
    QueryResult result = checkIfAlreadySorted(this._bindings.getQueryResult());
    for (final OperatorIDTuple opId : this.succeedingOperators) {
      opId.processAll(result);
    }
    this._bindings = new ParallelIteratorMultipleQueryResults();
    return msg;
View Full Code Here

  }


  @Override
  public QueryResult join(final Indices indices, final Bindings bindings) {
    final QueryResult queryResult = QueryResult.createInstance();
    queryResult.add(bindings); // empty since no bindings exist yet
    return this.join(indices, queryResult);
  }
View Full Code Here

  }
 
  @Override
  public Message preProcessMessageDebug(final EndOfEvaluationMessage msg,
      final DebugStep debugstep) {
    QueryResult result = checkIfAlreadySorted(this._bindings.getQueryResult());
    for (final OperatorIDTuple opId : this.succeedingOperators) {
      final QueryResultDebug qrDebug = new QueryResultDebug(result,debugstep, this, opId.getOperator(), true);
      ((Operator) opId.getOperator()).processAllDebug(qrDebug, opId.getId(), debugstep);
    }
    this._bindings = new ParallelIteratorMultipleQueryResults();
View Full Code Here

    try {

      // move over the collection of the provided triple patterns
      for (final TriplePattern tp : this.triplePatterns) {

        final QueryResult zQueryResult = queryResult;

        final Iterator<Bindings> itb = new ImmutableIterator<Bindings>() {
          Iterator<Bindings> oldBindings = zQueryResult.oneTimeIterator();
          Bindings currentBindings = null;
          Iterator<Triple> newTriples = null;
          Bindings next = null;

          @Override
          public boolean hasNext() {
            if (this.next != null) {
              return true;
            }
            this.next = this.computeNext();
            return (this.next != null);
          }

          @Override
          public Bindings next() {
            if (this.next != null) {
              final Bindings znext = this.next;
              this.next = null;
              return znext;
            }
            return this.computeNext();
          }

          public Bindings computeNext() {
            while ((this.newTriples == null || !this.newTriples.hasNext()) && this.oldBindings.hasNext()) {
              this.retrieveNewTriples();
            }
            if (this.newTriples == null || !this.newTriples.hasNext()) {
              return null;
            }
            final Triple triple = this.newTriples.next();
            final Bindings cB = this.currentBindings.clone();
            for (int i = 0; i < 3; i++) {
              if (tp.getPos(i).isVariable()) {
                final Literal l = cB.get((Variable) tp.getPos(i));
                if (l != null) {
                  if (!triple.getPos(i).equals(l)) {
                    return this.computeNext();
                  }
                } else {
                  cB.add((Variable) tp.getPos(i), triple.getPos(i));
                }
              }
            }
            cB.addTriple(triple);
            return cB;
          }

          private void retrieveNewTriples() {
            this.currentBindings = this.oldBindings.next();

            final StringBuffer key = new StringBuffer();
            int mapPattern = MAP_PATTERN.NONE.ordinal();

            // compute a key which is as restrictive as possible
            // to cut down the amount of triple pattern which
            // have
            // to be processed to produce the result
            if (MemoryIndexScan.this.computeKey4Maps(this.currentBindings, key, tp.getPos(0))) {
              mapPattern += MAP_PATTERN.SMAP.ordinal();
            }
            if (MemoryIndexScan.this.computeKey4Maps(this.currentBindings, key, tp.getPos(1))) {
              mapPattern += MAP_PATTERN.PMAP.ordinal();
            }
            if (MemoryIndexScan.this.computeKey4Maps(this.currentBindings, key, tp.getPos(2))) {
              mapPattern += MAP_PATTERN.OMAP.ordinal();
            }
            this.newTriples = MemoryIndexScan.this.getFromMap(MAP_PATTERN.values()[mapPattern], key.toString(), indices);
          }
        };

        // use a "fresh" object to gather the result of the join
        // operation
        // when using the current triple pattern and the previous query
        // results
        final QueryResult qresult = QueryResult.createInstance(itb);

        // replace the previous query results with the new ones
        queryResult.release();
        queryResult = qresult;
      }
View Full Code Here

   * else null
   */
  public QueryResult addBinding( Bindings b ){
    store.add( b );
    if( limit > 0 && store.size() > limit ){
      QueryResult ret = forward.process( store , operandID);
      store.reset();
      return ret;
    }
    return null;
  }
View Full Code Here

   * null if not
   */
  public QueryResult addAll( QueryResult qr ){
    store.addAll( qr );
    if( limit > 0 && store.size() > limit ){
      QueryResult ret = forward.process( store, operandID );
      store.reset();
      return ret;
    }
    return null;
  }
View Full Code Here

   * stored here, what has not been processed, but as end of inputStream has been reached, limit will
   * never be reached => no processing.
   * @return processed QueryResult
   */
  public QueryResult forward(){
    QueryResult ret = forward.process( store, operandID );
    store.reset();
    return ret;
  }
View Full Code Here

  @Override
  public QueryResult join(final Indices indices, final Bindings bindings) {
    // a fetch as needed distributed join strategy is implemented
    final QueryClientIndices queryClientIndices = (QueryClientIndices) indices;
    QueryResult result = QueryResult.createInstance();
    result.add(bindings);

    for (final TriplePattern pattern : this.triplePatterns) {
      final QueryResult iResult = result;
      result = QueryResult.createInstance();

      for(final Bindings b: iResult){
        final TriplePattern tpWithReplacedVariables = this.determineTriplePatternToEvaluate(pattern, b);
        final QueryResult resultOfTP = queryClientIndices.evaluateTriplePattern(tpWithReplacedVariables);
        if(resultOfTP!=null){
          result.addAll(this.addBindings(b, resultOfTP));
        }
      }
    }
View Full Code Here

TOP

Related Classes of lupos.datastructures.queryresult.QueryResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.