Esempio n. 1
0
    public OperationOutputFactory(Factory parent, Fields selfFields) {
      _parent = parent;
      _fieldIndex = new HashMap(parent.getFieldIndex());
      int myIndex = parent.numDelegates();
      for (int i = 0; i < selfFields.size(); i++) {
        String field = selfFields.get(i);
        _fieldIndex.put(field, new ValuePointer(myIndex, i, field));
      }
      List<String> myOrder = new ArrayList<String>(parent.getOutputFields());

      Set<String> parentFieldsSet = new HashSet<String>(myOrder);
      for (String f : selfFields) {
        if (parentFieldsSet.contains(f)) {
          throw new IllegalArgumentException(
              "Additive operations cannot add fields with same name as already exists. "
                  + "Tried adding "
                  + selfFields
                  + " to "
                  + parent.getOutputFields());
        }
        myOrder.add(f);
      }

      _index = ValuePointer.buildIndex(new Fields(myOrder), _fieldIndex);
    }
Esempio n. 2
0
  @Override
  public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
    _fieldLocations = new HashMap<String, GlobalStreamId>();
    _collector = collector;
    int timeout = ((Number) conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS)).intValue();
    _pending =
        new TimeCacheMap<List<Object>, Map<GlobalStreamId, Tuple>>(timeout, new ExpireCallback());
    _numSources = context.getThisSources().size();
    Set<String> idFields = null;
    for (GlobalStreamId source : context.getThisSources().keySet()) {
      Fields fields =
          context.getComponentOutputFields(source.get_componentId(), source.get_streamId());
      Set<String> setFields = new HashSet<String>(fields.toList());
      if (idFields == null) idFields = setFields;
      else idFields.retainAll(setFields);

      for (String outfield : _outFields) {
        for (String sourcefield : fields) {
          if (outfield.equals(sourcefield)) {
            _fieldLocations.put(outfield, source);
          }
        }
      }
    }
    _idFields = new Fields(new ArrayList<String>(idFields));

    if (_fieldLocations.size() != _outFields.size()) {
      throw new RuntimeException("Cannot find all outfields among sources");
    }
  }
Esempio n. 3
0
 public FreshOutputFactory(Fields selfFields) {
   _fieldIndex = new HashMap<String, ValuePointer>();
   for (int i = 0; i < selfFields.size(); i++) {
     String field = selfFields.get(i);
     _fieldIndex.put(field, new ValuePointer(0, i, field));
   }
   _index = ValuePointer.buildIndex(selfFields, _fieldIndex);
 }
  /** This one is for the spout */
  @SuppressWarnings("unchecked")
  public static Fields registerMetaParticleFieldsFromMetaParticleClass(
      Config conf, Class<? extends MetaParticle> metaParticleClass) {
    Fields metaParticleFields = null;
    if (conf.containsKey(METADATA_FIELDS)) {
      metaParticleFields = new Fields((List<String>) conf.get(METADATA_FIELDS));
    }
    Fields fields =
        ParticleMapper.mergeFields(metaParticleFields, ParticleMapper.getFields(metaParticleClass));
    conf.put(METADATA_FIELDS, fields.toList());

    return fields;
  }
  public void execute(Tuple tuple) {

    Fields fields = tuple.getFields();
    int numFields = fields.size();
    System.out.println("numer of fields: " + numFields + " \n");

    for (int idx = 0; idx < numFields; idx++) {
      String name = fields.get(idx);
      Object value = tuple.getValue(idx);
      System.out.println("Field name: " + name + ", Field value: " + value + " \n");
    }

    collector.ack(tuple);
  }
Esempio n. 6
0
  private void projectionValidation(Fields projFields) {
    if (projFields == null) {
      return;
    }

    Fields allFields = this.getOutputFields();
    for (String field : projFields) {
      if (!allFields.contains(field)) {
        throw new IllegalArgumentException(
            "Trying to select non-existent field: '"
                + field
                + "' from stream containing fields fields: <"
                + allFields
                + ">");
      }
    }
  }
Esempio n. 7
0
 public RootFactory(Fields inputFields) {
   index = new ValuePointer[inputFields.size()];
   int i = 0;
   for (String f : inputFields) {
     index[i] = new ValuePointer(0, i, f);
     i++;
   }
   fieldIndex = ValuePointer.buildFieldIndex(index);
 }
Esempio n. 8
0
 public Stream partitionBy(Fields fields) {
   projectionValidation(fields);
   return partition(Grouping.fields(fields.toList()));
 }
Esempio n. 9
0
  public StaticTuple(Fields fields, Values values) {
    assert (fields.size() == values.size());

    this.fields = fields;
    this.values = values;
  }