本文整理了Java中org.apache.storm.tuple.Tuple.getStringByField()
方法的一些代码示例,展示了Tuple.getStringByField()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.getStringByField()
方法的具体详情如下:
包路径:org.apache.storm.tuple.Tuple
类名称:Tuple
方法名:getStringByField
[英]Gets the String field with a specific name.
[中]获取具有特定名称的字符串字段。
代码示例来源:origin: apache/storm
@Override
public Writable value(Tuple tuple) {
if (this.value == null) {
this.value = new Text();
}
this.value.set(tuple.getStringByField(this.valueField));
return this.value;
}
}
代码示例来源:origin: apache/storm
@Override
public void execute(Tuple input) {
String wordName = input.getStringByField("word");
String countStr = input.getStringByField("count");
// print lookup result with low probability
if(RANDOM.nextInt(1000) > 995) {
int count = 0;
if (countStr != null) {
count = Integer.parseInt(countStr);
}
LOG.info("Count result - word : " + wordName + " / count : " + count);
}
collector.ack(input);
}
代码示例来源:origin: apache/storm
@Override
public void execute(Tuple input) {
String wordName = input.getStringByField("wordName");
String countStr = input.getStringByField("count");
// print lookup result with low probability
if(RANDOM.nextInt(1000) > 995) {
int count = 0;
if (countStr != null) {
count = Integer.parseInt(countStr);
}
LOG.info("Lookup result - word : " + wordName + " / count : " + count);
}
collector.ack(input);
}
代码示例来源:origin: apache/storm
@Override
public String getPartitionPath(Tuple tuple) {
return Path.SEPARATOR + tuple.getStringByField("city");
}
};
代码示例来源:origin: apache/storm
@Override
public String getTopic(Tuple tuple) {
if (tuple.contains(fieldName)) {
return tuple.getStringByField(fieldName);
} else {
LOG.warn("Field {} Not Found. Returning default topic {}", fieldName, defaultTopicName);
return defaultTopicName;
}
}
}
代码示例来源:origin: apache/storm
@Override
public List<String> mapPartitions(Tuple tuple) {
List<String> partitionList = new ArrayList<String>();
if (this.partitionFields != null) {
for (String field : this.partitionFields) {
partitionList.add(tuple.getStringByField(field));
}
}
if (this.timeFormat != null) {
partitionList.add(getPartitionsByTimeFormat());
}
return partitionList;
}
代码示例来源:origin: apache/storm
@Override
public List<String> mapPartitions(Tuple tuple) {
List<String> partitionList = new ArrayList<String>();
if (this.partitionFields != null) {
for (String field : this.partitionFields) {
partitionList.add(tuple.getStringByField(field));
}
}
if (this.timeFormat != null) {
partitionList.add(getPartitionsByTimeFormat());
}
return partitionList;
}
代码示例来源:origin: apache/storm
public void execute(Tuple input, BasicOutputCollector collector) {
String word = input.getStringByField("word");
int count;
if (wordCounter.containsKey(word)) {
count = wordCounter.get(word) + 1;
wordCounter.put(word, wordCounter.get(word) + 1);
} else {
count = 1;
}
wordCounter.put(word, count);
collector.emit(new Values(word, String.valueOf(count)));
}
代码示例来源:origin: apache/storm
public void execute(Tuple input, BasicOutputCollector collector) {
String word = input.getStringByField("word");
int count;
if (wordCounter.containsKey(word)) {
count = wordCounter.get(word) + 1;
wordCounter.put(word, wordCounter.get(word) + 1);
} else {
count = 1;
}
wordCounter.put(word, count);
collector.emit(new Values(word, String.valueOf(count)));
}
代码示例来源:origin: apache/storm
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
String word = input.getStringByField("str");
int count;
if (wordCounter.containsKey(word)) {
count = wordCounter.get(word) + 1;
} else {
count = 1;
}
wordCounter.put(word, count);
collector.emit(new Values(word, count));
}
代码示例来源:origin: apache/storm
@Override
protected int run(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
// example. spout1: generate random strings
// bolt1: get the first part of a string
// bolt2: output the tuple
// NOTE: Variable used in lambda expression should be final or effectively final
// (or it will cause compilation error),
// and variable type should implement the Serializable interface if it isn't primitive type
// (or it will cause not serializable exception).
Prefix prefix = new Prefix("Hello lambda:");
String suffix = ":so cool!";
int tag = 999;
builder.setSpout("spout1", () -> UUID.randomUUID().toString());
builder.setBolt("bolt1", (tuple, collector) -> {
String[] parts = tuple.getStringByField("lambda").split("\\-");
collector.emit(new Values(prefix + parts[0] + suffix, tag));
}, "strValue", "intValue").shuffleGrouping("spout1");
builder.setBolt("bolt2", tuple -> System.out.println(tuple)).shuffleGrouping("bolt1");
Config conf = new Config();
conf.setDebug(true);
conf.setNumWorkers(2);
return submit("lambda-demo", conf, builder);
}
}
代码示例来源:origin: apache/metron
@Override
public String getKey(Tuple tuple, JSONObject message) {
String key = null, guid = null;
try {
key = tuple.getStringByField("key");
guid = (String)message.get(Constants.GUID);
}
catch(Throwable t) {
//swallowing this just in case.
}
if(key != null) {
return key;
}
else if(guid != null) {
return guid;
}
else {
return UUID.randomUUID().toString();
}
}
代码示例来源:origin: apache/metron
/**
* Return the GUID from either the tuple or the message.
*
* @param tuple
* @param message
* @return
*/
public String getGUID(Tuple tuple, JSONObject message) {
String key = null, guid = null;
try {
key = tuple.getStringByField("key");
guid = (String)message.get(Constants.GUID);
}
catch(Throwable t) {
//swallowing this just in case.
}
if(key != null) {
return key;
}
else if(guid != null) {
return guid;
}
else {
return UUID.randomUUID().toString();
}
}
代码示例来源:origin: apache/metron
byte[] rowKey = Bytes.toBytes(tuple.getStringByField(tupleRowKeyField));
byte[] val;
try {
val = Bytes.toBytes(tuple.getStringByField(cq));
} catch (IllegalArgumentException ex) {
代码示例来源:origin: apache/metron
public Tuple toTuple(byte[] record) {
Tuple ret = mock(Tuple.class);
when(ret.getStringByField("topic")).thenReturn(sensorType);
when(ret.getBinary(eq(0))).thenReturn(record);
return ret;
}
}
代码示例来源:origin: apache/metron
String topic = tuple.getStringByField(FieldsConfiguration.TOPIC.getFieldName());
String sensorType = topicToSensorMap.get(topic);
try {
代码示例来源:origin: apache/metron
@Test
public void shouldThrowExceptionOnFailedExecute() {
when(messageGetStrategy.get(t1)).thenReturn("originalMessage".getBytes(StandardCharsets.UTF_8));
when(t1.getStringByField(FieldsConfiguration.TOPIC.getFieldName())).thenReturn("yafTopic");
代码示例来源:origin: apache/metron
@Test
public void shouldThrowExceptionOnFailedWrite() throws Exception {
when(messageGetStrategy.get(t1)).thenReturn("originalMessage".getBytes(StandardCharsets.UTF_8));
when(t1.getStringByField(FieldsConfiguration.TOPIC.getFieldName())).thenReturn("yafTopic");
MockParserRunner mockParserRunner = new MockParserRunner(new HashSet<String>() {{ add("yaf"); }});
ParserConfigurations parserConfigurations = new ParserConfigurations();
代码示例来源:origin: apache/metron
@Test
public void shouldExecuteOnError() throws Exception {
when(messageGetStrategy.get(t1)).thenReturn("originalMessage".getBytes(StandardCharsets.UTF_8));
when(t1.getStringByField(FieldsConfiguration.TOPIC.getFieldName())).thenReturn("yafTopic");
MockParserRunner mockParserRunner = new MockParserRunner(new HashSet<String>() {{
add("yaf");
代码示例来源:origin: apache/metron
/**
* This bolt consumes telemetry messages and determines if the message is needed
* by any of the profiles. The message is then routed to one or more downstream
* bolts that are responsible for building each profile
*
* <p>The outgoing tuples are timestamped so that Storm's window and event-time
* processing functionality can recognize the time of each message.
*
* <p>The timestamp that is attached to each outgoing tuple is what decides if
* the Profiler is operating on processing time or event time.
*
* @param input The tuple.
*/
@Override
public void execute(Tuple input) {
try {
LOG.debug("Received message; topic={}, partition={}, offset={}, kafkaTimestamp={}",
input.contains(TOPIC.getFieldName()) ? input.getStringByField(TOPIC.getFieldName()): "unknown",
input.contains(PARTITION.getFieldName()) ? input.getIntegerByField(PARTITION.getFieldName()): "unknown",
input.contains(OFFSET.getFieldName()) ? input.getLongByField(OFFSET.getFieldName()): "unknown",
input.contains(TIMESTAMP.getFieldName()) ? input.getLongByField(TIMESTAMP.getFieldName()): "unknown");
doExecute(input);
} catch (Throwable t) {
LOG.error("Unexpected error", t);
collector.reportError(t);
} finally {
collector.ack(input);
}
}
内容来源于网络,如有侵权,请联系作者删除!