use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class WindowFunctionPlanNode method loadFromJSONObject.
/**
* Deserialize a PartitionByPlanNode from JSON. Since we don't need the
* sort directions, and we don't serialize them in toJSONString, then we
* can't in general get them here.
*/
@Override
public void loadFromJSONObject(JSONObject jobj, Database db) throws JSONException {
helpLoadFromJSONObject(jobj, db);
JSONArray jarray = jobj.getJSONArray(Members.AGGREGATE_COLUMNS.name());
int size = jarray.length();
for (int i = 0; i < size; i++) {
// We only expect one of these for now.
assert (i == 0);
JSONObject tempObj = jarray.getJSONObject(i);
m_aggregateTypes.add(ExpressionType.get(tempObj.getString(Members.AGGREGATE_TYPE.name())));
m_aggregateOutputColumns.add(tempObj.getInt(Members.AGGREGATE_OUTPUT_COLUMN.name()));
m_aggregateExpressions.add(AbstractExpression.loadFromJSONArrayChild(null, tempObj, Members.AGGREGATE_EXPRESSIONS.name(), null));
}
m_partitionByExpressions = AbstractExpression.loadFromJSONArrayChild(null, jobj, Members.PARTITIONBY_EXPRESSIONS.name(), null);
m_orderByExpressions = new ArrayList<>();
AbstractExpression.loadSortListFromJSONArray(m_orderByExpressions, null, jobj);
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class HTTPUtils method responseFromJSON.
public static Response responseFromJSON(String jsonStr) throws JSONException, IOException {
Response response = new Response();
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray resultsJson = jsonObj.getJSONArray("results");
response.results = new VoltTable[resultsJson.length()];
for (int i = 0; i < response.results.length; i++) {
JSONObject tableJson = resultsJson.getJSONObject(i);
response.results[i] = VoltTable.fromJSONObject(tableJson);
System.out.println(response.results[i].toString());
}
if (jsonObj.isNull("status") == false) {
response.status = (byte) jsonObj.getInt("status");
}
if (jsonObj.isNull("appstatus") == false) {
response.appStatus = (byte) jsonObj.getInt("appstatus");
}
if (jsonObj.isNull("statusstring") == false) {
response.statusString = jsonObj.getString("statusstring");
}
if (jsonObj.isNull("appstatusstring") == false) {
response.appStatusString = jsonObj.getString("appstatusstring");
}
if (jsonObj.isNull("exception") == false) {
response.exception = jsonObj.getString("exception");
}
return response;
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class StreamSnapshotRequestConfig method parseStreams.
private ImmutableList<Stream> parseStreams(JSONObject jsData) {
ImmutableList.Builder<Stream> builder = ImmutableList.builder();
try {
JSONArray streamArray = jsData.getJSONArray("streams");
for (int i = 0; i < streamArray.length(); i++) {
JSONObject streamObj = streamArray.getJSONObject(i);
Integer newPartition = null;
if (!streamObj.isNull("newPartition")) {
newPartition = Integer.parseInt(streamObj.getString("newPartition"));
}
Stream config = new Stream(parseStreamPairs(streamObj), newPartition);
builder.add(config);
}
} catch (JSONException e) {
SNAP_LOG.warn("Failed to parse stream snapshot request config", e);
}
return builder.build();
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class DRConsumerDrIdTracker method toJSON.
public JSONObject toJSON() throws JSONException {
JSONObject obj = new JSONObject();
obj.put("spUniqueId", m_lastSpUniqueId);
obj.put("mpUniqueId", m_lastMpUniqueId);
obj.put("producerPartitionId", m_producerPartitionId);
JSONArray drIdRanges = new JSONArray();
for (Range<Long> sequenceRange : m_map.asRanges()) {
JSONObject range = new JSONObject();
range.put(Long.toString(start(sequenceRange)), end(sequenceRange));
drIdRanges.put(range);
}
obj.put("drIdRanges", drIdRanges);
return obj;
}
use of org.json_voltpatches.JSONArray in project voltdb by VoltDB.
the class AbstractExpression method fromJSONObject.
private static AbstractExpression fromJSONObject(JSONObject obj, StmtTableScan tableScan) throws JSONException {
ExpressionType type = ExpressionType.get(obj.getInt(Members.TYPE));
AbstractExpression expr;
try {
expr = type.getExpressionClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
}
expr.m_type = type;
expr.m_valueType = VoltType.get((byte) obj.getInt(Members.VALUE_TYPE));
if (obj.has(Members.VALUE_SIZE)) {
expr.m_valueSize = obj.getInt(Members.VALUE_SIZE);
} else {
expr.m_valueSize = expr.m_valueType.getLengthInBytesForFixedTypes();
}
expr.m_left = fromJSONChild(obj, Members.LEFT, tableScan);
expr.m_right = fromJSONChild(obj, Members.RIGHT, tableScan);
if (!obj.isNull(Members.ARGS)) {
JSONArray jarray = obj.getJSONArray(Members.ARGS);
ArrayList<AbstractExpression> arguments = new ArrayList<>();
loadFromJSONArray(arguments, jarray, tableScan);
expr.setArgs(arguments);
}
expr.loadFromJSONObject(obj, tableScan);
return expr;
}
Aggregations