Search in sources :

Example 26 with JSONArray

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);
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray)

Example 27 with JSONArray

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray)

Example 28 with JSONArray

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();
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ImmutableList(com.google_voltpatches.common.collect.ImmutableList) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException)

Example 29 with JSONArray

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray)

Example 30 with JSONArray

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;
}
Also used : JSONArray(org.json_voltpatches.JSONArray) ArrayList(java.util.ArrayList) ExpressionType(org.voltdb.types.ExpressionType)

Aggregations

JSONArray (org.json_voltpatches.JSONArray)44 JSONObject (org.json_voltpatches.JSONObject)29 JSONException (org.json_voltpatches.JSONException)13 File (java.io.File)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)4 JSONString (org.json_voltpatches.JSONString)4 ByteBuffer (java.nio.ByteBuffer)3 HashSet (java.util.HashSet)3 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)2 InetSocketAddress (java.net.InetSocketAddress)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 ExecutionException (java.util.concurrent.ExecutionException)2 ZipFile (java.util.zip.ZipFile)2 HttpResponse (org.apache.http.HttpResponse)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 InstanceId (org.voltcore.utils.InstanceId)2 Configuration (org.voltdb.VoltDB.Configuration)2 ClientResponse (org.voltdb.client.ClientResponse)2