@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; count++; counts.put(word, count); collector.emit(new Values(word, count)); }
@Override public void execute(Tuple input, BasicOutputCollector collector) { String line = input.getString(0); String[] fields = line.split(seprator); try { pstmt = conn.prepareStatement(insertSql); for (int i = 0; i < fields.length; i++) { pstmt.setString(i + 1, fields[i]); } pstmt.executeUpdate(); } catch (SQLException e) { log.error("数据插入失败", e); throw new RuntimeException("数据插入失败", e); } collector.emit(new Values(line)); }
@Override public void execute(Tuple input, BasicOutputCollector collector) { collector.emit(input.getValues()); }