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;
}
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);
}
}
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();
}
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;
}
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());
}
}
Aggregations