本文整理了Java中org.apache.storm.tuple.Tuple.size()
方法的一些代码示例,展示了Tuple.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.size()
方法的具体详情如下:
包路径:org.apache.storm.tuple.Tuple
类名称:Tuple
方法名:size
[英]Returns the number of fields in this tuple.
[中]返回此元组中的字段数。
代码示例来源:origin: apache/storm
private boolean isPair(Tuple input) {
return input.size() == (timestampField == null ? 2 : 3);
}
代码示例来源:origin: apache/storm
@Override
public String getTopic(Tuple tuple) {
if (fieldIndex < tuple.size()) {
return tuple.getString(fieldIndex);
} else {
LOG.warn("Field index {} is out of bounds. Using default topic {}", fieldIndex, defaultTopicName);
return defaultTopicName;
}
}
}
代码示例来源:origin: elastic/elasticsearch-hadoop
@Override
public void convert(Object from, BytesArray to) {
Assert.isTrue(from == null || from instanceof Tuple,
String.format("Unexpected object type, expecting [%s], given [%s]", Tuple.class, from.getClass()));
// handle common cases
Tuple tuple = (Tuple) from;
if (tuple == null || tuple.size() == 0) {
to.bytes("{}");
return;
}
Assert.isTrue(tuple.size() == 1, "When using JSON input, only one field is expected");
super.convert(tuple.getValue(0), to);
}
}
代码示例来源:origin: apache/storm
private void setUpMockTuples(Tuple... tuples) {
for (Tuple tuple : tuples) {
Mockito.when(tuple.size()).thenReturn(1);
Mockito.when(tuple.getValue(0)).thenReturn(100);
Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
}
}
代码示例来源:origin: apache/storm
private void setUpPunctuation(Tuple punctuation) {
Mockito.when(punctuation.size()).thenReturn(1);
Mockito.when(punctuation.getValue(0)).thenReturn(WindowNode.PUNCTUATION);
Mockito.when(punctuation.getSourceComponent()).thenReturn("bolt0");
Mockito.when(punctuation.getSourceStreamId()).thenReturn("inputstream");
}
}
代码示例来源:origin: apache/storm
private void setUpMockTuples(Tuple... tuples) {
for (Tuple tuple : tuples) {
Mockito.when(tuple.size()).thenReturn(1);
Mockito.when(tuple.getValue(0)).thenReturn(100);
Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
}
}
代码示例来源:origin: apache/storm
private void setUpMockTuples(Tuple... tuples) {
for (Tuple tuple : tuples) {
Mockito.when(tuple.size()).thenReturn(1);
Mockito.when(tuple.getValue(0)).thenReturn(Pair.of("k", "v"));
Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
}
}
}
代码示例来源:origin: org.apache.storm/storm-kafka-client
@Override
public String getTopic(Tuple tuple) {
if (fieldIndex < tuple.size()) {
return tuple.getString(fieldIndex);
} else {
LOG.warn("Field index {} is out of bounds. Using default topic {}", fieldIndex, defaultTopicName);
return defaultTopicName;
}
}
}
代码示例来源:origin: org.apache.storm/storm-kafka
@Override
public String getTopic(Tuple tuple) {
if (fieldIndex < tuple.size()) {
return tuple.getString(fieldIndex);
} else {
LOG.warn("Field Index " + fieldIndex + " Out of bound . Using default topic " + defaultTopicName);
return defaultTopicName;
}
}
}
代码示例来源:origin: stackoverflow.com
public class time extends EvalFunc<String>{
public String exec(Tuple input) throws IOException {
if ((input == null) || (input.size() == 0))
return null;
try{
String time = (String) input.get(0) ;
DateFormat df = new SimpleDateFormat("hh:mm:ss.000");
Date date = df.parse(time);
String timeOfDay = getTimeOfDay(date);
return timeOfDay;
} catch (ParseException e) {
//how will I handle when df.parse(time) fails and throws ParseException?
//maybe:
return null;
}
} //exec
} //class
代码示例来源:origin: com.yahoo.bullet/bullet-storm
private void updateLatency(Tuple tuple) {
if (metricsEnabled && tuple.size() > 1) {
// Could use named fields instead
Long timestamp = (Long) tuple.getValue(TopologyConstants.RECORD_TIMESTAMP_POSITION);
averageLatency.update(System.currentTimeMillis() - timestamp);
}
}
}
代码示例来源:origin: bullet-db/bullet-storm
private void updateLatency(Tuple tuple) {
if (metricsEnabled && tuple.size() > 1) {
// Could use named fields instead
Long timestamp = (Long) tuple.getValue(TopologyConstants.RECORD_TIMESTAMP_POSITION);
averageLatency.update(System.currentTimeMillis() - timestamp);
}
}
}
代码示例来源:origin: stackoverflow.com
import org.apache.pig.FilterFunc;
import java.io.IOException;
import org.apache.pig.data.Tuple;
public class FilterUDF extends FilterFunc {
public Boolean exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
int val1 = input.get(0) // gets val1 from pig
int val2 = input.get(1) // gets val2 from pig
/*rest of code*/
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch-hadoop
@Override
public void convert(Object from, BytesArray to) {
Assert.isTrue(from == null || from instanceof Tuple,
String.format("Unexpected object type, expecting [%s], given [%s]", Tuple.class, from.getClass()));
// handle common cases
Tuple tuple = (Tuple) from;
if (tuple == null || tuple.size() == 0) {
to.bytes("{}");
return;
}
Assert.isTrue(tuple.size() == 1, "When using JSON input, only one field is expected");
super.convert(tuple.getValue(0), to);
}
}
代码示例来源:origin: bullet-db/bullet-storm
private static Tuple pushInto(Tuple mocked, Object... contents) {
when(mocked.getValues()).thenReturn(Arrays.asList(contents));
when(mocked.size()).thenReturn(contents.length);
for (int i = 0; i < contents.length; ++i) {
when(mocked.getValue(i)).thenReturn(contents[i]);
when(mocked.getString(i)).thenReturn(Objects.toString(contents[i]));
}
return mocked;
}
内容来源于网络,如有侵权,请联系作者删除!