Package lupos.engine.operators

Examples of lupos.engine.operators.BasicOperator


        jointree.remove(second);
        jointree.remove(first);
      }
     
      // join the determined subgraphs and put the join back into jointree!
      BasicOperator firstOperand = firstSubGraph.getFirst();
      BasicOperator secondOperand = secondSubGraph.getFirst();
     
      Join join = new Join();
     
      HashSet<Variable> joinUnion = new HashSet<Variable>(firstOperand.getUnionVariables());
      joinUnion.addAll(secondOperand.getUnionVariables());
      join.setUnionVariables(joinUnion);
     
      HashSet<Variable> joinIntersection = new HashSet<Variable>(firstOperand.getUnionVariables());
      joinIntersection.retainAll(secondOperand.getUnionVariables());
      join.setIntersectionVariables(joinIntersection);
           
      firstOperand.addSucceedingOperator(join, 0);
      secondOperand.addSucceedingOperator(join, 1);
     
      jointree.add(new Tuple<BasicOperator, T>(join, mergeInitialInformations(firstSubGraph.getSecond(), secondSubGraph.getSecond())));     
    }
   
    BasicOperator op = jointree.get(0).getFirst();
    op.setSucceedingOperators(indexScan.getSucceedingOperators());
  }
View Full Code Here


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

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

    repVar_new.setPrecedingOperators(pres);
    repVar_new.setSucceedingOperator(new OperatorIDTuple(repLit_new, 0));

    repLit_new.setPrecedingOperator(repVar_new);
    repLit_new.setSucceedingOperators(succs);

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

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
View Full Code Here

  @Override
  public void rearrangeJoinOrder(final Root newRoot, final BasicIndexScan indexScan) {
    final Triple<List<LeafNodePlan>, HashMap<Variable, Literal>, HashMap<Variable, Literal>> initialInfo = this.getInitialPlansAndMinimaAndMaxima(indexScan.getTriplePattern(), indexScan);
    final Plan plan = this.getPlan(initialInfo.getFirst());
    final BasicOperator op = this.operatorGraphGenerator.generateOperatorGraph(plan, newRoot, indexScan, new LinkedList<Variable>(), initialInfo.getSecond(), initialInfo.getThird(), new HashMap<TriplePattern, Map<Variable, VarBucket>>());
    op.setSucceedingOperators(indexScan.getSucceedingOperators());
  }
View Full Code Here

    }
    while (remainingJoins.size() > 1) {
      // choose best combination
      final Collection<BasicOperator> co = this.getNextJoin(remainingJoins);
      final Iterator<BasicOperator> io = co.iterator();
      final BasicOperator first = io.next();
      final BasicOperator second = io.next();
      final Join join = new Join();
      join.setIntersectionVariables(new HashSet<Variable>());
      join.setUnionVariables(new HashSet<Variable>());
      join.getUnionVariables().addAll(first.getUnionVariables());
      join.getUnionVariables().addAll(second.getUnionVariables());
      first.setSucceedingOperator(new OperatorIDTuple(join, 0));
      second.setSucceedingOperator(new OperatorIDTuple(join, 1));
      remainingJoins.remove(first);
      remainingJoins.remove(second);
      remainingJoins.add(join);
    }
    remainingJoins.iterator().next().setSucceedingOperators(
View Full Code Here

    //Logger.getLogger(getClass()).debug("serializeNode: " + node + " with id: " + parent_id);
    this.id_counter++;

    final int edge_id = node.getId();

    final BasicOperator op = node.getOperator();
    boolean newEntry = false;
   
    /*
     * store all Operators in our new map!
     */
    if (!map.containsKey(op)) {
      map.put(op, id_counter);
      /*
       * this is a new entry! (so no re-visit node, that is just serialized)
       */
      newEntry = true;
    }

    /*
     * for our forward-connections in the operator graph (we stored an edge to  a not known node, that is
     * now added, so we know its new id and can serialize the edge!)
     */
    if (addLater.containsKey(op)) {
      /*
       * an object is now serialized, that is used before! now we know its
       * id, so we can add the edge from (op_id) to (already stored
       * succeeding id)
       */
      Tuple<Integer,Integer> data = addLater.get(op);
      JSONObject edge = new JSONObject();
      try {
        edge.put("from", id_counter);
        edge.put("to", data.getFirst());
        edge.put("edge_id", data.getSecond());
        addEdgeTo(edgesJSON, edge);
      } catch (Exception e) {
        propagate(e);
      }
    }
    if (parent_id > 0) {
      final JSONObject edge = new JSONObject();
      try {
        int counterID = this.id_counter;
        if (map.containsKey(op)) {
          /*
           * get the node id of the operator
           */
          counterID = map.get(op);
          if (op.getPrecedingOperators().size() == 0) {
            //if there is no preceding, it should be the root (node_id = 1)
            edge.put("from", 1);
            edge.put("to", counterID);
            edge.put("edge_id", edge_id);
            addEdgeTo(edgesJSON, edge);
          } else {
            //otherwise create edges to the current operator by
            //its preceding operators
            for (BasicOperator is : op.getPrecedingOperators()) {
              /*
               * if the preceding is already known (an node_is is set),
               * add the edge, otherwise store the information
               * to be added, if the not known operator is stored!
               */
              if (map.containsKey(is)) {
                edge.put("from", map.get(is));
                edge.put("to", counterID);
                edge.put("edge_id", edge_id);
                addEdgeTo(edgesJSON, edge);
              } else {
                /*
                 * we found an operator that is still not known! but we have
                 * to store the edge to the future serialized node!
                 */
                int tmpEdge_id = is.getOperatorIDTuple(op).getId();
                addLater.put(is, new Tuple<Integer,Integer>(counterID,tmpEdge_id));
              }
            }
          }

        }
      } catch (final JSONException e) {
        e.printStackTrace();
      }
    }

    OperatorFormatter serializer;
    if (op instanceof BasicIndexScan) {
      serializer = new IndexScanFormatter();
    } else if (op instanceof Root) {
      serializer = new RootFormatter();
    } else if (op instanceof Result) {
      serializer = new ResultFormatter();
    } else if (op instanceof Filter) {
      serializer = new FilterFormatter();
    } else if (op instanceof Join) {
      /*
       * added the Join formatter for joins in subgraph-containers
       */
      serializer = new JoinFormatter();
    } else if (op instanceof SubgraphContainer) {
      /*
       * added the formatter for an included subgraph in the subgraph
       */
      serializer = new SubSubgraphContainerFormatter();
    } else {
      throw new RuntimeException("Something is wrong here. Forgot case?");
    }

    try {
      /*
       * only add new entry, because otherwise we serialize an node twice ;(
       */
      if (newEntry) {
        nodesJSON.add(serializer.serialize(op, this.id_counter));
      }
    } catch (final NullPointerException e) {
      throw new IllegalArgumentException(
          "This operator is not serializable", e);
    } catch (final JSONException e) {
      throw propagate(e);
    }

    for (final OperatorIDTuple successor : op.getSucceedingOperators()) {
      this.serializeNode(successor, nodesJSON, edgesJSON, this.id_counter);
    }
  }
View Full Code Here

  }

  private Collection<BasicOperator> getNextJoin(
      final Collection<BasicOperator> remainingJoins) {
    final Collection<BasicOperator> co = new LinkedList<BasicOperator>();
    BasicOperator best1 = null;
    BasicOperator best2 = null;
    int minCommonVariables = -1;
    for (final BasicOperator o1 : remainingJoins) {
      for (final BasicOperator o2 : remainingJoins) {
        if (!o1.equals(o2)) {
          final Collection<Variable> v = o1.getUnionVariables();
View Full Code Here

    for (int i = 0; i < edgesJson.length(); i++) {

      final JSONObject edgeJson = edgesJson.getJSONObject(i);

      final BasicOperator from = nodes.get(edgeJson.getInt("from"));
      final BasicOperator to = nodes.get(edgeJson.getInt("to"));

      if (succeedingOperators.get(from) == null) {
        succeedingOperators
            .put(from, new LinkedList<OperatorIDTuple>());
      }

      if (precedingOperators.get(to) == null) {
        precedingOperators.put(to, new LinkedList<BasicOperator>());
      }

      succeedingOperators.get(from).add(
          new OperatorIDTuple(to, edgeJson.getInt("edge_id")));
      precedingOperators.get(to).add(from);
    }

    for (final Entry<BasicOperator, List<OperatorIDTuple>> from : succeedingOperators
        .entrySet()) {
      from.getKey().setSucceedingOperators(from.getValue());
    }

    for (final Entry<BasicOperator, List<BasicOperator>> to : precedingOperators
        .entrySet()) {
      to.getKey().setPrecedingOperators(to.getValue());
    }
  }
View Full Code Here

      final OperatorFormatter formatter = formatters.get(nodeJson
          .getString("type"));

      // add deserialized node to list
     
      final BasicOperator node = formatter.deserialize(nodeJson);
      nodes.put(nodeJson.getInt("node_id"), node);

      if (node instanceof Root) {
        final IndexScanFormatter indexScanFormatter = (IndexScanFormatter) formatters
            .get(BasicIndexScan.class.getName());
View Full Code Here

  @Override
  protected void init() {
    final TriplePattern pat1 = new TriplePattern();
    final ReplaceLit repLit = new ReplaceLit();
    final TriplePattern pat2 = new TriplePattern();
    final BasicOperator succ = new BasicOperator();

    pat1.setSucceedingOperator(new OperatorIDTuple(repLit, 0));

    repLit.setPrecedingOperator(pat1);
    repLit.setSucceedingOperator(new OperatorIDTuple(succ, -1));

    pat2.addSucceedingOperator(new OperatorIDTuple(succ, -1));

    succ.setPrecedingOperator(repLit);
    succ.addPrecedingOperator(pat2);

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(pat1, "pat1");
    subGraphMap.put(repLit, "repLit");
    subGraphMap.put(pat2, "pat2");
View Full Code Here

    pat2.setSucceedingOperator(new OperatorIDTuple(genAdd, 0));

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

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

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
View Full Code Here

TOP

Related Classes of lupos.engine.operators.BasicOperator

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.