如何为结果创建新字段?
我正在使用wordcount作业,我想附加一个时间戳。目前它包含字段'word'和'count'。
我的目标是创建一个如下所示的元组: 'word''count''timestamp'
到目前为止,这是我的代码。我尝试将时间戳附加到名为“TimestampAppender”
的自定义函数中wcPipe = new Each(wcPipe, Fields.ALL, new TimestampAppender(Fields.ALL), Fields.RESULTS);
TimestampAppender:
public class TimestampAppender extends BaseOperation implements Function {
public TimestampAppender(Fields fieldDeclaration) {
super(2, fieldDeclaration);
}
public void operate(FlowProcess flowProcess, FunctionCall functionCall) {
TupleEntry argument = functionCall.getArguments();
String arg0 = argument.getString(0);
String arg1 = argument.getString(1);
Tuple result = new Tuple();
result.addString(arg0);
result.addString(arg1);
result.addString("01-01-2015");
functionCall.getOutputCollector().add(result);
}
答案 0 :(得分:1)
您可以将代码更改为:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link type="text/css" rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<div class="title">Column 1</div>
<div id="sortable1" class="connectedSortable">
<div class="ui-state-default">Item 1</div>
<div class="ui-state-default">Item 2</div>
<div class="ui-state-default">Item 3</div>
<div class="ui-state-default">Item 4</div>
<div class="ui-state-default">Item 5</div>
<div class="ui-state-default">Item 6</div>
<div class="ui-state-default">Item 7</div>
<div class="ui-state-default">Item 8</div>
<div class="ui-state-default">Item 9</div>
<div class="ui-state-default">Item 10</div>
</div>
<div class="title">Column 2</div>
<div id="sortable2" class="connectedSortable">
<div class="ui-state-highlight">Item A</div>
<div class="ui-state-highlight">Item B</div>
<div class="ui-state-highlight">Item C</div>
<div class="ui-state-highlight">Item D</div>
<div class="ui-state-highlight">Item E</div>
<div class="ui-state-highlight">Item F</div>
<div class="ui-state-highlight">Item G</div>
<div class="ui-state-highlight">Item H</div>
<div class="ui-state-highlight">Item I</div>
<div class="ui-state-highlight">Item J</div>
<div class="ui-state-highlight">Item K</div>
<div class="ui-state-highlight">Item L</div>
<div class="ui-state-highlight">Item M</div>
<div class="ui-state-highlight">Item N</div>
<div class="ui-state-highlight">Item O</div>
<div class="ui-state-highlight">Item P</div>
<div class="ui-state-highlight">Item Q</div>
<div class="ui-state-highlight">Item R</div>
<div class="ui-state-highlight">Item S</div>
<div class="ui-state-highlight">Item T</div>
<div class="ui-state-highlight">Item U</div>
<div class="ui-state-highlight">Item V</div>
<div class="ui-state-highlight">Item W</div>
<div class="ui-state-highlight">Item X</div>
<div class="ui-state-highlight">Item Y</div>
<div class="ui-state-highlight">Item Z</div>
</div>
<强> TimestampAppender:强>
wcPipe = new Each(wcPipe, new Insert(new Fields("timestamp"), ""), Fields.ALL);
wcPipe = new Each(wcPipe, Fields.ALL, new TimestampAppender(Fields.ALL), Fields.RESULTS);