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();
}
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;
}
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();
}
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();
}
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();
}
Aggregations