Search in sources :

Example 36 with JSONException

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();
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException)

Example 37 with JSONException

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));
}
Also used : CoreZK(org.voltcore.zk.CoreZK) ParameterSet(org.voltdb.ParameterSet) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) VoltType(org.voltdb.VoltType) ClusterSettings(org.voltdb.settings.ClusterSettings) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) Logger(org.apache.log4j.Logger) Systemsettings(org.voltdb.catalog.Systemsettings) DtxnConstants(org.voltdb.dtxn.DtxnConstants) CatalogUtil(org.voltdb.utils.CatalogUtil) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) ProcInfo(org.voltdb.ProcInfo) Deployment(org.voltdb.catalog.Deployment) Map(java.util.Map) JSONObject(org.json_voltpatches.JSONObject) CoreUtils(org.voltcore.utils.CoreUtils) Constants(org.voltcore.common.Constants) GroupRef(org.voltdb.catalog.GroupRef) User(org.voltdb.catalog.User) VoltLogger(org.voltcore.logging.VoltLogger) SnapshotSchedule(org.voltdb.catalog.SnapshotSchedule) SocketHubAppender(org.apache.log4j.net.SocketHubAppender) VoltTableUtil(org.voltdb.utils.VoltTableUtil) Connector(org.voltdb.catalog.Connector) VoltSystemProcedure(org.voltdb.VoltSystemProcedure) Set(java.util.Set) Cluster(org.voltdb.catalog.Cluster) DependencyPair(org.voltdb.DependencyPair) MiscUtils(org.voltdb.utils.MiscUtils) UnknownHostException(java.net.UnknownHostException) VoltDB(org.voltdb.VoltDB) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) JSONException(org.json_voltpatches.JSONException) SystemProcedureExecutionContext(org.voltdb.SystemProcedureExecutionContext) List(java.util.List) Stat(org.apache.zookeeper_voltpatches.data.Stat) NodeSettings(org.voltdb.settings.NodeSettings) Entry(java.util.Map.Entry) Database(org.voltdb.catalog.Database) JSONArray(org.json_voltpatches.JSONArray) CommandLog(org.voltdb.catalog.CommandLog) VoltTable(org.voltdb.VoltTable) Stat(org.apache.zookeeper_voltpatches.data.Stat) JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 38 with JSONException

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

Example 39 with JSONException

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");
    }
}
Also used : TaskType(org.voltdb.jni.ExecutionEngine.TaskType) JSONException(org.json_voltpatches.JSONException) Map(java.util.Map)

Example 40 with JSONException

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;
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) Statement(org.voltdb.catalog.Statement) ArrayList(java.util.ArrayList) JSONException(org.json_voltpatches.JSONException) PlanNodeList(org.voltdb.plannodes.PlanNodeList) JSONException(org.json_voltpatches.JSONException) StmtParameter(org.voltdb.catalog.StmtParameter) JSONObject(org.json_voltpatches.JSONObject) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression) QueryType(org.voltdb.types.QueryType) DatabaseEstimates(org.voltdb.compiler.DatabaseEstimates)

Aggregations

JSONException (org.json_voltpatches.JSONException)76 JSONObject (org.json_voltpatches.JSONObject)36 AbstractExpression (org.voltdb.expressions.AbstractExpression)17 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)13 ColumnRef (org.voltdb.catalog.ColumnRef)13 JSONArray (org.json_voltpatches.JSONArray)12 JSONStringer (org.json_voltpatches.JSONStringer)12 Column (org.voltdb.catalog.Column)12 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)11 HashMap (java.util.HashMap)9 Map (java.util.Map)9 File (java.io.File)8 Constraint (org.voltdb.catalog.Constraint)8 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)8 HashSet (java.util.HashSet)7 Table (org.voltdb.catalog.Table)7 Index (org.voltdb.catalog.Index)6 TreeMap (java.util.TreeMap)5 ExecutionException (java.util.concurrent.ExecutionException)5