Search in sources :

Example 6 with JSONException

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

the class SubPlanAssembler method isPartialIndexPredicateCovered.

/**
     * Split the index WHERE clause into a list of sub-expressions and process
     * each expression separately searching the query (or matview) for a
     * covering expression for each of these expressions.
     * All index WHERE sub-expressions must be covered to enable the index.
     * Collect the query expressions that EXACTLY match the index expression.
     * They can be eliminated from the post-filters as an optimization.
     *
     * @param tableScan The source table.
     * @param coveringExprs The set of query predicate expressions.
     * @param index The partial index to cover.
     * @param exactMatchCoveringExprs The output subset of the query predicates that EXACTLY match the
     *        index predicate expression(s)
     * @return TRUE if the index has a predicate that is completely covered by the query expressions.
     */
public static boolean isPartialIndexPredicateCovered(StmtTableScan tableScan, List<AbstractExpression> coveringExprs, String predicatejson, List<AbstractExpression> exactMatchCoveringExprs) {
    assert (!predicatejson.isEmpty());
    AbstractExpression indexPredicate = null;
    try {
        indexPredicate = AbstractExpression.fromJSONString(predicatejson, tableScan);
    } catch (JSONException e) {
        e.printStackTrace();
        assert (false);
        return false;
    }
    List<AbstractExpression> exprsToCover = ExpressionUtil.uncombinePredicate(indexPredicate);
    for (AbstractExpression coveringExpr : coveringExprs) {
        if (exprsToCover.isEmpty()) {
            // We are done there. All the index predicate expressions are covered.
            break;
        }
        // Each covering expression and its reversed copy need to be tested for the index expression coverage.
        AbstractExpression reversedCoveringExpr = null;
        ExpressionType reverseCoveringType = ComparisonExpression.reverses.get(coveringExpr.getExpressionType());
        if (reverseCoveringType != null) {
            // reverse the expression
            reversedCoveringExpr = new ComparisonExpression(reverseCoveringType, coveringExpr.getRight(), coveringExpr.getLeft());
        }
        // Exact match first.
        if (removeExactMatchCoveredExpressions(coveringExpr, exprsToCover)) {
            exactMatchCoveringExprs.add(coveringExpr);
        }
        // Try the reversed expression for the exact match
        if (reversedCoveringExpr != null && removeExactMatchCoveredExpressions(reversedCoveringExpr, exprsToCover)) {
            // It is the original expression that we need to remember
            exactMatchCoveringExprs.add(coveringExpr);
        }
    }
    // Handle the remaining NOT NULL index predicate expressions that can be covered by NULL rejecting expressions
    exprsToCover = removeNotNullCoveredExpressions(tableScan, coveringExprs, exprsToCover);
    // All index predicate expressions must be covered for index to be selected
    return exprsToCover.isEmpty();
}
Also used : ComparisonExpression(org.voltdb.expressions.ComparisonExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) JSONException(org.json_voltpatches.JSONException) ExpressionType(org.voltdb.types.ExpressionType)

Example 7 with JSONException

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

the class SystemInformation method populateOverviewTable.

/**
     * Accumulate per-host information and return as a table.
     * This function does the real work. Everything else is
     * boilerplate sysproc stuff.
     */
public static VoltTable populateOverviewTable() {
    VoltTable vt = constructOverviewTable();
    int hostId = VoltDB.instance().getHostMessenger().getHostId();
    // try to get the external interface first, if none was set, use local addresses
    InetAddress addr = null;
    String clientInterface = null;
    int clientPort = VoltDB.DEFAULT_PORT;
    String adminInterface = null;
    int adminPort = VoltDB.DEFAULT_ADMIN_PORT;
    String httpInterface = null;
    int httpPort = VoltDB.DEFAULT_HTTP_PORT;
    String internalInterface = null;
    int internalPort = Constants.DEFAULT_INTERNAL_PORT;
    String zkInterface = null;
    int zkPort = Constants.DEFAULT_ZK_PORT;
    String drInterface = null;
    int drPort = VoltDB.DEFAULT_DR_PORT;
    String publicInterface = null;
    try {
        String localMetadata = VoltDB.instance().getLocalMetadata();
        JSONObject jsObj = new JSONObject(localMetadata);
        JSONArray interfaces = jsObj.getJSONArray("interfaces");
        String iface = interfaces.getString(0);
        addr = InetAddress.getByName(iface);
        clientPort = jsObj.getInt("clientPort");
        clientInterface = jsObj.getString("clientInterface");
        adminPort = jsObj.getInt("adminPort");
        adminInterface = jsObj.getString("adminInterface");
        httpPort = jsObj.getInt("httpPort");
        httpInterface = jsObj.getString("httpInterface");
        internalPort = jsObj.getInt("internalPort");
        internalInterface = jsObj.getString("internalInterface");
        zkPort = jsObj.getInt("zkPort");
        zkInterface = jsObj.getString("zkInterface");
        drPort = jsObj.getInt("drPort");
        drInterface = jsObj.getString("drInterface");
        publicInterface = jsObj.getString("publicInterface");
    } catch (JSONException e) {
        hostLog.info("Failed to get local metadata, falling back to first resolvable IP address.");
    } catch (UnknownHostException e) {
        hostLog.info("Failed to determine hostname, falling back to first resolvable IP address.");
    }
    // host name and IP address.
    if (addr == null) {
        addr = org.voltcore.utils.CoreUtils.getLocalAddress();
    }
    vt.addRow(hostId, "IPADDRESS", addr.getHostAddress());
    vt.addRow(hostId, "HOSTNAME", CoreUtils.getHostnameOrAddress());
    vt.addRow(hostId, "CLIENTINTERFACE", clientInterface);
    vt.addRow(hostId, "CLIENTPORT", Integer.toString(clientPort));
    vt.addRow(hostId, "ADMININTERFACE", adminInterface);
    vt.addRow(hostId, "ADMINPORT", Integer.toString(adminPort));
    vt.addRow(hostId, "HTTPINTERFACE", httpInterface);
    vt.addRow(hostId, "HTTPPORT", Integer.toString(httpPort));
    vt.addRow(hostId, "INTERNALINTERFACE", internalInterface);
    vt.addRow(hostId, "INTERNALPORT", Integer.toString(internalPort));
    vt.addRow(hostId, "ZKINTERFACE", zkInterface);
    vt.addRow(hostId, "ZKPORT", Integer.toString(zkPort));
    vt.addRow(hostId, "DRINTERFACE", drInterface);
    vt.addRow(hostId, "DRPORT", Integer.toString(drPort));
    vt.addRow(hostId, "PUBLICINTERFACE", publicInterface);
    // build string
    vt.addRow(hostId, "BUILDSTRING", VoltDB.instance().getBuildString());
    // version
    vt.addRow(hostId, "VERSION", VoltDB.instance().getVersionString());
    // catalog path
    String path = VoltDB.instance().getConfig().m_pathToCatalog;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "CATALOG", path);
    // deployment path
    path = VoltDB.instance().getConfig().m_pathToDeployment;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "DEPLOYMENT", path);
    String cluster_state = VoltDB.instance().getMode().toString();
    vt.addRow(hostId, "CLUSTERSTATE", cluster_state);
    // INITIALIZED, used by VEM to determine the spinny icon state.
    org.voltdb.OperationMode mode = VoltDB.instance().getMode();
    String areInitialized = Boolean.toString(!VoltDB.instance().rejoining() && (mode == org.voltdb.OperationMode.RUNNING || mode == org.voltdb.OperationMode.PAUSED));
    vt.addRow(hostId, "INITIALIZED", areInitialized);
    String replication_role = VoltDB.instance().getReplicationRole().toString();
    vt.addRow(hostId, "REPLICATIONROLE", replication_role);
    vt.addRow(hostId, "LASTCATALOGUPDATETXNID", Long.toString(VoltDB.instance().getCatalogContext().m_transactionId));
    vt.addRow(hostId, "CATALOGCRC", Long.toString(VoltDB.instance().getCatalogContext().getCatalogCRC()));
    vt.addRow(hostId, "IV2ENABLED", "true");
    long startTimeMs = VoltDB.instance().getHostMessenger().getInstanceId().getTimestamp();
    vt.addRow(hostId, "STARTTIME", Long.toString(startTimeMs));
    vt.addRow(hostId, "UPTIME", MiscUtils.formatUptime(VoltDB.instance().getClusterUptime()));
    SocketHubAppender hubAppender = (SocketHubAppender) Logger.getRootLogger().getAppender("hub");
    int port = 0;
    if (hubAppender != null)
        port = hubAppender.getPort();
    vt.addRow(hostId, "LOG4JPORT", Integer.toString(port));
    //Add license information
    if (MiscUtils.isPro()) {
        vt.addRow(hostId, "LICENSE", VoltDB.instance().getLicenseInformation());
    }
    populatePartitionGroups(hostId, vt);
    // root path
    vt.addRow(hostId, "VOLTDBROOT", VoltDB.instance().getVoltDBRootPath());
    vt.addRow(hostId, "FULLCLUSTERSIZE", Integer.toString(VoltDB.instance().getCatalogContext().getClusterSettings().hostcount()));
    vt.addRow(hostId, "CLUSTERID", Integer.toString(VoltDB.instance().getCatalogContext().getCluster().getDrclusterid()));
    return vt;
}
Also used : UnknownHostException(java.net.UnknownHostException) SocketHubAppender(org.apache.log4j.net.SocketHubAppender) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) VoltTable(org.voltdb.VoltTable) JSONObject(org.json_voltpatches.JSONObject) InetAddress(java.net.InetAddress) File(java.io.File)

Example 8 with JSONException

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

the class CatalogSchemaTools method toSchema.

/**
     * Convert a Table catalog object into the proper SQL DDL, including all indexes,
     * constraints, and foreign key references.
     * Also returns just the CREATE TABLE statement, since, like all good methods,
     * it should have two purposes....
     * It would be nice to have a separate method to just generate the CREATE TABLE,
     * but we use that pass to also figure out what separate constraint and index
     * SQL DDL needs to be generated, so instead, we opt to build the CREATE TABLE DDL
     * separately as we go here, and then fill it in to the StringBuilder being used
     * to construct the full canonical DDL at the appropriate time.
     * @param sb - the schema being built
     * @param catalog_tbl - object to be analyzed
     * @param viewQuery - the Query if this Table is a View
     * @param isExportOnly Is this a export table.
     * @param streamPartitionColumn stream partition column
     * @param streamTarget - true if this Table is an Export Table
     * @return SQL Schema text representing the CREATE TABLE statement to generate the table
     */
public static String toSchema(StringBuilder sb, Table catalog_tbl, String viewQuery, boolean isExportOnly, String streamPartitionColumn, String streamTarget) {
    assert (!catalog_tbl.getColumns().isEmpty());
    boolean tableIsView = (viewQuery != null);
    // We need the intermediate results of building the table schema string so that
    // we can return the full CREATE TABLE statement, so accumulate it separately
    final StringBuilder table_sb = new StringBuilder();
    final Set<Index> skip_indexes = new HashSet<>();
    final Set<Constraint> skip_constraints = new HashSet<>();
    if (tableIsView) {
        table_sb.append("CREATE VIEW ").append(catalog_tbl.getTypeName()).append(" (");
    } else {
        if (isExportOnly) {
            table_sb.append("CREATE STREAM ").append(catalog_tbl.getTypeName());
            if (streamPartitionColumn != null && viewQuery == null) {
                table_sb.append(" PARTITION ON COLUMN ").append(streamPartitionColumn);
            }
            //Default target means no target.
            if (streamTarget != null && !streamTarget.equalsIgnoreCase(Constants.DEFAULT_EXPORT_CONNECTOR_NAME)) {
                table_sb.append(" EXPORT TO TARGET ").append(streamTarget);
            }
        } else {
            table_sb.append("CREATE TABLE ").append(catalog_tbl.getTypeName());
        }
        table_sb.append(" (");
    }
    // Columns
    String add = "\n";
    for (Column catalog_col : CatalogUtil.getSortedCatalogItems(catalog_tbl.getColumns(), "index")) {
        VoltType col_type = VoltType.get((byte) catalog_col.getType());
        if (tableIsView) {
            table_sb.append(add).append(spacer).append(catalog_col.getTypeName());
            add = ",\n";
            continue;
        }
        table_sb.append(add).append(spacer).append(catalog_col.getTypeName()).append(" ").append(col_type.toSQLString()).append(col_type.isVariableLength() && catalog_col.getSize() > 0 ? "(" + catalog_col.getSize() + (catalog_col.getInbytes() ? " BYTES" : "") + ")" : "");
        // Default value
        String defaultvalue = catalog_col.getDefaultvalue();
        //VoltType defaulttype = VoltType.get((byte)catalog_col.getDefaulttype());
        boolean nullable = catalog_col.getNullable();
        // TODO: Shouldn't have to check whether the string contains "null"
        if (defaultvalue == null) {
        } else if (defaultvalue.toLowerCase().equals("null") && nullable) {
            defaultvalue = null;
        } else {
            if (col_type == VoltType.TIMESTAMP) {
                if (defaultvalue.startsWith("CURRENT_TIMESTAMP")) {
                    defaultvalue = "CURRENT_TIMESTAMP";
                } else {
                    assert (defaultvalue.matches("[0-9]+"));
                    long epoch = Long.parseLong(defaultvalue);
                    Date d = new Date(epoch / 1000);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    defaultvalue = "\'" + sdf.format(d) + "." + StringUtils.leftPad(String.valueOf(epoch % 1000000), 6, "0") + "\'";
                }
            } else {
                // XXX: if (defaulttype != VoltType.VOLTFUNCTION) {
                // TODO: Escape strings properly
                defaultvalue = defaultvalue.replace("\'", "\'\'");
                defaultvalue = "'" + defaultvalue + "'";
            }
        }
        if (defaultvalue == null) {
            table_sb.append((!nullable ? " NOT NULL" : ""));
        } else {
            table_sb.append(" DEFAULT ").append(defaultvalue != null ? defaultvalue : "NULL").append(!nullable ? " NOT NULL" : "");
        }
        // Single-column constraints
        for (ConstraintRef catalog_const_ref : catalog_col.getConstraints()) {
            Constraint catalog_const = catalog_const_ref.getConstraint();
            ConstraintType const_type = ConstraintType.get(catalog_const.getType());
            // Check if there is another column in our table with the same constraint
            // If there is, then we need to add it to the end of the table definition
            boolean found = false;
            for (Column catalog_other_col : catalog_tbl.getColumns()) {
                if (catalog_other_col.equals(catalog_col))
                    continue;
                if (catalog_other_col.getConstraints().getIgnoreCase(catalog_const.getTypeName()) != null) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                switch(const_type) {
                    case FOREIGN_KEY:
                        {
                            Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                            Column catalog_fkey_col = null;
                            for (ColumnRef ref : catalog_const.getForeignkeycols()) {
                                catalog_fkey_col = ref.getColumn();
                                // Nasty hack to get first item
                                break;
                            }
                            assert (catalog_fkey_col != null);
                            table_sb.append(" REFERENCES ").append(catalog_fkey_tbl.getTypeName()).append(" (").append(catalog_fkey_col.getTypeName()).append(")");
                            skip_constraints.add(catalog_const);
                            break;
                        }
                    default:
                }
            }
        }
        add = ",\n";
    }
    // Constraints
    for (Constraint catalog_const : catalog_tbl.getConstraints()) {
        if (skip_constraints.contains(catalog_const))
            continue;
        ConstraintType const_type = ConstraintType.get(catalog_const.getType());
        // Primary Keys / Unique Constraints
        if (const_type == ConstraintType.PRIMARY_KEY || const_type == ConstraintType.UNIQUE) {
            Index catalog_idx = catalog_const.getIndex();
            if (!tableIsView) {
                // Get the ConstraintType.
                table_sb.append(add).append(spacer);
                if (!catalog_const.getTypeName().startsWith(HSQLInterface.AUTO_GEN_PREFIX)) {
                    table_sb.append("CONSTRAINT ").append(catalog_const.getTypeName()).append(" ");
                }
                if (const_type == ConstraintType.PRIMARY_KEY || const_type == ConstraintType.UNIQUE) {
                    if (const_type == ConstraintType.PRIMARY_KEY) {
                        table_sb.append("PRIMARY KEY (");
                    } else {
                        if (catalog_idx.getAssumeunique()) {
                            table_sb.append("ASSUMEUNIQUE (");
                        } else {
                            table_sb.append("UNIQUE (");
                        }
                    }
                    String col_add = "";
                    if (catalog_idx.getExpressionsjson() != null && !catalog_idx.getExpressionsjson().equals("")) {
                        String exprStrings = new String();
                        StmtTargetTableScan tableScan = new StmtTargetTableScan(catalog_tbl);
                        try {
                            List<AbstractExpression> expressions = AbstractExpression.fromJSONArrayString(catalog_idx.getExpressionsjson(), tableScan);
                            String sep = "";
                            for (AbstractExpression expr : expressions) {
                                exprStrings += sep + expr.explain(catalog_tbl.getTypeName());
                                sep = ",";
                            }
                        } catch (JSONException e) {
                        }
                        table_sb.append(col_add).append(exprStrings);
                    } else {
                        for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                            table_sb.append(col_add).append(catalog_colref.getColumn().getTypeName());
                            col_add = ", ";
                        }
                    // FOR
                    }
                    table_sb.append(")");
                }
            }
            if (catalog_idx.getTypeName().startsWith(HSQLInterface.AUTO_GEN_PREFIX) || catalog_idx.getTypeName().startsWith(HSQLInterface.AUTO_GEN_MATVIEW)) {
                skip_indexes.add(catalog_idx);
            }
        // Foreign Key
        } else if (const_type == ConstraintType.FOREIGN_KEY) {
            Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
            String col_add = "";
            String our_columns = "";
            String fkey_columns = "";
            for (ColumnRef catalog_colref : catalog_const.getForeignkeycols()) {
                // The name of the ColumnRef is the column in our base table
                Column our_column = catalog_tbl.getColumns().getIgnoreCase(catalog_colref.getTypeName());
                assert (our_column != null);
                our_columns += col_add + our_column.getTypeName();
                Column fkey_column = catalog_colref.getColumn();
                assert (fkey_column != null);
                fkey_columns += col_add + fkey_column.getTypeName();
                col_add = ", ";
            }
            table_sb.append(add).append(spacer + "CONSTRAINT ").append(catalog_const.getTypeName()).append(" FOREIGN KEY (").append(our_columns).append(") REFERENCES ").append(catalog_fkey_tbl.getTypeName()).append(" (").append(fkey_columns).append(")");
        }
        skip_constraints.add(catalog_const);
    }
    if (catalog_tbl.getTuplelimit() != Integer.MAX_VALUE) {
        table_sb.append(add).append(spacer + "LIMIT PARTITION ROWS ").append(String.valueOf(catalog_tbl.getTuplelimit()));
        String deleteStmt = CatalogUtil.getLimitPartitionRowsDeleteStmt(catalog_tbl);
        if (deleteStmt != null) {
            if (deleteStmt.endsWith(";")) {
                // StatementCompiler appends the semicolon, we don't want it here.
                deleteStmt = deleteStmt.substring(0, deleteStmt.length() - 1);
            }
            table_sb.append("\n" + spacer + spacer + "EXECUTE (").append(deleteStmt).append(")");
        }
    }
    if (viewQuery != null) {
        table_sb.append("\n) AS \n");
        table_sb.append(spacer).append(viewQuery).append(";\n");
    } else {
        table_sb.append("\n);\n");
    }
    // We've built the full CREATE TABLE statement for this table,
    // Append the generated table schema to the canonical DDL StringBuilder
    sb.append(table_sb.toString());
    // Partition Table for regular tables (non-streams)
    if (catalog_tbl.getPartitioncolumn() != null && viewQuery == null && !isExportOnly) {
        sb.append("PARTITION TABLE ").append(catalog_tbl.getTypeName()).append(" ON COLUMN ").append(catalog_tbl.getPartitioncolumn().getTypeName()).append(";\n");
    }
    // All other Indexes
    for (Index catalog_idx : catalog_tbl.getIndexes()) {
        if (skip_indexes.contains(catalog_idx))
            continue;
        if (catalog_idx.getUnique()) {
            if (catalog_idx.getAssumeunique()) {
                sb.append("CREATE ASSUMEUNIQUE INDEX ");
            } else {
                sb.append("CREATE UNIQUE INDEX ");
            }
        } else {
            sb.append("CREATE INDEX ");
        }
        sb.append(catalog_idx.getTypeName()).append(" ON ").append(catalog_tbl.getTypeName()).append(" (");
        add = "";
        String jsonstring = catalog_idx.getExpressionsjson();
        if (jsonstring.isEmpty()) {
            for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                sb.append(add).append(catalog_colref.getColumn().getTypeName());
                add = ", ";
            }
        } else {
            List<AbstractExpression> indexedExprs = null;
            try {
                indexedExprs = AbstractExpression.fromJSONArrayString(jsonstring, new StmtTargetTableScan(catalog_tbl));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (indexedExprs != null) {
                for (AbstractExpression expr : indexedExprs) {
                    sb.append(add).append(expr.explain(catalog_tbl.getTypeName()));
                    add = ", ";
                }
            }
        }
        sb.append(")");
        String jsonPredicate = catalog_idx.getPredicatejson();
        if (!jsonPredicate.isEmpty()) {
            try {
                AbstractExpression predicate = AbstractExpression.fromJSONString(jsonPredicate, new StmtTargetTableScan(catalog_tbl));
                sb.append(" WHERE ").append(predicate.explain(catalog_tbl.getTypeName()));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        sb.append(";\n");
    }
    if (catalog_tbl.getIsdred()) {
        sb.append("DR TABLE ").append(catalog_tbl.getTypeName()).append(";\n");
    }
    sb.append("\n");
    // statement to whoever might be interested (DDLCompiler, I'm looking in your direction)
    return table_sb.toString();
}
Also used : Table(org.voltdb.catalog.Table) Constraint(org.voltdb.catalog.Constraint) JSONException(org.json_voltpatches.JSONException) Index(org.voltdb.catalog.Index) Date(java.util.Date) AbstractExpression(org.voltdb.expressions.AbstractExpression) Column(org.voltdb.catalog.Column) VoltType(org.voltdb.VoltType) StmtTargetTableScan(org.voltdb.planner.parseinfo.StmtTargetTableScan) ConstraintType(org.voltdb.types.ConstraintType) ColumnRef(org.voltdb.catalog.ColumnRef) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) ConstraintRef(org.voltdb.catalog.ConstraintRef)

Example 9 with JSONException

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

the class AdhocDDLTestBase method isDRedTable.

protected boolean isDRedTable(String table) throws Exception {
    VoltTable tableinfo = m_client.callProcedure("@SystemCatalog", "TABLES").getResults()[0];
    for (int i = 0; i < tableinfo.m_rowCount; i++) {
        tableinfo.advanceToRow(i);
        String tablename = (String) tableinfo.get(2, VoltType.STRING);
        if (tablename.equals(table)) {
            try {
                String remarks = (String) tableinfo.get(4, VoltType.STRING);
                if (remarks == null) {
                    return false;
                }
                JSONObject jsEntry = new JSONObject(remarks);
                return Boolean.valueOf(jsEntry.getString(JdbcDatabaseMetaDataGenerator.JSON_DRED_TABLE));
            } catch (JSONException e) {
                return false;
            }
        }
    }
    return false;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException)

Example 10 with JSONException

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

the class ClientResponseImpl method toJSONString.

@Override
public String toJSONString() {
    JSONStringer js = new JSONStringer();
    try {
        js.object();
        js.keySymbolValuePair(JSON_STATUS_KEY, status);
        js.keySymbolValuePair(JSON_APPSTATUS_KEY, appStatus);
        js.keySymbolValuePair(JSON_STATUSSTRING_KEY, statusString);
        js.keySymbolValuePair(JSON_APPSTATUSSTRING_KEY, appStatusString);
        js.key(JSON_RESULTS_KEY);
        js.array();
        for (VoltTable o : results) {
            js.value(o);
        }
        js.endArray();
        js.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        throw new RuntimeException("Failed to serialize a parameter set to JSON.", e);
    }
    return js.toString();
}
Also used : JSONException(org.json_voltpatches.JSONException) JSONStringer(org.json_voltpatches.JSONStringer)

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