use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class SnapshotDaemon method retrievePerPartitionTransactionIds.
/*
* If this cluster has per partition transactions ids carried over from
* previous instances, retrieve them from ZK and pass them to snapshot save so that it can
* include them in the snapshot
*/
private JSONArray retrievePerPartitionTransactionIds() {
JSONArray retval = new JSONArray();
try {
ByteBuffer values = ByteBuffer.wrap(m_zk.getData(VoltZK.perPartitionTxnIds, false, null));
int numKeys = values.getInt();
for (int ii = 0; ii < numKeys; ii++) {
retval.put(values.getLong());
}
} catch (KeeperException.NoNodeException e) {
/*doesn't have to exist*/
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Failed to retrieve per partition transaction ids for snapshot", false, e);
}
return retval;
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class ParameterSet method paramFromPossibleJSON.
static Object paramFromPossibleJSON(Object value) throws JSONException, IOException {
if (value instanceof JSONObject) {
JSONObject jsonObj = (JSONObject) value;
return VoltTable.fromJSONObject(jsonObj);
}
if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
Object[] retval = new Object[array.length()];
for (int i = 0; i < array.length(); i++) {
Object valueAtIndex = array.get(i);
retval[i] = paramFromPossibleJSON(valueAtIndex);
}
return retval;
}
return value;
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class VoltTable method fromJSONObject.
/**
* <p>Construct a table from a JSON object. Only parses VoltDB VoltTable JSON format.</p>
*
* @param json String containing JSON-formatted table data.
* @return Constructed <code>VoltTable</code> instance.
* @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
if (row[j] != null) {
switch(type) {
case BIGINT:
case INTEGER:
case SMALLINT:
case TINYINT:
case TIMESTAMP:
if (row[j] instanceof String) {
row[j] = Long.parseLong((String) row[j]);
}
assert (row[j] instanceof Number);
break;
case DECIMAL:
String decVal;
if (row[j] instanceof String)
decVal = (String) row[j];
else
decVal = row[j].toString();
if (decVal.compareToIgnoreCase("NULL") == 0)
row[j] = null;
else
row[j] = VoltDecimalHelper.deserializeBigDecimalFromString(decVal);
break;
case FLOAT:
if (row[j] instanceof String) {
row[j] = Double.parseDouble((String) row[j]);
}
assert (row[j] instanceof Number);
break;
default:
}
}
}
t.addRow(row);
}
return t;
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class AbstractPlanNode method loadSchemaFromJSONObject.
protected static NodeSchema loadSchemaFromJSONObject(JSONObject jobj, String jsonKey) throws JSONException {
NodeSchema nodeSchema = new NodeSchema();
JSONArray jarray = jobj.getJSONArray(jsonKey);
int size = jarray.length();
for (int i = 0; i < size; ++i) {
nodeSchema.addColumn(SchemaColumn.fromJSONObject(jarray.getJSONObject(i)));
}
return nodeSchema;
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class AbstractPlanNode method loadIntArrayMemberFromJSON.
/**
* @param jobj
* @param key
* @return
* @throws JSONException
*/
int[] loadIntArrayMemberFromJSON(JSONObject jobj, String key) throws JSONException {
if (jobj.isNull(key)) {
return null;
}
JSONArray jarray = jobj.getJSONArray(key);
int numElems = jarray.length();
int[] result = new int[numElems];
for (int ii = 0; ii < numElems; ++ii) {
result[ii] = jarray.getInt(ii);
}
return result;
}
Aggregations