* @throws JSONException on JSON-related error.
* @throws IOException if thrown by our JSON library.
*/
public static VoltTable fromJSONObject(JSONObject json) throws JSONException, IOException {
// extract the schema and creat an empty table
JSONArray jsonCols = json.getJSONArray(JSON_SCHEMA_KEY);
ColumnInfo[] columns = new ColumnInfo[jsonCols.length()];
for (int i = 0; i < jsonCols.length(); i++) {
JSONObject jsonCol = jsonCols.getJSONObject(i);
String name = jsonCol.getString(JSON_NAME_KEY);
VoltType type = VoltType.get((byte) jsonCol.getInt(JSON_TYPE_KEY));
columns[i] = new ColumnInfo(name, type);
}
VoltTable t = new VoltTable(columns);
// set the status byte
byte status = (byte) json.getInt(JSON_STATUS_KEY);
t.setStatusCode(status);
// load the row data
JSONArray data = json.getJSONArray(JSON_DATA_KEY);
for (int i = 0; i < data.length(); i++) {
JSONArray jsonRow = data.getJSONArray(i);
assert(jsonRow.length() == jsonCols.length());
Object[] row = new Object[jsonRow.length()];
for (int j = 0; j < jsonRow.length(); j++) {
row[j] = jsonRow.get(j);
if (row[j] == JSONObject.NULL)
row[j] = null;
VoltType type = columns[j].type;
// convert strings to numbers