Java Code Examples for backtype.storm.tuple.Fields#size()
The following examples show how to use
backtype.storm.tuple.Fields#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureGrouping.java From StormCV with Apache License 2.0 | 6 votes |
/** * Constructs a featureGrouping for the specified feature name. Features with this name will be routed * according the the fields specified. * @param featureName * @param grouping * @throws InstantiationException */ public FeatureGrouping(String featureName, Fields grouping) throws InstantiationException{ this.featureName = featureName; FeatureSerializer serializer = new FeatureSerializer(); Fields fields = serializer.getFields(); indexes = new ArrayList<Integer>(); for(String groupBy : grouping){ for(int i=0; i<fields.size(); i++){ if(groupBy.equals(fields.get(i))){ indexes.add(i); } if(fields.get(i).equals(FeatureSerializer.NAME)){ nameIndex = i; } } } if(nameIndex == -1)throw new InstantiationException("No index found for feature name: "+featureName); if(indexes.size() == 0) throw new InstantiationException("No field indexes found for provided grouping: "+grouping); }
Example 2
Source File: TridentTupleView.java From jstorm with Apache License 2.0 | 6 votes |
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<>(parent.getOutputFields()); Set<String> parentFieldsSet = new HashSet<>(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); }
Example 3
Source File: ModGrouping.java From StormCV with Apache License 2.0 | 6 votes |
/** * @param mod only tuples with sequenceNr % mod == 0 will be accepted * @param serializer the serializer used to interpret tuples provided * @param grouping the set of fields used to choose the taks * @throws InstantiationException */ @SuppressWarnings("rawtypes") public ModGrouping(int mod, CVParticleSerializer serializer, Fields grouping) throws InstantiationException{ this.mod = mod; Fields fields = serializer.getFields(); indexes = new ArrayList<Integer>(); for(String groupBy : grouping){ for(int i=0; i<fields.size(); i++){ if(groupBy.equals(fields.get(i))){ indexes.add(i); } if(fields.get(i).equals(CVParticleSerializer.SEQUENCENR)){ sequenceIndex = i; } } } if(sequenceIndex == -1) throw new InstantiationException("No index found for Field '"+CVParticleSerializer.SEQUENCENR+"'"); if(indexes.size() == 0) throw new InstantiationException("No field indexes found for provided grouping: "+grouping); }
Example 4
Source File: DelimitedRecordFormat.java From jstorm with Apache License 2.0 | 5 votes |
@Override public byte[] format(Tuple tuple) { StringBuilder sb = new StringBuilder(); Fields fields = this.fields == null ? tuple.getFields() : this.fields; int size = fields.size(); for(int i = 0; i < size; i++){ sb.append(tuple.getValueByField(fields.get(i))); if(i != size - 1){ sb.append(this.fieldDelimiter); } } sb.append(this.recordDelimiter); return sb.toString().getBytes(); }
Example 5
Source File: GroupedStream.java From jstorm with Apache License 2.0 | 5 votes |
@Override public IAggregatableStream partitionAggregate(Fields inputFields, Aggregator agg, Fields functionFields) { Aggregator groupedAgg = new GroupedAggregator(agg, _groupFields, inputFields, functionFields.size()); Fields allInFields = TridentUtils.fieldsUnion(_groupFields, inputFields); Fields allOutFields = TridentUtils.fieldsConcat(_groupFields, functionFields); Stream s = _stream.partitionAggregate(allInFields, groupedAgg, allOutFields); return new GroupedStream(s, _groupFields); }
Example 6
Source File: MapCombinerAggStateUpdater.java From jstorm with Apache License 2.0 | 5 votes |
public MapCombinerAggStateUpdater(CombinerAggregator agg, Fields groupFields, Fields inputFields) { _agg = agg; _groupFields = groupFields; _inputFields = inputFields; if (inputFields.size() != 1) { throw new IllegalArgumentException("Combiner aggs only take a single field as input. Got this instead: " + inputFields.toString()); } _factory = new ComboList.Factory(groupFields.size(), inputFields.size()); }
Example 7
Source File: ValuePointer.java From jstorm with Apache License 2.0 | 5 votes |
public static ValuePointer[] buildIndex(Fields fieldsOrder, Map<String, ValuePointer> pointers) { if(fieldsOrder.size()!=pointers.size()) { throw new IllegalArgumentException("Fields order must be same length as pointers map"); } ValuePointer[] ret = new ValuePointer[pointers.size()]; for(int i=0; i<fieldsOrder.size(); i++) { ret[i] = pointers.get(fieldsOrder.get(i)); } return ret; }
Example 8
Source File: TridentTupleView.java From jstorm with Apache License 2.0 | 5 votes |
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); }
Example 9
Source File: TridentTupleView.java From jstorm with Apache License 2.0 | 5 votes |
public FreshOutputFactory(Fields selfFields) { _fieldIndex = new HashMap<>(); 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); }
Example 10
Source File: KvStatefulBoltExecutor.java From jstorm with Apache License 2.0 | 5 votes |
private IKvState<K, V> getSpecifiedKeyRangeState(Tuple input, Fields fields) { Object key = null; if (fields.size() == 1) { key = input.getValueByField(fields.get(0)); } else { List<Object> fieldedValuesTobeHash = Lists.newArrayList(); for (String field : fields) { fieldedValuesTobeHash.add(input.getValueByField(field)); } key = fieldedValuesTobeHash; } return keyRangeState.getRangeStateByKey(key); }
Example 11
Source File: DelimitedRecordFormat.java From storm-hdfs with Apache License 2.0 | 5 votes |
@Override public byte[] format(Tuple tuple) { StringBuilder sb = new StringBuilder(); Fields fields = this.fields == null ? tuple.getFields() : this.fields; int size = fields.size(); for(int i = 0; i < size; i++){ sb.append(tuple.getValueByField(fields.get(i))); if(i != size - 1){ sb.append(this.fieldDelimiter); } } sb.append(this.recordDelimiter); return sb.toString().getBytes(); }
Example 12
Source File: TileGrouping.java From StormCV with Apache License 2.0 | 5 votes |
@Override public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { this.targetTasks = targetTasks; Fields tupleFields = context.getComponentOutputFields(stream); for(int i=0; i<tupleFields.size(); i++){ if(tupleFields.get(i).equals(CVParticleSerializer.STREAMID)){ streamIdIndex = i; }else if(tupleFields.get(i).equals(CVParticleSerializer.SEQUENCENR)){ sequenceNrIndex = i; } } }
Example 13
Source File: MetadataGrouping.java From StormCV with Apache License 2.0 | 5 votes |
public MetadataGrouping(String[] keysToHash) throws InstantiationException{ this.keysToHash = keysToHash; this.hashmod = true; Fields fields = new FrameSerializer().getFields(); for(int i=0; i<fields.size(); i++){ if(fields.get(i).equals(CVParticleSerializer.METADATA)){ mdIndex = i; break; } } if(mdIndex == -1) throw new InstantiationException("Unable to find "+CVParticleSerializer.METADATA+ " field in CVParticle tuple representation!"); }
Example 14
Source File: MetadataGrouping.java From StormCV with Apache License 2.0 | 5 votes |
public MetadataGrouping(Map<String, Object[]> accept, boolean hashmod) throws InstantiationException{ this.accept = accept; this.hashmod = hashmod; Fields fields = new FrameSerializer().getFields(); for(int i=0; i<fields.size(); i++){ if(fields.get(i).equals(CVParticleSerializer.METADATA)){ mdIndex = i; break; } } if(mdIndex == -1) throw new InstantiationException("Unable to find "+CVParticleSerializer.METADATA+ " field in CVParticle tuple representation!"); }
Example 15
Source File: FeatureGrouping.java From StormCV with Apache License 2.0 | 5 votes |
/** * Constructs a featureGrouping for the specified feature name. Features with this name will be routed * randomly. * @param featureName * @throws InstantiationException */ public FeatureGrouping(String featureName) throws InstantiationException{ this.featureName = featureName; FeatureSerializer serializer = new FeatureSerializer(); Fields fields = serializer.getFields(); indexes = new ArrayList<Integer>(); for(int i=0; i<fields.size(); i++){ if(fields.get(i).equals(FeatureSerializer.NAME)){ nameIndex = i; } } if(nameIndex == -1)throw new InstantiationException("No index found for feature name: "+featureName); }
Example 16
Source File: ModGrouping.java From StormCV with Apache License 2.0 | 5 votes |
/** * @param mod only tuples with sequenceNr % mod == 0 will be accepted * @param serializer the serializer used to interpret tuples provided * @throws InstantiationException */ @SuppressWarnings("rawtypes") public ModGrouping(int mod, CVParticleSerializer serializer) throws InstantiationException{ this.mod = mod; Fields fields = serializer.getFields(); for(int i=0; i<fields.size(); i++){ if(fields.get(i).equals(CVParticleSerializer.SEQUENCENR)){ sequenceIndex = i; } } if(sequenceIndex == -1) throw new InstantiationException("No index found for Field '"+CVParticleSerializer.SEQUENCENR+"'"); }
Example 17
Source File: RandomNumberLimitBatchSpout.java From jstorm with Apache License 2.0 | 4 votes |
public RandomNumberLimitBatchSpout(long limit, Fields fields, int maxBatchSize, int maxNumber) { super(limit, fields, maxBatchSize); this.maxNumber = maxNumber; this.fieldSize = fields.size(); }
Example 18
Source File: MapReducerAggStateUpdater.java From jstorm with Apache License 2.0 | 4 votes |
public MapReducerAggStateUpdater(ReducerAggregator agg, Fields groupFields, Fields inputFields) { _agg = agg; _groupFields = groupFields; _inputFields = inputFields; _factory = new ComboList.Factory(groupFields.size(), 1); }