private static JSONArray getSelectionColumnsFromDataSchema(
     List<String> selectionColumns, DataSchema dataSchema) {
   final JSONArray jsonArray = new JSONArray();
   for (int idx = 0; idx < dataSchema.size(); ++idx) {
     if (selectionColumns.contains(dataSchema.getColumnName(idx))) {
       jsonArray.put(dataSchema.getColumnName(idx));
     }
   }
   return jsonArray;
 }
 public static List<String> getSelectionColumns(
     List<String> selectionColumns, DataSchema dataSchema) {
   if ((selectionColumns.size() == 1) && selectionColumns.get(0).equals("*")) {
     selectionColumns.clear();
     for (int i = 0; i < dataSchema.size(); ++i) {
       selectionColumns.add(dataSchema.getColumnName(i));
     }
   }
   return selectionColumns;
 }
  public static JSONArray getJSonArrayFromRow(
      Serializable[] poll, List<String> selectionColumns, DataSchema dataSchema)
      throws JSONException {

    final JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < dataSchema.size(); ++i) {
      if (selectionColumns.contains(dataSchema.getColumnName(i))) {
        if (dataSchema.getColumnType(i).isSingleValue()) {
          if (dataSchema.getColumnType(i) == DataType.STRING) {
            jsonArray.put(poll[i]);
          } else {
            jsonArray.put(
                DEFAULT_FORMAT_STRING_MAP.get(dataSchema.getColumnType(i)).format(poll[i]));
          }
        } else {
          // Multi-value;

          JSONArray stringJsonArray = new JSONArray();
          //          stringJsonArray.put(poll[i]);
          switch (dataSchema.getColumnType(i)) {
            case STRING_ARRAY:
              String[] stringValues = (String[]) poll[i];
              for (String s : stringValues) {
                stringJsonArray.put(s);
              }
              break;
            case INT_ARRAY:
              int[] intValues = (int[]) poll[i];
              for (int s : intValues) {
                stringJsonArray.put(
                    DEFAULT_FORMAT_STRING_MAP.get(dataSchema.getColumnType(i)).format(s));
              }
              break;
            case FLOAT_ARRAY:
              float[] floatValues = (float[]) poll[i];
              for (float s : floatValues) {
                stringJsonArray.put(
                    DEFAULT_FORMAT_STRING_MAP.get(dataSchema.getColumnType(i)).format(s));
              }
              break;
            case LONG_ARRAY:
              long[] longValues = (long[]) poll[i];
              for (long s : longValues) {
                stringJsonArray.put(
                    DEFAULT_FORMAT_STRING_MAP.get(dataSchema.getColumnType(i)).format(s));
              }
              break;
            case DOUBLE_ARRAY:
              double[] doubleValues = (double[]) poll[i];
              for (double s : doubleValues) {
                stringJsonArray.put(
                    DEFAULT_FORMAT_STRING_MAP.get(dataSchema.getColumnType(i)).format(s));
              }
              break;
            default:
              break;
          }
          jsonArray.put(stringJsonArray);
        }
      }
    }
    return jsonArray;
  }