Search in sources :

Example 71 with JSONException

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

the class CatalogUtil method getCatalogIndexSize.

// Calculate the width of an index:
// -- if the index is a pure-column index, return number of columns in the index
// -- if the index is an expression index, return number of expressions used to create the index
public static int getCatalogIndexSize(Index index) {
    int indexSize = 0;
    String jsonstring = index.getExpressionsjson();
    if (jsonstring.isEmpty()) {
        indexSize = getSortedCatalogItems(index.getColumns(), "index").size();
    } else {
        try {
            indexSize = AbstractExpression.fromJSONArrayString(jsonstring, null).size();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return indexSize;
}
Also used : JSONException(org.json_voltpatches.JSONException) Constraint(org.voltdb.catalog.Constraint)

Example 72 with JSONException

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

the class ReplaceWithIndexLimit method checkIndex.

private boolean checkIndex(Index index, AbstractExpression aggExpr, List<AbstractExpression> filterExprs, List<AbstractExpression> bindingExprs, String fromTableAlias) {
    if (!IndexType.isScannable(index.getType())) {
        return false;
    }
    // Skip partial indexes
    if (!index.getPredicatejson().isEmpty()) {
        return false;
    }
    String exprsjson = index.getExpressionsjson();
    if (exprsjson.isEmpty()) {
        // if the index is on simple columns, aggregate expression must be a simple column too
        if (aggExpr.getExpressionType() != ExpressionType.VALUE_TUPLE) {
            return false;
        }
        return checkPureColumnIndex(index, ((TupleValueExpression) aggExpr).getColumnIndex(), filterExprs);
    } else {
        // either pure expression index or mix of expressions and simple columns
        List<AbstractExpression> indexedExprs = null;
        StmtTableScan tableScan = m_parsedStmt.getStmtTableScanByAlias(fromTableAlias);
        try {
            indexedExprs = AbstractExpression.fromJSONArrayString(exprsjson, tableScan);
        } catch (JSONException e) {
            e.printStackTrace();
            assert (false);
            return false;
        }
        return checkExpressionIndex(indexedExprs, aggExpr, filterExprs, bindingExprs);
    }
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) JSONException(org.json_voltpatches.JSONException) StmtTableScan(org.voltdb.planner.parseinfo.StmtTableScan)

Example 73 with JSONException

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

Example 74 with JSONException

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

the class IndexSnapshotRequestConfig method parsePartitionRanges.

// parse ranges
private Collection<PartitionRanges> parsePartitionRanges(JSONObject jsData) {
    if (jsData != null) {
        try {
            JSONObject partitionObj = jsData.getJSONObject("partitionRanges");
            Iterator partitionKey = partitionObj.keys();
            ImmutableList.Builder<PartitionRanges> partitionRangesBuilder = ImmutableList.builder();
            while (partitionKey.hasNext()) {
                String pidStr = (String) partitionKey.next();
                JSONObject rangeObj = partitionObj.getJSONObject(pidStr);
                Iterator rangeKey = rangeObj.keys();
                ImmutableSortedMap.Builder<Integer, Integer> rangeBuilder = ImmutableSortedMap.naturalOrder();
                while (rangeKey.hasNext()) {
                    String rangeStartStr = (String) rangeKey.next();
                    int rangeStart = Integer.parseInt(rangeStartStr);
                    int rangeEnd = rangeObj.getInt(rangeStartStr);
                    rangeBuilder.put(rangeStart, rangeEnd);
                }
                partitionRangesBuilder.add(new PartitionRanges(Integer.parseInt(pidStr), rangeBuilder.build()));
            }
            return partitionRangesBuilder.build();
        } catch (JSONException e) {
            SNAP_LOG.warn("Failed to parse partition ranges", e);
        }
    }
    return null;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ImmutableList(com.google_voltpatches.common.collect.ImmutableList) Iterator(java.util.Iterator) ImmutableSortedMap(com.google_voltpatches.common.collect.ImmutableSortedMap) JSONException(org.json_voltpatches.JSONException)

Example 75 with JSONException

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

the class TestCollector method createLogFiles.

private void createLogFiles() throws Exception {
    try {
        String configInfoPath = m_voltDbRootPath + File.separator + Constants.CONFIG_DIR + File.separator + "config.json";
        ;
        JSONObject jsonObject = Collector.parseJSONFile(configInfoPath);
        JSONArray jsonArray = jsonObject.getJSONArray("log4jDst");
        //maintain the file naming format
        String fileNamePrefix = "volt-junit-fulllog.txt.";
        String fileText = "This is a dummy log file.";
        String workingDir = getWorkingDir(m_voltDbRootPath);
        VoltFile logFolder = new VoltFile(workingDir + "/obj/release/testoutput/");
        logFolder.mkdir();
        for (File oldLogFile : logFolder.listFiles()) {
            if (oldLogFile.getName().startsWith(fileNamePrefix)) {
                oldLogFile.delete();
            }
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String[] fileDates = new String[6];
        Calendar cal, cal2;
        cal = Calendar.getInstance();
        cal2 = Calendar.getInstance();
        for (int i = -1; i < 2; i++) {
            cal.add(Calendar.DATE, -i - 1);
            fileDates[i + 1] = formatter.format(cal.getTime());
        }
        cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, -1);
        cal2.set(cal.get(Calendar.YEAR), 11, 31);
        fileDates[3] = formatter.format(cal2.getTime());
        cal2.add(Calendar.DATE, -4);
        fileDates[4] = formatter.format(cal2.getTime());
        cal2 = Calendar.getInstance();
        cal2.set(cal2.get(Calendar.YEAR), 0, 02);
        fileDates[5] = formatter.format(cal2.getTime());
        for (String fileDate : fileDates) {
            VoltFile file = new VoltFile(logFolder, fileNamePrefix + fileDate);
            file.createNewFile();
            BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
            writer.write(fileText);
            writer.close();
            formatter.format(file.lastModified());
            file.setLastModified(formatter.parse(fileDate).getTime());
            JSONObject object = new JSONObject();
            object.put("path", file.getCanonicalPath());
            object.put("format", "'.'" + fileDate);
            jsonArray.put(object);
        }
        VoltFile repeatFileFolder = new VoltFile(logFolder, "test");
        repeatFileFolder.mkdir();
        VoltFile file = new VoltFile(repeatFileFolder, fileNamePrefix + fileDates[0]);
        file.createNewFile();
        BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
        writer.write(fileText);
        writer.close();
        JSONObject object = new JSONObject();
        object.put("path", file.getCanonicalPath());
        object.put("format", "'.'" + fileDates[0]);
        jsonArray.put(object);
        FileOutputStream fos = new FileOutputStream(configInfoPath);
        fos.write(jsonObject.toString(4).getBytes(Charsets.UTF_8));
        fos.close();
    } catch (JSONException e) {
        System.err.print(e.getMessage());
    } catch (ParseException e) {
        System.err.print(e.getMessage());
    }
}
Also used : Calendar(java.util.Calendar) FileWriter(java.io.FileWriter) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) BufferedWriter(java.io.BufferedWriter) JSONObject(org.json_voltpatches.JSONObject) FileOutputStream(java.io.FileOutputStream) ParseException(java.text.ParseException) ZipFile(java.util.zip.ZipFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

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