use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class HBaseState method batchRetrieve.
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
List<List<Values>> batchRetrieveResult = Lists.newArrayList();
List<Get> gets = Lists.newArrayList();
for (TridentTuple tuple : tridentTuples) {
byte[] rowKey = options.mapper.rowKey(tuple);
gets.add(hBaseClient.constructGetRequests(rowKey, options.projectionCriteria));
}
try {
Result[] results = hBaseClient.batchGet(gets);
for (int i = 0; i < results.length; i++) {
Result result = results[i];
TridentTuple tuple = tridentTuples.get(i);
List<Values> values = options.rowToStormValueMapper.toValues(tuple, result);
batchRetrieveResult.add(values);
}
} catch (Exception e) {
LOG.warn("Batch get operation failed. Triggering replay.", e);
throw new FailedException(e);
}
return batchRetrieveResult;
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class HdfsStateTest method createMockTridentTuples.
private List<TridentTuple> createMockTridentTuples(int count) {
TridentTuple tuple = mock(TridentTuple.class);
when(tuple.getValueByField(any(String.class))).thenReturn("data");
List<TridentTuple> tuples = new ArrayList<>();
for (int i = 0; i < count; i++) {
tuples.add(tuple);
}
return tuples;
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class MongoState method batchRetrieve.
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
List<List<Values>> batchRetrieveResult = Lists.newArrayList();
try {
for (TridentTuple tuple : tridentTuples) {
Bson filter = options.queryCreator.createFilter(tuple);
Document doc = mongoClient.find(filter);
List<Values> values = options.lookupMapper.toTuple(tuple, doc);
batchRetrieveResult.add(values);
}
} catch (Exception e) {
LOG.warn("Batch get operation failed. Triggering replay.", e);
throw new FailedException(e);
}
return batchRetrieveResult;
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class AbstractRedisStateQuerier method batchRetrieve.
/**
* {@inheritDoc}
*/
@Override
public List<List<Values>> batchRetrieve(T state, List<TridentTuple> inputs) {
List<List<Values>> values = Lists.newArrayList();
List<String> keys = Lists.newArrayList();
for (TridentTuple input : inputs) {
keys.add(lookupMapper.getKeyFromTuple(input));
}
List<String> redisVals = retrieveValuesFromRedis(state, keys);
for (int i = 0; i < redisVals.size(); i++) {
values.add(lookupMapper.toTuple(inputs.get(i), redisVals.get(i)));
}
return values;
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class AbstractRedisStateUpdater method updateState.
/**
* {@inheritDoc}
*/
@Override
public void updateState(T state, List<TridentTuple> inputs, TridentCollector collector) {
Map<String, String> keyToValue = new HashMap<String, String>();
for (TridentTuple input : inputs) {
String key = storeMapper.getKeyFromTuple(input);
String value = storeMapper.getValueFromTuple(input);
keyToValue.put(key, value);
}
updateStatesToRedis(state, keyToValue);
}
Aggregations