private Record textLineToRecord()

in odps-sdk-impl/odps-udf-example/src/main/java/com/aliyun/odps/udf/example/text/TextExtractor.java [158:215]


  private Record textLineToRecord(String[] parts) throws IllegalArgumentException,IOException
  {
    if (this.outputColumns.length != 0){
      int index = 0;
      for(int i = 0; i < parts.length; i++){
        // only parse data in columns indexed by output indexes
        if (index < outputIndexes.length && i == outputIndexes[index]){
          // TODO: make NULL representation configurable
          if (parts[i].equals("NULL")) {
            record.set(index, null);
            index++;
            continue;
          }
          switch (this.outputTypes[index]) {
            case STRING:
              record.set(index,parts[i]);
              break;
            case BIGINT:
              record.setBigint(index,Long.parseLong(parts[i]));
              break;
            case BOOLEAN:
              record.setBoolean(index, Boolean.parseBoolean(parts[i]));
              break;
            case DOUBLE:
              record.setDouble(index, Double.parseDouble(parts[i]));
              break;
            case FLOAT:
              record.setFloat(index, Float.parseFloat(parts[i]));
              break;
            case BINARY:
              record.setBinary(index, new Binary(parts[i].getBytes()));
              break;
            case DATETIME:
              record.setDate(index, Date.valueOf(parts[i]));
              break;
            case DECIMAL:
              record.setDecimal(index, new BigDecimal(parts[i]));
              break;
            case TINYINT:
            case INT:
            case SMALLINT:
              record.setInt(index, Integer.parseInt(parts[i]));
              break;
            // TODO: add support
            case CHAR:
            case VARCHAR:
            case ARRAY:
            case MAP:
            default:
              throw new IllegalArgumentException("Type " + this.outputTypes[index] + " not supported for now.");
          }
          // TODO: change to setWithNoValidation when becomes available
          index++;
        }
      }
    }
    return record;
  }