private Record getOdpsRecord( TableTunnel.UploadSession uploadSession, int idx, ColumnGenerator... extraCols) throws ParseException { Record record = uploadSession.newRecord(); record.setBigint("id", (long) idx); record.setString("msg", getMsgPrefix() + idx); int colNum = 0; for (ColumnGenerator generator : extraCols) { String field = forIdx(colNum++); String fieldValue = generator.getExportText(idx); switch (generator.getOdpsType()) { case STRING: record.setString(field, fieldValue); break; case BIGINT: record.setBigint(field, Long.parseLong(fieldValue)); break; case DATETIME: String dateFormat = generator.getDateFormat(); record.setDatetime(field, new SimpleDateFormat(dateFormat).parse(fieldValue)); break; case DOUBLE: record.setDouble(field, Double.parseDouble(fieldValue)); break; case DECIMAL: record.setDecimal(field, new BigDecimal(fieldValue)); break; default: throw new RuntimeException("Unknown column type: " + generator.getOdpsType()); } } return record; }
public void map(long recordNum, Record record, TaskContext context) throws IOException { String w = record.getString(0); word.setString(0, w); context.write(word, one); }