Package lupos.engine.operators.multiinput

Examples of lupos.engine.operators.multiinput.Union


                .evaluateTriplePattern(tp);

            // first generate the Add(...)-operators for
            // the evaluated triple patterns and add them
            // under an UNION operator
            final Union union = new Union();
            final TriggerOneTime trigger = new TriggerOneTime();

            while (it.hasNext()) {
              final Triple t = it.next();
              BasicOperator lastOperator = union;
              for (int i = 0; i < 3; i++) {
                if (tp.getPos(i).isVariable()) {
                  final AddBinding add = new AddBinding(
                      (Variable) tp.getPos(i), t
                          .getPos(i));
                  add
                      .addSucceedingOperator(new OperatorIDTuple(
                          lastOperator, 0));
                  // Not completely correct, but for
                  // the succeeding optimization steps
                  // enough!
                  add
                      .setUnionVariables((HashSet<Variable>) tp
                          .getVariables().clone());
                  add.setIntersectionVariables(add
                      .getUnionVariables());
                  lastOperator.addPrecedingOperator(add);
                  lastOperator = add;
                }
              }
              trigger.addSucceedingOperator(new OperatorIDTuple(
                  lastOperator, 0));
            }

            if (trigger.getSucceedingOperators().size() > 0) {
              trigger.setPrecedingOperators(tp
                  .getPrecedingOperators());
              for (final BasicOperator po : tp
                  .getPrecedingOperators()) {
                po.addSucceedingOperator(new OperatorIDTuple(
                    trigger, 0));
              }
              BasicOperator lo = union;
              if (union.getPrecedingOperators().size() == 1
                  && isOntologyTriplePattern == ISONTOLOGYTRIPLEPATTERN.YES) {
                lo = union.getPrecedingOperators().get(0);
              }
              lo.setSucceedingOperators(tp
                  .getSucceedingOperators());
              for (final OperatorIDTuple so : tp
                  .getSucceedingOperators()) {
View Full Code Here


    // add new operators...
    Join join_new = new lupos.engine.operators.multiinput.join.Join();
    join_new.setIntersectionVariables(join1.getIntersectionVariables());
    join_new.setUnionVariables(union1.getUnionVariables());

    Union union_new = new lupos.engine.operators.multiinput.Union();
    union_new.setIntersectionVariables(union1.getIntersectionVariables());
    union_new.setUnionVariables(union1.getUnionVariables());

    int countingUnions = 0;
    firstLoop: for (;;) {
      // for each 1st sg container
      for (BasicOperator prec : union1.getPrecedingOperators()) {
        boolean match = false;
        // find the matching second one
        for (BasicOperator prec2 : union2.getPrecedingOperators()) {
          if (!compareBothSubgraphContainer((SubgraphContainer) prec,
              (SubgraphContainer) prec2))
            continue;
          match = true;
          /*
           * store with better variable name
           */
          SubgraphContainer sg1 = (SubgraphContainer) prec;
          SubgraphContainer sg2 = (SubgraphContainer) prec2;

          // remove succedding UNION-operator for both subgraphs
          for (OperatorIDTuple eachSucc : prec
              .getSucceedingOperators()) {
            prec.removeSucceedingOperator(eachSucc);
            eachSucc.getOperator().removePrecedingOperator(prec);
          }
          for (OperatorIDTuple eachSucc : prec2
              .getSucceedingOperators()) {
            prec2.removeSucceedingOperator(eachSucc);
            eachSucc.getOperator().removePrecedingOperator(prec2);
          }

          // remove 2nd sg
          for (BasicOperator bo : sg2.getPrecedingOperators()) {
            bo.removeSucceedingOperator(sg2);
            sg2.removePrecedingOperator(bo);
          }

          /*
           * join with is to be included into the subgraph container
           */
          Join smallJoin = new Join();
          smallJoin.cloneFrom(join_new);

          // remove so that the for-loop will end!
          union1.removePrecedingOperator(prec);
          union2.removePrecedingOperator(prec2);

          /*
           * get the index scan in first subgraph
           */
          BasicIndexScan bis = getIndexScan(sg1.getRootOfSubgraph());
          if (bis == null)
            continue;
          /*
           * you have to clone this list, because if changing
           * something, the list is updated immediately, but we want
           * to access the removed items later!
           */
          List<OperatorIDTuple> _bisSucc = bis
              .getSucceedingOperators();
          List<OperatorIDTuple> bisSucc = new ArrayList<>(
              _bisSucc.size());
          for (OperatorIDTuple toClone : _bisSucc) {
            bisSucc.add(toClone);
          }

          /*
           * now add the 2nd subgraph container in the first subgraph
           * container
           */
          sg1.getRootOfSubgraph().addSucceedingOperator(sg2);

          /*
           * remove old connections of the 2nd subgraph (because it
           * should be included into the subgraph)
           */
          for (OperatorIDTuple op : bisSucc) {
            bis.removeSucceedingOperator(op);
            op.getOperator().removePrecedingOperator(bis);
          }
          /*
           * connect the basic index scan and the 2nd subgraph
           * container in the join-operator in the 1st subgraph
           * container
           */
          bis.addSucceedingOperator(smallJoin, 0);
          smallJoin.addPrecedingOperator(sg2);
          sg2.addSucceedingOperator(smallJoin, 1);
          smallJoin.addPrecedingOperator(bis);
          /*
           * now connect the join with the succeeding operators of the
           * old basic index scan (here we use the hack, to clone the
           * succeeding list of the index scan, because when we
           * removed the connection and added the join, the list would
           * have no content)
           */
          for (OperatorIDTuple op : bisSucc) {
            smallJoin.addSucceedingOperator(op);
            op.getOperator().addPrecedingOperator(smallJoin);
          }
          /*
           * now connect the UNION with the result of the 1st subgraph
           * container. In this UNION all partitions are to be
           * combined.
           */
          union_new.addPrecedingOperator(sg1);
          OperatorIDTuple unionIDOperator = new OperatorIDTuple(
              union_new, countingUnions++);
          sg1.addSucceedingOperator(unionIDOperator);

          /*
           * this is to be executed, if the 2nd subgraph is directly
           * added as succeeding of the root, because in this case,
           * the 2nd subgraph container has no preceding (i don't know
           * why this is done this way)
           */
          if (this.root != null) {
            this.root.removeSucceedingOperator(sg2);
          }

          /*
           * add the intersections variables of the 2nd sg to the
           * first one
           */
          Collection<Variable> sg1interSection = sg1
              .getIntersectionVariables();
          Collection<Variable> sg2interSection = sg2
              .getIntersectionVariables();
          if (sg1interSection == null)
            sg1interSection = new HashSet<>();
          if (sg2interSection != null)
            sg1interSection.addAll(sg2interSection);
          sg1.setIntersectionVariables(sg1interSection);
          /*
           * add the union variables of the 2nd sg to the first one
           */
          Collection<Variable> sg1union = sg1.getUnionVariables();
          Collection<Variable> sg2union = sg2.getUnionVariables();
          if (sg1union == null)
            sg1union = new HashSet<>();
          if (sg2union != null)
            sg1union.addAll(sg2union);
          sg1.setUnionVariables(sg1union);

          log.debug(String.format(
              "Rule %s: Local join between %s and %s in %s",
              this.ruleName, sg1, sg2, sg1));

          continue firstLoop;
        }
        /*
         * we have no match -> no partitions which can be used for local
         * join -> exit!
         */
        if (!match)
          return;
      }
      break;
    }

    /*
     * stuff from the rule builder ...
     */

    // remove obsolete connections...
    this.union1.removeSucceedingOperator(this.join1);
    this.join1.removePrecedingOperator(this.union1);

    // remove all connections to the follower of our processing tree
    // and add the new union
    List<OperatorIDTuple> succeddingsOfAll = this.join1
        .getSucceedingOperators();
    for (OperatorIDTuple _child : succeddingsOfAll) {
      _child.getOperator().removePrecedingOperator(this.join1);
      union_new.addSucceedingOperator(_child);
      _child.getOperator().addPrecedingOperator(union_new);
    }
    // delete unreachable operators...
    this.deleteOperatorWithoutParentsRecursive(this.join1, _startNodes);
    this.deleteOperatorWithoutParentsRecursive(this.union1, _startNodes);
View Full Code Here

    }
  }

  public Object visit(Disjunction obj, Object arg) throws RIFException {
    // jeden einzelnen zweig mit Union zusammenf�hren
    final Union union = new Union();
    for (final IExpression expr : obj.exprs) {
      final BasicOperator subOperator = (BasicOperator) expr.accept(this,
          arg);
      subOperator.addSucceedingOperator(union);
    }
View Full Code Here

      this.add(this.tripleProducer, BuildOperatorGraphRuleVisitor.keyEquality, constructEq);
    }
    if (resultOps.size() == 1) {
      return resultOps.iterator().next();
    } else {
      final Union union = new Union();
      for (final BasicOperator op : resultOps){
        union.addSucceedingOperator(op);
        op.addPrecedingOperator(union);
      }
      return union;
    }
  }
View Full Code Here

  @Override
  public Object visit(final Disjunction obj, final Object arg) throws RIFException {
    // Einf�hrung eines Union Operators, der alle Untergeordneten
    // Operatoren
    // zusammenf�hrt
    final Union union = new Union();
//    final Distinct distinct = new Distinct();
//    distinct.setSucceedingOperator((OperatorIDTuple) arg);
//    union.addSucceedingOperator(distinct);
    for (final IExpression expr : obj.exprs){
      expr.accept(this, new OperatorIDTuple(union, union.getSucceedingOperators().size()));
    }

//    return distinct;
    return union;
  }
View Full Code Here

      }
    }
    if (flag) {
      // index -> (union -> distinct) <- triplepattern : return union
//      Distinct distinct = new Distinct();
      final Union union = new Union();
//      union.setSucceedingOperator(new OperatorIDTuple(distinct, 0));
      index.setSucceedingOperator(new OperatorIDTuple(union, 0));
      union.addPrecedingOperator(index);
//      distinct.setSucceedingOperator((OperatorIDTuple) arg);
      pattern.setSucceedingOperator(new OperatorIDTuple(union, 1));
      union.addPrecedingOperator(pattern);
      for(final KeyTriplePattern keyTP: possibleMatchingKeysOfProducers){
        this.add(this.tripleConsumer, keyTP, pattern);
      }
//      return distinct;
      if(arg!=null){
        union.setSucceedingOperator((OperatorIDTuple) arg);
        ((OperatorIDTuple) arg).getOperator().addPrecedingOperator(union);
      }
      return union;
    } else {
      if(arg!=null){
View Full Code Here

    node.jjtGetChild(0).accept(this, connection, graphConstraint);
  }

  @Override
  public void visit(final ASTUnionConstraint node, final OperatorConnection connection, final Item graphConstraint) {
    final Union union = new Union();
    connection.connectAndSetAsNewOperatorConnection(union);
    node.jjtGetChild(0).accept(this, connection, graphConstraint);
    connection.setOperatorConnection(union,1);
    node.jjtGetChild(1).accept(this, connection, graphConstraint);
  }
View Full Code Here

      }

      final PathLengthZero zeroOperator = new PathLengthZero(subject, object, allowedSubjects, allowedObjects);
      memoryScan.addSucceedingOperator(new OperatorIDTuple(zeroOperator,0));

      final Union union = new Union();
      zeroOperator.addSucceedingOperator(new OperatorIDTuple(union,0));
      startingOperator.addSucceedingOperator(new OperatorIDTuple(union,1));

      final InMemoryDistinct distinct = new InMemoryDistinct();
      union.addSucceedingOperator(new OperatorIDTuple(distinct,0));

      return distinct;
    } else {
      // alternative way to evaluate (...)? without using the PathLengthZero operator!

      final BasicOperator startingOperator = node.jjtGetChild(0).accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);
      final Union union = new Union();

      final BasicOperator leftSide = this.zeroPath(node, graphConstraint, subject, object, subjectNode, objectNode);
      leftSide.addSucceedingOperator(new OperatorIDTuple(union,0));

      final Projection projection = new Projection();
      projection.addProjectionElement(subject);
      projection.addProjectionElement(object);
      if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
        projection.addProjectionElement((Variable)graphConstraint);
      }

      startingOperator.addSucceedingOperator(new OperatorIDTuple(union,1));

      union.addSucceedingOperator(new OperatorIDTuple(projection,0));
      return projection;
    }
  }
View Full Code Here

      final BasicOperator memoryScan = this.indexScanCreator.createIndexScanAndConnectWithRoot(null, temp, graphConstraint);

      final PathLengthZero zeroOperator = new PathLengthZero(subject, object, allowedSubjects, allowedObjects);
      memoryScan.addSucceedingOperator(new OperatorIDTuple(zeroOperator,0));

      final Union union = new Union();
      zeroOperator.addSucceedingOperator(new OperatorIDTuple(union,0));
      startingOperator.removeSucceedingOperator(closure);
      startingOperator.addSucceedingOperator(new OperatorIDTuple(union,1));
      union.addSucceedingOperator(new OperatorIDTuple(closure,0));

      return closure;
    } else {
      // alternative way to evaluate (...)* without using the Closure and PathLengthZero operators!

      // Plus Operator
      final BasicOperator startingOperator = node.jjtGetChild(0).accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);

      final Projection projection = new Projection();
      projection.addProjectionElement(subject);
      projection.addProjectionElement(object);
      if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
        projection.addProjectionElement((Variable)graphConstraint);
      }

      final Union union = new Union();
      final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
      try {
        final Filter filter = new Filter("(" + subject + " != " + object + ")");

        final ReplaceVar replaceVar = new ReplaceVar();
        replaceVar.addSubstitution(object, subject);
        final Variable variable = this.getVariable(subject.toString(), object.toString(), "interimVariable");
        replaceVar.addSubstitution(variable, object);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVar.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }
        final ReplaceVar replaceVari = new ReplaceVar();
        replaceVari.addSubstitution(subject, subject);
        replaceVari.addSubstitution(object, variable);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVari.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }

        startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
        startingOperator.addSucceedingOperator(new OperatorIDTuple(union,1));
        final Join intermediateJoinOperator = new Join();
        replaceVar.addSucceedingOperator(new OperatorIDTuple(memoryDistinct,0));
        memoryDistinct.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,1));
        filter.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,0));
        filter.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        intermediateJoinOperator.addSucceedingOperator(new OperatorIDTuple(replaceVari,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(union,1));
        union.addSucceedingOperator(new OperatorIDTuple(projection,0));

        //Zero Operator
        final BasicOperator startingPoint = this.zeroPath(node, graphConstraint, subject, object, subjectNode, objectNode);

        startingPoint.addSucceedingOperator(new OperatorIDTuple(union,0));
View Full Code Here

      firstBind.addProjectionElement(subject, objectNode);
      // TODO consider graphConstraint!
      this.indexScanCreator.createEmptyIndexScanSubmittingQueryResultWithOneEmptyBindingsAndConnectWithRoot(new OperatorIDTuple(firstBind,0), graphConstraint);
      return firstBind;
    } else {
      final Union union = new Union();
      final Variable intermediatePredicate = this.getVariable(subject.toString(),object.toString(),"intermediatePredicate");
      final Variable intermediateObject = this.getVariable(subject.toString(),object.toString(),"intermediateObject");
      final Item[] items = {subject, intermediatePredicate, intermediateObject};
      LinkedList<TriplePattern> temp = new LinkedList<TriplePattern>();
      TriplePattern tp = new TriplePattern(items);
      temp.add(tp);
      this.indexScanCreator.createIndexScanAndConnectWithRoot(new OperatorIDTuple(union,0), temp, graphConstraint);

      items[0] = intermediateObject;
      items[1] = intermediatePredicate;
      items[2] = subject;
      temp = new LinkedList<TriplePattern>();
      tp = new TriplePattern(items.clone());
      temp.add(tp);
      this.indexScanCreator.createIndexScanAndConnectWithRoot(new OperatorIDTuple(union,1), temp, graphConstraint);

      final Projection projection = new Projection();
      projection.addProjectionElement(subject);
      projection.addProjectionElement(object);
      if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
        projection.addProjectionElement((Variable)graphConstraint);
      }
      final ASTVar n = new ASTVar(100);
      n.setName(subject.toString().substring(1));
      final Bind bind = new Bind(subject);
      bind.addProjectionElement(object,n);
      union.addSucceedingOperator(new OperatorIDTuple(bind,0));
      bind.addSucceedingOperator(new OperatorIDTuple(projection,0));
      final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
      projection.addSucceedingOperator(new OperatorIDTuple(memoryDistinct,0));
      return memoryDistinct;
    }
View Full Code Here

TOP

Related Classes of lupos.engine.operators.multiinput.Union

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.