private boolean _checkPrivate0(BasicOperator _op) {
    if (_op.getClass() != lupos.engine.operators.singleinput.Filter.class) {
      return false;
    }

    this.f = (lupos.engine.operators.singleinput.Filter) _op;

    List<BasicOperator> _precedingOperators_1_0 = _op.getPrecedingOperators();

    this._dim_0 = -1;
    this.o1 = new lupos.engine.operators.BasicOperator[_precedingOperators_1_0.size()];

    for (BasicOperator _precOp_1_0 : _precedingOperators_1_0) {
      this._dim_0 += 1;

      if (!this._checkPrivate1(_precOp_1_0)) {
        return false;
      }
    }

    List<OperatorIDTuple> _succedingOperators_1_0 = _op.getSucceedingOperators();

    this._dim_0 = -1;
    this.o2 = new lupos.engine.operators.BasicOperator[_succedingOperators_1_0.size()];

    for (OperatorIDTuple _sucOpIDTup_1_0 : _succedingOperators_1_0) {
      this._dim_0 += 1;

      if (!this._checkPrivate2(_sucOpIDTup_1_0.getOperator())) {
        return false;
      }
    }

    return true;
  }
 /** {@inheritDoc} */
 @Override
 public void insertFederatedQueryOperator(
     final ASTService node, final OperatorConnection connection) {
   SeveralSucceedingOperators sso = new SeveralSucceedingOperators();
   BasicOperator federatedQuery = this.getFederatedQuery(node);
   Node child0 = node.jjtGetChild(0);
   if (child0 instanceof ASTVar) {
     Sort sort = new Sort();
     LinkedList<Variable> listOfVars = new LinkedList<Variable>();
     listOfVars.add(new Variable(((ASTVar) child0).getName()));
     ComparatorVariables comparator = new ComparatorVariables(listOfVars);
     sort.setComparator(comparator);
     Group group = new Group(comparator);
     sort.addSucceedingOperator(group);
     group.addSucceedingOperator(federatedQuery);
     sso.addSucceedingOperator(sort);
   } else {
     sso.addSucceedingOperator(federatedQuery);
   }
   Join join = new Join();
   federatedQuery.addSucceedingOperator(join, 1);
   sso.addSucceedingOperator(join, 0);
   connection.connect(join);
   connection.setOperatorConnection(sso);
 }
Example #3
0
 /**
  * This method returns the first found preceding operator, which is connected to this operator
  * with the given id
  *
  * @param id the id of the OperatorIDTuple
  * @return the first found preceding operator, which is connected to this operator with the given
  *     id, otherwise null
  */
 public BasicOperator getPrecedingOperatorWithID(final int id) {
   for (BasicOperator prec : this.getPrecedingOperators()) {
     if (prec.getOperatorIDTuple(this).getId() == id) {
       return prec;
     }
   }
   return null;
 }
  protected void replace(HashMap<Class<?>, HashSet<BasicOperator>> _startNodes) {
    // remove obsolete connections...
    int[] _label_a = null;

    int _label_a_count = 0;
    _label_a = new int[this.o1.length];

    for (lupos.engine.operators.BasicOperator _parent : this.o1) {
      _label_a[_label_a_count] = _parent.getOperatorIDTuple(this.p).getId();
      _label_a_count += 1;

      _parent.removeSucceedingOperator(this.p);
      this.p.removePrecedingOperator(_parent);
    }

    this.p.removeSucceedingOperator(this.o2);
    this.o2.removePrecedingOperator(this.p);

    // add new operators...
    lupos.rif.operator.PredicatePattern[] p_new = null;
    p_new = new lupos.rif.operator.PredicatePattern[this.o1.length];

    for (this._dim_0 = 0; this._dim_0 < p_new.length; this._dim_0 += 1) {
      p_new[this._dim_0] = new lupos.rif.operator.PredicatePattern();
    }

    // add new connections...
    for (this._dim_0 = 0; this._dim_0 < this.o1.length; this._dim_0 += 1) {
      this.o1[this._dim_0].addSucceedingOperator(p_new[this._dim_0]);
      p_new[this._dim_0].addPrecedingOperator(this.o1[this._dim_0]);
    }

    _label_a_count = 0;

    for (lupos.rif.operator.PredicatePattern _parent : p_new) {
      _parent.addSucceedingOperator(new OperatorIDTuple(this.o2, _label_a[_label_a_count]));
      this.o2.addPrecedingOperator(_parent);

      _label_a_count += 1;
    }

    // delete unreachable operators...
    this.deleteOperatorWithoutParentsRecursive(this.p, _startNodes);

    // additional replace method code...
    for (lupos.rif.operator.PredicatePattern tmp_p : p_new) {
      tmp_p.getSucceedingOperators().get(0).setId(id);
      tmp_p.setUnionVariables(
          new java.util.HashSet<lupos.datastructures.items.Variable>(this.p.getUnionVariables()));
      tmp_p.setIntersectionVariables(
          new java.util.HashSet<lupos.datastructures.items.Variable>(
              this.p.getIntersectionVariables()));
      tmp_p.setPredicateName(this.p.getPredicateName());
      tmp_p.setPatternItems(this.p.getPatternItems());
    }
  }
Example #5
0
 public void removeFromOperatorGraph() {
   for (final OperatorIDTuple oidtuple : this.getSucceedingOperators()) {
     oidtuple.getOperator().removePrecedingOperator(this);
     oidtuple.getOperator().addPrecedingOperators(this.getPrecedingOperators());
   }
   for (final BasicOperator prec : this.getPrecedingOperators()) {
     prec.removeSucceedingOperator(this);
     prec.addSucceedingOperators(this.getSucceedingOperators());
   }
 }
Example #6
0
 public void removeFromOperatorGraphWithoutConnectingPrecedingWithSucceedingOperators() {
   for (final OperatorIDTuple oidtuple : this.getSucceedingOperators()) {
     oidtuple.getOperator().removePrecedingOperator(this);
   }
   this.succeedingOperators.clear();
   for (final BasicOperator prec : this.getPrecedingOperators()) {
     prec.removeSucceedingOperator(this);
   }
   this.precedingOperators.clear();
 }
 public void logDeletedOperatorsBelow(
     final BasicOperator parent, final Collection<BasicOperator> deleted) {
   if (parent.getPrecedingOperators().size() < 2) {
     deleted.add(parent);
     final OperatorIDTuple[] opIDTuples =
         parent.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
     for (final OperatorIDTuple opIDTuple : opIDTuples) {
       logDeletedOperatorsBelow(opIDTuple.getOperator(), deleted);
     }
   }
 }
Example #8
0
 /**
  * The clone method to clone the current operator
  *
  * @return the cloned operator
  */
 @Override
 public BasicOperator clone() {
   BasicOperator result = null;
   try {
     result = (BasicOperator) super.clone();
     result.cloneFrom(this);
   } catch (final CloneNotSupportedException ex) {
     // just return null;
   }
   return result;
 }
Example #9
0
 /**
  * applyRulesDebugByteArray.
  *
  * @param op a {@link lupos.engine.operators.BasicOperator} object.
  * @param mapStartNodes a {@link java.util.Map} object.
  * @param rules an array of {@link lupos.optimizations.logical.rules.Rule} objects.
  * @param untilRule a {@link lupos.optimizations.logical.rules.Rule} object.
  * @param prefixInstance a {@link lupos.rdf.Prefix} object.
  * @return a {@link java.util.List} object.
  */
 public List<DebugContainer<BasicOperatorByteArray>> applyRulesDebugByteArray(
     final BasicOperator op,
     final Map<Class<? extends BasicOperator>, Set<BasicOperator>> mapStartNodes,
     final Rule[] rules,
     final Rule untilRule,
     final Prefix prefixInstance) {
   final List<DebugContainer<BasicOperatorByteArray>> debug =
       new LinkedList<DebugContainer<BasicOperatorByteArray>>();
   for (final Rule r : rules) {
     if (untilRule != null && r.equals(untilRule)) break;
     while (r.applyDebug(op, mapStartNodes)) {
       debug.add(
           new DebugContainer<BasicOperatorByteArray>(
               r.getName(),
               r.getDescription(),
               BasicOperatorByteArray.getBasicOperatorByteArray(op.deepClone(), prefixInstance)));
       // mapStartNodes = RuleEngine.createStartNodeMap(op);
       if (checkNodeMap) {
         // check if all nodes of the operatorgraph are in the
         // map:
         op.visit(
             new SimpleOperatorGraphVisitor() {
               public Object visit(final BasicOperator basicOperator) {
                 if (!checkIfInNodeMap(basicOperator, mapStartNodes))
                   System.err.println(
                       "The following node is not in mapStartNodes:" + basicOperator);
                 return null;
               }
             });
         // check if all nodes of the map are in the
         // operatorgraph:
         for (final Map.Entry<Class<? extends BasicOperator>, Set<BasicOperator>> entry :
             mapStartNodes.entrySet()) {
           for (final BasicOperator bo : entry.getValue()) {
             final FindInOperatorGraph findInOperatorGraph = new FindInOperatorGraph(bo);
             op.visit(findInOperatorGraph);
             if (!findInOperatorGraph.getFlag())
               System.err.println(
                   "The following node for class "
                       + entry.getKey()
                       + " is not in the operatorgraph:"
                       + bo);
           }
         }
       }
       Rule[] rulesToApply = r.getRulesToApply(this);
       if (rulesToApply == null) rulesToApply = this.rules;
       debug.addAll(applyRulesDebugByteArray(op, mapStartNodes, rulesToApply, r, prefixInstance));
     }
   }
   return debug;
 }
Example #10
0
  /**
   * addToNodeMap.
   *
   * @param basicOperator a {@link lupos.engine.operators.BasicOperator} object.
   * @param mapStartNodes a {@link java.util.Map} object.
   */
  public static void addToNodeMap(
      final BasicOperator basicOperator,
      final Map<Class<? extends BasicOperator>, Set<BasicOperator>> mapStartNodes) {
    Set<BasicOperator> set = mapStartNodes.get(basicOperator.getClass());
    if (set == null) {
      set = new HashSet<BasicOperator>();
    }
    set.add(basicOperator);
    mapStartNodes.put(basicOperator.getClass(), set);

    set = mapStartNodes.get(BasicOperator.class);
    if (set == null) {
      set = new HashSet<BasicOperator>();
    }
    set.add(basicOperator);
    mapStartNodes.put(BasicOperator.class, set);

    if (basicOperator instanceof Join
        &&
        // exclude special case:
        basicOperator
                .getClass()
                .getPackage()
                .getName()
                .compareTo("lupos.engine.operators.multiinput.join.parallel")
            != 0) {
      set = mapStartNodes.get(Join.class);
      if (set == null) {
        set = new HashSet<BasicOperator>();
      }
      set.add(basicOperator);
      mapStartNodes.put(Join.class, set);
    }

    if (basicOperator instanceof Optional
        ||
        // include special case:
        basicOperator
                .getClass()
                .getPackage()
                .getName()
                .compareTo("lupos.engine.operators.multiinput.optional.parallel")
            == 0) {
      set = mapStartNodes.get(Optional.class);
      if (set == null) {
        set = new HashSet<BasicOperator>();
      }
      set.add(basicOperator);
      mapStartNodes.put(Optional.class, set);
    }
  }
Example #11
0
  /**
   * deleteFromNodeMap.
   *
   * @param basicOperator a {@link lupos.engine.operators.BasicOperator} object.
   * @param mapStartNodes a {@link java.util.Map} object.
   */
  public static void deleteFromNodeMap(
      final BasicOperator basicOperator,
      final Map<Class<? extends BasicOperator>, Set<BasicOperator>> mapStartNodes) {
    Set<BasicOperator> set = mapStartNodes.get(basicOperator.getClass());
    if (set != null) {
      set.remove(basicOperator);
      if (set.size() > 0) mapStartNodes.put(basicOperator.getClass(), set);
      else mapStartNodes.remove(basicOperator.getClass());
    }

    set = mapStartNodes.get(BasicOperator.class);
    if (set != null) {
      set.remove(basicOperator);
      mapStartNodes.put(BasicOperator.class, set);
    }

    if (basicOperator instanceof Join
        &&
        // exclude special case:
        basicOperator
                .getClass()
                .getPackage()
                .getName()
                .compareTo("lupos.engine.operators.multiinput.optional.parallel")
            != 0) {
      set = mapStartNodes.get(Join.class);
      if (set != null) {
        set.remove(basicOperator);
        if (set.size() > 0) mapStartNodes.put(Join.class, set);
        else mapStartNodes.remove(Join.class);
      }
    }

    if (basicOperator instanceof Optional
        ||
        // include special case:
        basicOperator
                .getClass()
                .getPackage()
                .getName()
                .compareTo("lupos.engine.operators.multiinput.optional.parallel")
            == 0) {
      set = mapStartNodes.get(Optional.class);
      if (set != null) {
        set.remove(basicOperator);
        if (set.size() > 0) mapStartNodes.put(Optional.class, set);
        else mapStartNodes.remove(Optional.class);
      }
    }
  }
Example #12
0
  public void dump(final String prefix, final HashSet<BasicOperator> visited) {
    if (visited.contains(this)) {
      return;
    }

    visited.add(this);

    System.out.println(prefix + this.toString());

    for (final OperatorIDTuple childIDT : this.succeedingOperators) {
      final BasicOperator child = childIDT.getOperator();

      child.dump(prefix + "-", visited);
    }
  }
  protected void replace(HashMap<Class<?>, HashSet<BasicOperator>> _startNodes) {
    // remove obsolete connections...
    for (lupos.engine.operators.BasicOperator _parent : this.o1) {
      _parent.removeSucceedingOperator(this.f);
      this.f.removePrecedingOperator(_parent);
    }

    for (lupos.engine.operators.BasicOperator _child : this.o2) {
      this.f.removeSucceedingOperator(_child);
      _child.removePrecedingOperator(this.f);
    }

    // add new operators...
    lupos.rif.operator.RuleFilter rf = null;
    rf = new lupos.rif.operator.RuleFilter();

    // add new connections...
    for (lupos.engine.operators.BasicOperator _parent : this.o1) {
      _parent.addSucceedingOperator(rf);
      rf.addPrecedingOperator(_parent);
    }

    for (lupos.engine.operators.BasicOperator _child : this.o2) {
      rf.addSucceedingOperator(_child);
      _child.addPrecedingOperator(rf);
    }

    // delete unreachable operators...
    this.deleteOperatorWithoutParentsRecursive(this.f, _startNodes);

    // additional replace method code...
    lupos.optimizations.sparql2core_sparql.SPARQLParserVisitorImplementationDumper filterDumper =
        new lupos.optimizations.sparql2core_sparql.SPARQLParserVisitorImplementationDumper();

    String equalsString =
        (String)
            filterDumper.visit(
                (lupos.sparql1_1.ASTEqualsNode) this.f.getNodePointer().jjtGetChild(0));

    lupos.rif.model.Equality equality = null;

    try {
      lupos.rif.generated.syntaxtree.RIFAtomic atomic =
          new lupos.rif.generated.parser.RIFParser(
                  new java.io.StringReader(equalsString.substring(1, equalsString.length() - 1)))
              .RIFAtomic();
      lupos.rif.visitor.ParseSyntaxTreeVisitor rifParser =
          new lupos.rif.visitor.ParseSyntaxTreeVisitor();
      equality = (lupos.rif.model.Equality) atomic.accept(rifParser, null);
    } catch (lupos.rif.generated.parser.ParseException e) {
      e.printStackTrace();
      return;
    }

    rf.setExpression(equality);
    rf.setUnionVariables(this.f.getUnionVariables());
    rf.setIntersectionVariables(this.f.getIntersectionVariables());
  }
Example #14
0
  /**
   * checkIfInNodeMap.
   *
   * @param basicOperator a {@link lupos.engine.operators.BasicOperator} object.
   * @param mapStartNodes a {@link java.util.Map} object.
   * @return a boolean.
   */
  public static boolean checkIfInNodeMap(
      final BasicOperator basicOperator,
      final Map<Class<? extends BasicOperator>, Set<BasicOperator>> mapStartNodes) {
    Set<BasicOperator> set = mapStartNodes.get(basicOperator.getClass());
    if (set == null) {
      return false;
    }
    if (!set.contains(basicOperator)) return false;

    set = mapStartNodes.get(BasicOperator.class);
    if (set == null) {
      return false;
    }
    if (!set.contains(basicOperator)) return false;

    if (basicOperator instanceof Join
        &&
        // exclude special case:
        basicOperator
                .getClass()
                .getPackage()
                .getName()
                .compareTo("lupos.engine.operators.multiinput.optional.parallel")
            != 0) {
      set = mapStartNodes.get(Join.class);
      if (set == null) {
        return false;
      }
      if (!set.contains(basicOperator)) return false;
    }

    if (basicOperator instanceof Optional
        ||
        // include special case:
        basicOperator
                .getClass()
                .getPackage()
                .getName()
                .compareTo("lupos.engine.operators.multiinput.optional.parallel")
            == 0) {
      set = mapStartNodes.get(Optional.class);
      if (set == null) {
        return false;
      }
      if (!set.contains(basicOperator)) return false;
    }
    return true;
  }
 public void deleteAllBelow(
     final BasicOperator parent,
     final BasicOperator child,
     final Collection<BasicOperator> deleted) {
   if (child.getPrecedingOperators().size() > 1) {
     parent.removeSucceedingOperator(child);
     child.removePrecedingOperator(parent);
   } else {
     deleted.add(parent);
     final OperatorIDTuple[] opIDTuples =
         child.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
     for (final OperatorIDTuple opIDTuple : opIDTuples) {
       deleteAllBelow(child, opIDTuple.getOperator(), deleted);
     }
   }
 }
  /** {@inheritDoc} */
  @SuppressWarnings("rawtypes")
  @Override
  public JSONObject serialize(final BasicOperator operator, final int node_id)
      throws JSONException {
    final JSONObject json = new JSONObject();
    /*
     * store preceeding's and remove them from the subgraph, because they
     * are not to be serialized (but they are added later)
     */
    final List<BasicOperator> storePrecds =
        new LinkedList<BasicOperator>(((SubgraphContainer) operator).getPrecedingOperators());
    for (final BasicOperator op : storePrecds) {
      ((SubgraphContainer) operator).removePrecedingOperator(op);
    }
    /*
     * store succeeding's and remove them from the subgraph (see above)
     */
    final List<OperatorIDTuple> storeSuccs =
        new LinkedList<OperatorIDTuple>(((SubgraphContainer) operator).getSucceedingOperators());
    for (final OperatorIDTuple op : storeSuccs) {
      ((SubgraphContainer) operator).removeSucceedingOperator(op);
    }

    json.put("type", operator.getClass().getName());
    json.put("node_id", node_id);

    /*
     * now serialize the subgraph container
     */
    final SubgraphContainerFormatter serializer = new SubgraphContainerFormatter();
    final JSONObject serializedGraph =
        serializer.serialize(((SubgraphContainer) operator).getRootOfSubgraph(), 0);
    json.put("subgraph", serializedGraph);

    /*
     * now serialize the subgraph container's key
     */
    final Object key = ((SubgraphContainer) operator).getKey();
    try {
      final String sgKey = JsonWriter.objectToJson(key);
      json.put("key", sgKey);
    } catch (final IOException e) {
      json.put("key", "Not serializable.");
      propagate(
          new RuntimeException(
              String.format("The key of subgraphContainer %s is not serialzable.", operator)));
    }

    // now add the connections ... we have removed above.
    for (final BasicOperator op : storePrecds) {
      ((SubgraphContainer) operator).addPrecedingOperator(op);
    }
    for (final OperatorIDTuple op : storeSuccs) {
      ((SubgraphContainer) operator).addSucceedingOperator(op);
    }
    return json;
  }
Example #17
0
  /**
   * This method clones not only the current operator, but all of its succeeding operators
   * recursively.
   *
   * @return the cloned operator
   */
  public BasicOperator deepClone() {
    final BasicOperator op =
        (BasicOperator)
            visit(
                new SimpleOperatorGraphVisitor() {
                  /** */
                  private static final long serialVersionUID = -2374279115052843835L;

                  final Map<BasicOperator, BasicOperator> clones =
                      new HashMap<BasicOperator, BasicOperator>();

                  @Override
                  public Object visit(final BasicOperator basicOperator) {
                    BasicOperator cloneCurrent;
                    if (this.clones.containsKey(basicOperator)) {
                      cloneCurrent = this.clones.get(basicOperator);
                    } else {
                      cloneCurrent = basicOperator.clone();
                      this.clones.put(basicOperator, cloneCurrent);
                    }

                    final LinkedList<OperatorIDTuple> newSucc = new LinkedList<OperatorIDTuple>();

                    for (final OperatorIDTuple opid : basicOperator.succeedingOperators) {
                      BasicOperator clone = null;
                      if (this.clones.containsKey(opid.getOperator())) {
                        clone = this.clones.get(opid.getOperator());
                      } else {
                        clone = opid.getOperator().clone();
                        this.clones.put(opid.getOperator(), clone);
                      }
                      newSucc.add(new OperatorIDTuple(clone, opid.getId()));
                    }

                    cloneCurrent.setSucceedingOperators(newSucc);
                    return cloneCurrent;
                  }
                });

    op.deleteParents();
    op.setParents();

    return op;
  }
  /** {@inheritDoc} */
  @Override
  public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso, final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    final LinkedList<BasicOperator> pres =
        (LinkedList<BasicOperator>) replaceVar.getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs =
        (LinkedList<OperatorIDTuple>) replaceVar.getSucceedingOperators();

    BasicOperator pre;
    OperatorIDTuple idTuple;
    // Connect all precessors to all successors
    for (int i = 0; i < pres.size(); i++) {
      for (int a = 0; a < succs.size(); a++) {
        idTuple = succs.get(a);
        pre = pres.get(i);
        pre.addSucceedingOperator(new OperatorIDTuple(idTuple.getOperator(), idTuple.getId()));
        pre.removeSucceedingOperator(replaceVar);
      }
    }

    BasicOperator succ;
    // And all successors to all precessors
    for (int i = 0; i < succs.size(); i++) {
      for (int a = 0; a < pres.size(); a++) {
        succ = succs.get(i).getOperator();
        succ.addPrecedingOperator(pres.get(a));
        succ.removePrecedingOperator(replaceVar);
      }
    }

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
    // should have been done manually: rootOperator.sendMessage(new
    // BoundVariablesMessage());
    deleted.add(replaceVar);
    if (deleted.size() > 0 || added.size() > 0)
      return new Tuple<Collection<BasicOperator>, Collection<BasicOperator>>(added, deleted);
    else return null;
  }
  private boolean _checkPrivate0(BasicOperator _op) {
    if (_op.getClass() != lupos.rif.operator.PredicatePattern.class) {
      return false;
    }

    this.p = (lupos.rif.operator.PredicatePattern) _op;

    List<BasicOperator> _precedingOperators_1_0 = _op.getPrecedingOperators();

    this._dim_0 = -1;
    this.o1 = new lupos.engine.operators.BasicOperator[_precedingOperators_1_0.size()];

    for (BasicOperator _precOp_1_0 : _precedingOperators_1_0) {
      this._dim_0 += 1;

      if (!this._checkPrivate1(_precOp_1_0)) {
        return false;
      }
    }

    List<OperatorIDTuple> _succedingOperators_1_0 = _op.getSucceedingOperators();

    if (_succedingOperators_1_0.size() != 1) {
      return false;
    }

    for (OperatorIDTuple _sucOpIDTup_1_0 : _succedingOperators_1_0) {
      if (!(_sucOpIDTup_1_0.getOperator() instanceof lupos.engine.operators.BasicOperator)) {
        continue;
      }

      this.o2 = (lupos.engine.operators.BasicOperator) _sucOpIDTup_1_0.getOperator();

      return true;
    }

    return false;
  }
  @Override
  public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso, final BasicOperator rootOperator) {
    final GenerateAddEnv genAdd = (GenerateAddEnv) mso.get("genAdd");
    final Optional optional = (Optional) mso.get("optional");

    final LinkedList<BasicOperator> pres =
        (LinkedList<BasicOperator>) genAdd.getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs =
        (LinkedList<OperatorIDTuple>) optional.getSucceedingOperators();

    BasicOperator pre;
    for (int i = 0; i < pres.size(); i++) {
      pre = pres.get(i);
      pre.addSucceedingOperator(new OperatorIDTuple(optional, 0));
      pre.removeSucceedingOperator(genAdd);
      optional.addPrecedingOperator(pre);
    }

    optional.removePrecedingOperator(genAdd);
    optional.setSucceedingOperator(new OperatorIDTuple(genAdd, 0));

    genAdd.setPrecedingOperator(optional);
    genAdd.setSucceedingOperators(succs);

    BasicOperator succ;
    for (int i = 0; i < succs.size(); i++) {
      succ = succs.get(i).getOperator();
      succ.addPrecedingOperator(genAdd);
      succ.removePrecedingOperator(optional);
    }

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
    rootOperator.sendMessage(new BoundVariablesMessage());
    return null;
  }
 public static Set<Variable> getAllVariablesOfQuery(final BasicOperator rootNode) {
   final Set<Variable> maxVariables = new TreeSet<Variable>();
   rootNode.visit(
       new SimpleOperatorGraphVisitor() {
         @Override
         public Object visit(final BasicOperator basicOperator) {
           if (basicOperator.getUnionVariables() != null) {
             maxVariables.addAll(basicOperator.getUnionVariables());
           }
           return null;
         }
       });
   return maxVariables;
 }
  public void deleteAllAbove(
      final BasicOperator parent,
      final BasicOperator child,
      final Collection<BasicOperator> deleted) {
    parent.removeSucceedingOperator(child);
    if (!(parent instanceof PatternMatcher)) {

      // log parent as deleted operator
      deleted.add(parent);

      // in addition, log all operators (other than child) below parent, that became unrechable
      if (parent.getSucceedingOperators().size() > 0) {
        final OperatorIDTuple[] opIDTuples =
            parent.getSucceedingOperators().toArray(new OperatorIDTuple[0]);
        for (final OperatorIDTuple opIDTuple : opIDTuples) {
          logDeletedOperatorsBelow(opIDTuple.getOperator(), deleted);
        }
      }

      for (final BasicOperator parentparent : parent.getPrecedingOperators()) {
        deleteAllAbove(parentparent, parent, deleted);
      }
    }
  }
Example #23
0
  private static Map<Class<? extends BasicOperator>, Set<BasicOperator>> createStartNodeMap(
      final BasicOperator op) {
    final Map<Class<? extends BasicOperator>, Set<BasicOperator>> mapStartNodes =
        new HashMap<Class<? extends BasicOperator>, Set<BasicOperator>>();

    op.visit(
        new SimpleOperatorGraphVisitor() {

          public Object visit(final BasicOperator basicOperator) {
            RuleEngine.addToNodeMap(basicOperator, mapStartNodes);
            return null;
          }
        });

    return mapStartNodes;
  }
  @Override
  protected BasicOperator generateJoin(
      final InnerNodePlan inp,
      final Root root,
      final BasicOperator left,
      final BasicOperator right,
      final Collection<Variable> sortCriterium,
      final Map<TriplePattern, Map<Variable, VarBucket>> selectivity) {
    // left-deep-tree or right-deep-tree?
    if (left instanceof BasicIndexScan && right instanceof BasicIndexScan) {
      if (((BasicIndexScan) right).getTriplePattern().size() == 1
          || ((BasicIndexScan) left).getTriplePattern().size() == 1) {
        final Collection<TriplePattern> ctp;
        if (inp.getLeft().getCost() < inp.getRight().getCost()) {
          ctp = ((BasicIndexScan) left).getTriplePattern();
          ctp.addAll(((BasicIndexScan) right).getTriplePattern());
        } else {
          ctp = ((BasicIndexScan) right).getTriplePattern();
          ctp.addAll(((BasicIndexScan) left).getTriplePattern());
        }
        ((BasicIndexScan) left).setTriplePatterns(ctp);
        root.remove((BasicIndexScan) right);
        return left;
      }
    }
    Join join = new Join();
    join.setEstimatedCardinality(inp.getCardinality());

    // TODO check if necessary (or is it just necessary for RDF3X???)!

    if (!(inp.getLeft() instanceof InnerNodePlan
                && ((InnerNodePlan) inp.getLeft()).getJoinType() == JoinType.DEFAULT)
            && (inp.getRight() instanceof InnerNodePlan
                && ((InnerNodePlan) inp.getRight()).getJoinType() == JoinType.DEFAULT)
        || (inp.getLeft() instanceof LeafNodePlan && inp.getRight() instanceof InnerNodePlan)) {
      moveToLeft(inp.getRight().getTriplePatterns(), root);
    } else if (!(inp.getRight() instanceof InnerNodePlan
                && ((InnerNodePlan) inp.getRight()).getJoinType() == JoinType.DEFAULT)
            && (inp.getLeft() instanceof InnerNodePlan
                && ((InnerNodePlan) inp.getLeft()).getJoinType() == JoinType.DEFAULT)
        || (inp.getRight() instanceof LeafNodePlan && inp.getLeft() instanceof InnerNodePlan)) {
      moveToLeft(inp.getLeft().getTriplePatterns(), root);
    } else if (inp.getLeft().getCost() > inp.getRight().getCost()) {
      System.out.println(
          "Card. of joins with estimated lower cost vs. est. higher cost:"
              + inp.getRight().getCardinality()
              + "<->"
              + inp.getLeft().getCardinality());
      System.out.println(
          "Cost of joins with estimated lower cost vs. est. higher cost:"
              + inp.getRight().getCost()
              + "<->"
              + inp.getLeft().getCost());
      moveToLeft(inp.getRight().getTriplePatterns(), root);
    } else {
      System.out.println(
          "Card. of joins with estimated lower cost vs. est. higher cost:"
              + inp.getLeft().getCardinality()
              + "<->"
              + inp.getRight().getCardinality());
      System.out.println(
          "Cost of joins with estimated lower cost vs. est. higher cost:"
              + inp.getLeft().getCost()
              + "<->"
              + inp.getRight().getCost());
      moveToLeft(inp.getLeft().getTriplePatterns(), root);
    }

    join.setIntersectionVariables(inp.getJoinPartner());
    join.setUnionVariables(inp.getVariables());
    left.setSucceedingOperator(new OperatorIDTuple(join, 0));
    right.setSucceedingOperator(new OperatorIDTuple(join, 1));
    join.addPrecedingOperator(left);
    join.addPrecedingOperator(right);
    return join;
  }
Example #25
0
 public Object visit(final BasicOperator basicOperator) {
   if (basicOperator.equals(toFind)) flag = true;
   return null;
 }