Esempio n. 1
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);
    }
  }
Esempio n. 2
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);
      }
    }
  }
Esempio n. 3
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;
  }
  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} */
  @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;
  }
  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;
  }