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); }
@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"); } }
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); }
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 + ">"); } } }
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); }
public Stream partitionBy(Fields fields) { projectionValidation(fields); return partition(Grouping.fields(fields.toList())); }
public StaticTuple(Fields fields, Values values) { assert (fields.size() == values.size()); this.fields = fields; this.values = values; }