Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 protected void createOdpsTable(
     String tableName, String[] partitionCols, ColumnGenerator... extraCols) throws OdpsException {
   TableSchema schema = new TableSchema();
   schema.addColumn(new Column("id", OdpsType.BIGINT));
   schema.addColumn(new Column("msg", OdpsType.STRING));
   int colNum = 0;
   for (ColumnGenerator generator : extraCols) {
     schema.addColumn(new Column(forIdx(colNum++), generator.getOdpsType()));
   }
   if (partitionCols != null) {
     for (String partition : partitionCols) {
       schema.addPartitionColumn(new Column(partition, OdpsType.STRING));
     }
   }
   odps.tables().create(tableName, schema);
 }