use of org.json_voltpatches.JSONException 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.JSONException in project voltdb by VoltDB.
the class SystemInformation method populatePartitionGroups.
private static void populatePartitionGroups(Integer hostId, VoltTable vt) {
try {
byte[] bytes = VoltDB.instance().getHostMessenger().getZK().getData(CoreZK.hosts_host + hostId, false, new Stat());
String hostInfo = new String(bytes, StandardCharsets.UTF_8);
JSONObject obj = new JSONObject(hostInfo);
vt.addRow(hostId, "PLACEMENTGROUP", obj.getString("group"));
} catch (KeeperException | InterruptedException | JSONException e) {
vt.addRow(hostId, "PLACEMENTGROUP", "NULL");
}
Set<Integer> buddies = VoltDB.instance().getCartograhper().getHostIdsWithinPartitionGroup(hostId);
String[] strIds = buddies.stream().sorted().map(i -> String.valueOf(i)).toArray(String[]::new);
vt.addRow(hostId, "PARTITIONGROUP", String.join(",", strIds));
}
use of org.json_voltpatches.JSONException in project voltdb by VoltDB.
the class BalancePartitionsRequest method toJSONString.
@Override
public String toJSONString() {
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
stringer.key("partitionPairs").array();
for (PartitionPair pair : partitionPairs) {
stringer.object();
stringer.keySymbolValuePair("srcPartition", pair.srcPartition);
stringer.keySymbolValuePair("destPartition", pair.destPartition);
stringer.keySymbolValuePair("rangeStart", pair.rangeStart);
stringer.keySymbolValuePair("rangeEnd", pair.rangeEnd);
stringer.endObject();
}
stringer.endArray();
stringer.endObject();
return stringer.toString();
} catch (JSONException e) {
return null;
}
}
use of org.json_voltpatches.JSONException in project voltdb by VoltDB.
the class ExecuteTask_SP method run.
/**
* System procedure run hook.
* Use the base class implementation.
*
* @param ctx execution context
* @param partitionParam key for routing stored procedure to correct site
* @param params additional parameter(s) for the task to execute, first one is always task type
*/
public void run(SystemProcedureExecutionContext ctx, byte[] partitionParam, byte[] params) {
assert params.length > 0;
byte taskId = params[0];
TaskType taskType = TaskType.values()[taskId];
switch(taskType) {
case SP_JAVA_GET_DRID_TRACKER:
Map<Integer, Map<Integer, DRConsumerDrIdTracker>> drIdTrackers = ctx.getDrAppliedTrackers();
Pair<Long, Long> lastConsumerUniqueIds = ctx.getDrLastAppliedUniqueIds();
try {
setAppStatusString(jsonifyTrackedDRData(lastConsumerUniqueIds, drIdTrackers));
} catch (JSONException e) {
throw new VoltAbortException("DRConsumerDrIdTracker could not be converted to JSON");
}
break;
case RESET_DR_APPLIED_TRACKER_SINGLE:
assert params.length == 2;
byte clusterId = params[1];
ctx.resetDrAppliedTracker(clusterId);
break;
default:
throw new VoltAbortException("Unable to find the task associated with the given task id");
}
}
use of org.json_voltpatches.JSONException in project voltdb by VoltDB.
the class PlannerTestAideDeCamp method compile.
/**
* Compile and cache the statement and plan and return the final plan graph.
*/
private List<AbstractPlanNode> compile(String sql, int paramCount, String joinOrder, boolean inferPartitioning, boolean forceSingle, DeterminismMode detMode) {
String stmtLabel = "stmt-" + String.valueOf(compileCounter++);
Statement catalogStmt = proc.getStatements().add(stmtLabel);
catalogStmt.setSqltext(sql);
catalogStmt.setSinglepartition(forceSingle);
// determine the type of the query
QueryType qtype = QueryType.SELECT;
catalogStmt.setReadonly(true);
if (sql.toLowerCase().startsWith("insert")) {
qtype = QueryType.INSERT;
catalogStmt.setReadonly(false);
}
if (sql.toLowerCase().startsWith("update")) {
qtype = QueryType.UPDATE;
catalogStmt.setReadonly(false);
}
if (sql.toLowerCase().startsWith("delete")) {
qtype = QueryType.DELETE;
catalogStmt.setReadonly(false);
}
catalogStmt.setQuerytype(qtype.getValue());
// name will look like "basename-stmt-#"
String name = catalogStmt.getParent().getTypeName() + "-" + catalogStmt.getTypeName();
DatabaseEstimates estimates = new DatabaseEstimates();
TrivialCostModel costModel = new TrivialCostModel();
StatementPartitioning partitioning;
if (inferPartitioning) {
partitioning = StatementPartitioning.inferPartitioning();
} else if (forceSingle) {
partitioning = StatementPartitioning.forceSP();
} else {
partitioning = StatementPartitioning.forceMP();
}
String procName = catalogStmt.getParent().getTypeName();
QueryPlanner planner = new QueryPlanner(sql, stmtLabel, procName, db, partitioning, hsql, estimates, false, StatementCompiler.DEFAULT_MAX_JOIN_TABLES, costModel, null, joinOrder, detMode);
CompiledPlan plan = null;
planner.parse();
plan = planner.plan();
assert (plan != null);
// Partitioning optionally inferred from the planning process.
if (partitioning.isInferred()) {
catalogStmt.setSinglepartition(partitioning.isInferredSingle());
}
// We will need to update the system catalogs with this new information
for (int i = 0; i < plan.parameters.length; ++i) {
StmtParameter catalogParam = catalogStmt.getParameters().add(String.valueOf(i));
ParameterValueExpression pve = plan.parameters[i];
catalogParam.setJavatype(pve.getValueType().getValue());
catalogParam.setIsarray(pve.getParamIsVector());
catalogParam.setIndex(i);
}
List<PlanNodeList> nodeLists = new ArrayList<>();
nodeLists.add(new PlanNodeList(plan.rootPlanGraph));
if (plan.subPlanGraph != null) {
nodeLists.add(new PlanNodeList(plan.subPlanGraph));
}
// Now update our catalog information
// HACK: We're using the node_tree's hashCode() as it's name. It would be really
// nice if the Catalog code give us an guid without needing a name first...
String json = null;
try {
JSONObject jobj = new JSONObject(nodeLists.get(0).toJSONString());
json = jobj.toString(4);
} catch (JSONException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
System.exit(-1);
return null;
}
//
try {
BuildDirectoryUtils.writeFile("statement-plans", name + "_json.txt", json, true);
BuildDirectoryUtils.writeFile("statement-plans", name + ".dot", nodeLists.get(0).toDOTString("name"), true);
} catch (Exception e) {
e.printStackTrace();
}
List<AbstractPlanNode> plannodes = new ArrayList<>();
for (PlanNodeList nodeList : nodeLists) {
plannodes.add(nodeList.getRootPlanNode());
}
m_currentPlan = plan;
return plannodes;
}
Aggregations