Package lupos.datastructures.queryresult

Examples of lupos.datastructures.queryresult.QueryResult


            if (this instanceof RDF3XIndexScan) {
              ((RDF3XIndexScan) this)
              .setCollationOrder(RDF3XOperatorGraphGenerator.getCollationOrder(tp, new LinkedList<Variable>()));

            }
            final QueryResult qr = this.join(this.root.dataset);
            if (qr == null) {
              this.setTriplePatterns(ztp);
              return true;
            }
            final Iterator<Bindings> itb = qr.oneTimeIterator();
            try {
              while (itb.hasNext()) {
                final Bindings b = itb.next();
                Literal literal = b.get(var);
                if (literal.originalStringDiffers()){
View Full Code Here


    if (this instanceof RDF3XIndexScan) {
      ((RDF3XIndexScan) this).setCollationOrder(RDF3XOperatorGraphGenerator.getCollationOrder(tp, joinPartners));
      ((RDF3XIndexScan) this).setMinimaMaxima(minima, maxima);

    }
    final QueryResult qrSize = this.join(this.root.dataset);
    if (qrSize == null) {
      // System.out.println("No result for " + tp);
      return null;
    }

    int size = 0;

    if (classBindings == BindingsArrayVarMinMax.class) {
      final Map<Variable, Integer> hmvi = this.bindingsFactory.getPosVariables();
      final Integer[] minArray = new Integer[hmvi.size()];
      final Integer[] maxArray = new Integer[hmvi.size()];

      final Iterator<Bindings> itbSize = qrSize.oneTimeIterator();
      while (itbSize.hasNext()) {
        final Bindings b = itbSize.next();
        for (final Variable v : b.getVariableSet()) {
          final LazyLiteral ll = (LazyLiteral) b.get(v);
          final int pos = hmvi.get(v);
          if (minArray[pos] == null || minArray[pos] > ll.getCode()) {
            minArray[pos] = ll.getCode();
          }
          if (maxArray[pos] == null || maxArray[pos] < ll.getCode()) {
            maxArray[pos] = ll.getCode();
          }
        }
        size++;

        for (int i = 0; i < minArray.length; i++) {
          if (minArray[i] != null) {
            tp.addMinMaxLazyLiteral(i, minArray[i], maxArray[i]);
          }
        }
      }
    } else {
      int maxId = 1;
      if (qrSize instanceof IdIteratorQueryResult) {
        maxId = ((IdIteratorQueryResult) qrSize).getMaxId();
      }

      final int[][] min = new int[maxId][];
      final int[][] max = new int[maxId][];

      size = qrSize.oneTimeSize();

      for (int id = 0; id < maxId; id++) {
        if (min[id] != null) {
          for (int i = 0; i < min[id].length; i++) {
            tp.addMinMaxPresortingNumbers(i, min[id].length,
                id, min[id][i], max[id][i]);
          }
        }
      }
    }

    qrSize.release();

    if (size == 0) {
      System.out.println("No result for " + tp);
      return null;
    }

    // System.out.println("(Statistics) " + tp + ", " + size
    // + " triples retrieved");
    tp.setCardinality(size);

    for (final Variable v : joinPartnersTP) {
      if (intermediate != null && intermediate.containsKey(v)) {
        boolean flag = true;
        final Literal min = minima.get(v);
        if (intermediate.get(v) == null
            || min != null
            && (intermediate.get(v).minimum == null || !min
                .equals(intermediate.get(v).minimum))) {
          flag = false;
        }
        final Literal max = maxima.get(v);
        if (max != null
            && (intermediate.get(v).maximum == null || !max
                .equals(intermediate.get(v).maximum))) {
          flag = false;
        }
        if (flag) {
          result.put(v, intermediate.get(v));
          continue;
        }
      }
      // get result of triple pattern in the correct sorted way!
      final Collection<Variable> cv = new LinkedList<Variable>();
      cv.add(v);
      if (this instanceof RDF3XIndexScan) {
        ((RDF3XIndexScan) this).setCollationOrder(CollationOrder.getCollationOrder(tp, cv));
      }

      QueryResult qr = this.join(this.root.dataset);

      if (this instanceof MemoryIndexScan) {
        // additional sorting phase according to variable v needed
        // for memory index approach!
        final DBMergeSortedBag<Bindings> sort = new DBMergeSortedBag<Bindings>(
            new SortConfiguration(), new Comparator<Bindings>() {
              @Override
              public int compare(final Bindings arg0, final Bindings arg1) {
                return arg0.get(v).compareToNotNecessarilySPARQLSpecificationConform(arg1.get(v));
              }
            }, Bindings.class);
        final Iterator<Bindings> itb = qr.oneTimeIterator();
        while (itb.hasNext()) {
          sort.add(itb.next());
        }
        qr = QueryResult.createInstance(sort.iterator());
      }
      if (qr == null) {
        return result;
      }

      if (size == 0) {
        qr.release();
        return result;
      }
      final double bucketSize = (double) size / MaxNumberBuckets;
      final Iterator<Bindings> ib = qr.oneTimeIterator();
      final VarBucket vb = new VarBucket();
      vb.minimum = minima.get(v);
      vb.maximum = maxima.get(v);
      Entry currentEntry = new Entry();
      Literal lastLiteral = null;
      while (ib.hasNext()) {
        final Bindings b = ib.next();
        final Literal next = b.get(v);
        if (lastLiteral == null
            || lastLiteral
                .compareToNotNecessarilySPARQLSpecificationConform(next) != 0) {
          currentEntry.distinctLiterals += 1.0;
          lastLiteral = next;
        }
        currentEntry.selectivity += 1.0;
        if (currentEntry.selectivity >= bucketSize) {
          currentEntry.literal = b.get(v);
          if (ib.hasNext()) {
            Bindings b2 = ib.next();
            while (ib.hasNext()
                && b2
                    .get(v)
                    .compareToNotNecessarilySPARQLSpecificationConform(
                        currentEntry.literal) == 0) {
              currentEntry.selectivity += 1.0;
              b2 = ib.next();
            }
            vb.selectivityOfInterval.add(currentEntry);
            currentEntry = new Entry();
            currentEntry.distinctLiterals = 1.0;
            currentEntry.selectivity = 1.0;
            if (!ib.hasNext()
                && b2
                    .get(v)
                    .compareToNotNecessarilySPARQLSpecificationConform(
                        next) != 0) {
              currentEntry.literal = b2.get(v);
              vb.selectivityOfInterval.add(currentEntry);
            }
          } else {
            vb.selectivityOfInterval.add(currentEntry);
          }
        }
      }
      qr.release();
      result.put(v, vb);
      if (intermediate != null) {
        intermediate.put(v, vb);
      }
    }
View Full Code Here

        }
        BasicIndexScanOptional.this.indexScanOperator.setTriplePatterns(tps_new);
        if(BasicIndexScanOptional.this.indexScanOperator instanceof RDF3XIndexScan){
          ((RDF3XIndexScan)BasicIndexScanOptional.this.indexScanOperator).setCollationOrder((Collection<Variable>)null);
        }
        final QueryResult queryResult = BasicIndexScanOptional.this.indexScanOperator.join(BasicIndexScanOptional.this.indexScanOperator.getRoot().dataset);
        BasicIndexScanOptional.this.indexScanOperator.setTriplePatterns(tps);
        if(queryResult==null || queryResult.size()==0){
          return new ParallelIterator<Bindings>(){
            boolean sent=false;
            @Override
            public boolean hasNext() {
              return !this.sent;
            }
            @Override
            public Bindings next() {
              if(this.hasNext()){
                this.sent=true;
                return currentBindings;
              } else {
                return null;
              }
            }
            @Override
            public void remove() {
              throw new UnsupportedOperationException();
            }
            @Override
            public void close() {
              // nothing to do...
            }           
          };
        } else {
          return new AddConstantBindingParallelIterator(currentBindings, queryResult.oneTimeIterator());
        }
      }

      @Override
      public void remove() {
View Full Code Here

      try {
        synchronized(this.evaluator){ // avoid any inference of several queries in parallel!
          System.out.println("Evaluating query using the delta approach:\n"+queryParameter);
          // log query-triples by using BindingsArrayReadTriples as class for storing the query solutions!
          Bindings.instanceClass = BindingsArrayReadTriples.class;
          final QueryResult queryResult = (this.evaluator instanceof CommonCoreQueryEvaluator)?((CommonCoreQueryEvaluator)this.evaluator).getResult(queryParameter, true):this.evaluator.getResult(queryParameter);
          final String mimeType = "text/n3";
          System.out.println("Done, sending response using MIME type "+mimeType);
          t.getResponseHeaders().add("Content-type", mimeType);
          t.getResponseHeaders().add("Transfer-encoding", "chunked");
          t.sendResponseHeaders(200, 0);
          OutputStream os = t.getResponseBody();
          if(Endpoint.log){
            os = new OutputStreamLogger(os);
          }

          // get the client's address
          final InetSocketAddress clientAddress = t.getRemoteAddress();
          // get the delta index for this client
          HashSet<Triple> deltaIndex = this.deltaIndices.get(clientAddress);
          if(deltaIndex==null){
            // initialize the delta index if it is not already there
            deltaIndex = new HashSet<Triple>();
          }
          // iterate through the solution and its query triples
          final Iterator<Bindings> itBindings = queryResult.oneTimeIterator();
          while(itBindings.hasNext()){
            final Bindings bindings = itBindings.next();
            for(final Triple triple: bindings.getTriples()){
              // Add the triple to the delta index and check if it is already in the delta index at the same time!
              // (Previously sent triples are eliminated as well as duplicates within the query triples of the same query result.)
View Full Code Here

    };
  }

  private void computeResult(){
    final QueryResult qr = QueryResult.createInstance(this.getIterator());
    if (this.succeedingOperators.size() > 1) {
      qr.materialize();
    }
    for (final OperatorIDTuple opId : this.succeedingOperators) {
      opId.processAll(qr);
    }
  }
View Full Code Here

  protected boolean isPipelineBreaker() {
    return true;
  }

  private void computeResultDebug(final DebugStep debugstep){
    final QueryResult qr = QueryResult.createInstance(this.getIterator());
    if (this.succeedingOperators.size() > 1) {
      qr.materialize();
    }
    for (final OperatorIDTuple opId : this.succeedingOperators) {
      final QueryResultDebug qrDebug = new QueryResultDebug(qr,
          debugstep, this, opId.getOperator(), true);
      ((Operator) opId.getOperator()).processAllDebug(qrDebug, opId
View Full Code Here

        if(breakFor){
          break;
        }
      }
    }
    final QueryResult finalQueryResult = queryResultParameter;
    final Iterator<Bindings> resultIterator = new ImmutableIterator<Bindings>() {
      final Iterator<Bindings> bindIt = finalQueryResult.oneTimeIterator();

      Bindings next = this.computeNext();

      @Override
      public boolean hasNext() {
View Full Code Here

    return null;
  }

  @Override
  public Message preProcessMessage(final EndOfEvaluationMessage msg) {
    final QueryResult qr = this.getQueryResultForAggregatedFilter(this.queryResult);
    if (qr != null) {
      if (this.succeedingOperators.size() > 1) {
        qr.materialize();
      }
      for (final OperatorIDTuple opId: this.succeedingOperators) {
        opId.processAll(qr);
      }
    }
View Full Code Here

  }

  @Override
  public Message preProcessMessageDebug(final EndOfEvaluationMessage msg,
      final DebugStep debugstep) {
    final QueryResult qr = this.getQueryResultForAggregatedFilter(this.queryResult);
    if (qr != null) {
      if (this.succeedingOperators.size() > 1) {
        qr.materialize();
      }
      for (final OperatorIDTuple opId : this.succeedingOperators) {
        final QueryResultDebug qrDebug = new QueryResultDebug(qr,
            debugstep, this, opId.getOperator(), true);
        ((Operator) opId.getOperator()).processAllDebug(qrDebug, opId
View Full Code Here

  protected QueryResult out_postProcess(final QueryResult bindings, int size) {

    if (bindings.size() == 1) {
      return bindings;
    } else if (bindings.size() == 2) {
      final QueryResult ret = getQR();
      final Iterator<Bindings> iter = bindings.iterator();
      final Bindings b1 = iter.next();
      final Bindings b2 = iter.next();
      if (this.comparator.compare(b1, b2) <= 0) {
        ret.add(b1);
        ret.add(b2);
        return ret;
      } else {
        ret.add(b2);
        ret.add(b1);
        return ret;
      }
    }

    QueryResult _LowEnd = getQR();
    QueryResult _HighEnd = getQR();
    final Bindings pivot = bindings.get(new Random().nextInt(bindings
        .size()));

    final Iterator<Bindings> it = bindings.iterator();
    while (it.hasNext()) {

      final Bindings nextB = it.next();

      if (this.comparator.compare(pivot, nextB) <= 0) {
        _HighEnd.add(nextB);
      } else {
        _LowEnd.add(nextB);
      }
    }

    if (checkOnDoubleEntry(_LowEnd, _HighEnd)) {
      System.out.println(_LowEnd);
      System.out.println(_HighEnd);
    }

    if (_LowEnd.size() != 0) {
      if (_LowEnd.size() == size) {
        if (checkIfSorted(_LowEnd)) {
          return _LowEnd;
        }
      }
      _LowEnd = out_postProcess(_LowEnd, size);
    }
    if (_HighEnd.size() != 0) {
      if (_HighEnd.size() == size) {
        if (checkIfSorted(_HighEnd)) {
          return _HighEnd;
        }
      }
      _HighEnd = out_postProcess(_HighEnd, size);
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.