use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class MiscUtils method formatHostMetadataFromJSON.
public static String formatHostMetadataFromJSON(String json) {
try {
JSONObject obj = new JSONObject(json);
StringBuilder sb = new StringBuilder();
JSONArray interfaces = (JSONArray) obj.get("interfaces");
for (int ii = 0; ii < interfaces.length(); ii++) {
sb.append(interfaces.getString(ii));
if (ii + 1 < interfaces.length()) {
sb.append(" ");
}
}
sb.append(" ");
sb.append(obj.getString("clientPort")).append(',');
sb.append(obj.getString("adminPort")).append(',');
sb.append(obj.getString("httpPort"));
return sb.toString();
} catch (Exception e) {
hostLog.warn("Unable to format host metadata " + json, e);
}
return "";
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class plannerTester method loadPlanFromFile.
public static AbstractPlanNode loadPlanFromFile(String path, ArrayList<String> getsql) {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(path));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
String message = "ERROR: Plan file " + path + " doesn't exist.\n" + "Use -s (the Compile/Save option) or 'ant plannertestrefresh'" + " ' to generate plans to the baseline directory.\n";
System.err.print(message);
try {
m_reportWriter.write(message);
} catch (IOException e2) {
e2.printStackTrace();
}
return null;
}
try {
String json = "";
try {
String line = reader.readLine();
getsql.add(line);
while ((line = reader.readLine()) != null) {
json += line;
}
} catch (IOException e2) {
e2.printStackTrace();
return null;
}
try {
PlanNodeTree pnt = new PlanNodeTree();
JSONObject jobj = new JSONObject(json);
Database db = s_singleton.getDatabase();
pnt.loadFromJSONPlan(jobj, db);
return pnt.getRootPlanNode();
} catch (JSONException e3) {
e3.printStackTrace();
System.out.println("Failed on input from file: " + path + " with JSON text: \n'" + json + "'");
return null;
}
} finally {
try {
reader.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class testLoadPlanNodeFromJSON method testLoadQueryPlanTree.
public void testLoadQueryPlanTree(String sql) throws JSONException {
AbstractPlanNode pn = compile(sql);
PlanNodeTree pnt = new PlanNodeTree(pn);
String str = pnt.toJSONString();
JSONObject jsonPlan = new JSONObject(str);
PlanNodeTree pnt1 = new PlanNodeTree();
pnt1.loadFromJSONPlan(jsonPlan, getDatabase());
String str1 = pnt1.toJSONString();
assertTrue(str.equals(str1));
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class testPlannerTester method testGetScanNodeList.
/// Unit test some of the techniques used by plannerTester
public void testGetScanNodeList() {
AbstractPlanNode pn = null;
pn = compile("select * from l where lname=? and b=0 order by id asc limit ?;");
ArrayList<AbstractScanPlanNode> collected = pn.getScanNodeList();
System.out.println(collected);
System.out.println(collected.size());
for (AbstractPlanNode n : collected) {
System.out.println(n.toExplainPlanString());
}
assertTrue(collected.size() == 1);
JSONObject j;
try {
j = new JSONObject(collected.get(0).toJSONString());
System.out.println(j.getString("PLAN_NODE_TYPE"));
assertTrue(j.getString("PLAN_NODE_TYPE").equalsIgnoreCase("INDEXSCAN"));
} catch (JSONException e) {
e.printStackTrace();
}
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class TestSystemCatalogSuite method testTablesSelector.
public void testTablesSelector() throws IOException, ProcCallException, JSONException {
Client client = getClient();
VoltTable results = client.callProcedure("@SystemCatalog", "TABLES").getResults()[0];
assertEquals(10, results.getColumnCount());
// Tables are returned in alphabetical order, because the underlying CatalogMap
// is backed by java.util.TreeMap
results.advanceRow();
assertEquals("AA_T", results.get("TABLE_NAME", VoltType.STRING));
assertEquals("{\"partitionColumn\":\"A1\",\"drEnabled\":\"true\"}", results.get("REMARKS", VoltType.STRING));
results.advanceRow();
assertEquals("BB_V", results.get("TABLE_NAME", VoltType.STRING));
assertEquals(new JSONObject("{\"partitionColumn\":\"A1\",\"sourceTable\":\"AA_T\"}").toString(), results.get("REMARKS", VoltType.STRING));
results.advanceRow();
assertEquals("CC_T_WITH_EXEC_DELETE", results.get("TABLE_NAME", VoltType.STRING));
assertEquals("{\"partitionColumn\":\"A1\"," + "\"limitPartitionRowsDeleteStmt\":\"DELETE FROM CC_T_WITH_EXEC_DELETE WHERE A1=0;\"}", results.get("REMARKS", VoltType.STRING));
assertEquals(false, results.advanceRow());
}
Aggregations