Search in sources :

Example 21 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class ElasticHashinator method toJSONString.

/**
     * Serializes the configuration into JSON, also updates the currently cached m_configJSON.
     * @return The JSONString of the current configuration.
     */
private String toJSONString() {
    JSONStringer js = new JSONStringer();
    try {
        js.object();
        for (Map.Entry<Integer, Integer> entry : m_tokensMap.get().entrySet()) {
            js.key(entry.getKey().toString()).value(entry.getValue());
        }
        js.endObject();
    } catch (JSONException e) {
        throw new RuntimeException("Failed to serialize Hashinator Configuration to JSON.", e);
    }
    return js.toString();
}
Also used : JSONException(org.json_voltpatches.JSONException) JSONStringer(org.json_voltpatches.JSONStringer) ImmutableSortedMap(com.google_voltpatches.common.collect.ImmutableSortedMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 22 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class TupleValueExpression method explain.

@Override
public String explain(String impliedTableName) {
    String tableName = (m_tableAlias != null) ? m_tableAlias : m_tableName;
    String columnName = m_columnName;
    if (columnName == null || columnName.equals("")) {
        columnName = "column#" + m_columnIndex;
    }
    if (m_verboseExplainForDebugging) {
        columnName += " (as JSON: ";
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            toJSONString(stringer);
            stringer.endObject();
            columnName += stringer.toString();
        } catch (Exception e) {
            columnName += "CORRUPTED beyond the ability to format? " + e;
            e.printStackTrace();
        }
        columnName += ")";
    }
    if (tableName == null) {
        if (m_tableIdx != 0) {
            assert (m_tableIdx == 1);
            // This is join inner table
            return "inner-table." + columnName;
        }
    } else if (!tableName.equals(impliedTableName)) {
        return tableName + "." + columnName;
    } else if (m_verboseExplainForDebugging) {
        // In verbose mode, always show an "implied' tableName that would normally be left off.
        return "{" + tableName + "}." + columnName;
    }
    return columnName;
}
Also used : JSONStringer(org.json_voltpatches.JSONStringer) JSONException(org.json_voltpatches.JSONException)

Example 23 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class AbstractExpression method toJSONString.

@Override
public String toJSONString() {
    JSONStringer stringer = new JSONStringer();
    try {
        stringer.object();
        toJSONString(stringer);
        stringer.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
    return stringer.toString();
}
Also used : JSONException(org.json_voltpatches.JSONException) JSONStringer(org.json_voltpatches.JSONStringer)

Example 24 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class VoltTable method toJSONString.

/**
     * Get a JSON representation of this table.
     * @return A string containing a JSON representation of this table.
     */
@Override
public String toJSONString() {
    JSONStringer js = new JSONStringer();
    try {
        js.object();
        // status code (1 byte)
        js.keySymbolValuePair(JSON_STATUS_KEY, getStatusCode());
        // column schema
        js.key(JSON_SCHEMA_KEY).array();
        for (int i = 0; i < getColumnCount(); i++) {
            js.object();
            js.keySymbolValuePair(JSON_NAME_KEY, getColumnName(i));
            js.keySymbolValuePair(JSON_TYPE_KEY, getColumnType(i).getValue());
            js.endObject();
        }
        js.endArray();
        // row data
        js.key(JSON_DATA_KEY).array();
        VoltTableRow row = cloneRow();
        row.resetRowPosition();
        while (row.advanceRow()) {
            js.array();
            for (int i = 0; i < getColumnCount(); i++) {
                row.putJSONRep(i, js);
            }
            js.endArray();
        }
        js.endArray();
        js.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        throw new RuntimeException("Failed to serialized a table to JSON.", e);
    }
    return js.toString();
}
Also used : JSONException(org.json_voltpatches.JSONException) JSONStringer(org.json_voltpatches.JSONStringer)

Example 25 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class AbstractPlanNode method toJSONString.

@Override
public String toJSONString() {
    JSONStringer stringer = new JSONStringer();
    try {
        stringer.object();
        toJSONString(stringer);
        stringer.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage(), e);
    }
    return stringer.toString();
}
Also used : JSONException(org.json_voltpatches.JSONException) JSONStringer(org.json_voltpatches.JSONStringer)

Aggregations

JSONStringer (org.json_voltpatches.JSONStringer)28 JSONException (org.json_voltpatches.JSONException)18 JSONObject (org.json_voltpatches.JSONObject)7 ExecutionException (java.util.concurrent.ExecutionException)6 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)6 IOException (java.io.IOException)5 Map (java.util.Map)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SocketException (java.net.SocketException)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 AbstractExpression (org.voltdb.expressions.AbstractExpression)2 SettingsException (org.voltdb.settings.SettingsException)2 ImmutableSortedMap (com.google_voltpatches.common.collect.ImmutableSortedMap)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1