Пример #1
0
 @Override
 public void readFields(DataInput in) throws IOException {
   // read head (rows, cols)
   _numRows = in.readInt();
   int numCols = in.readInt();
   // read columns (value type, data)
   _schema.clear();
   _coldata.clear();
   for (int j = 0; j < numCols; j++) {
     ValueType vt = ValueType.values()[in.readByte()];
     String name = in.readUTF();
     Array arr = null;
     switch (vt) {
       case STRING:
         arr = new StringArray(new String[_numRows]);
         break;
       case BOOLEAN:
         arr = new BooleanArray(new boolean[_numRows]);
         break;
       case INT:
         arr = new LongArray(new long[_numRows]);
         break;
       case DOUBLE:
         arr = new DoubleArray(new double[_numRows]);
         break;
       default:
         throw new IOException("Unsupported value type: " + vt);
     }
     arr.readFields(in);
     _schema.add(vt);
     _colnames.add(name);
     _coldata.add(arr);
   }
 }
Пример #2
0
  /**
   * Returns the schema based on Json object
   *
   * @param schemaObject
   * @return
   */
  public static List<ValueType> getSchemaType(Object schemaObject) {
    JSONArray schemaJsonArr = (JSONArray) schemaObject;
    ValueType[] schemaArray = new ValueType[schemaJsonArr.size()];

    for (int i = 0; i < schemaJsonArr.length(); i++)
      schemaArray[i] = ValueType.valueOf((String) schemaJsonArr.get(0));
    return Arrays.asList(schemaArray);
  }