use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class PlanStore method addPlan.
/**
* Adds a Logical Plan JSON to the plan store.
*
* @param planName, the name of the plan.
* @param description, the description of the plan.
* @param logicalPlanJson, the logical plan JSON string
* @Return IDField, the id field of the plan stored.
* @throws TextDBException, when there are null fields or the given name is invalid or there is an existing plan with same name.
*/
public IDField addPlan(String planName, String description, String logicalPlanJson) throws TextDBException {
if (planName == null || description == null || logicalPlanJson == null) {
throw new TextDBException("Arguments cannot be null when adding a plan");
}
if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
throw new TextDBException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
}
if (getPlan(planName) != null) {
throw new TextDBException("A plan with the same name already exists");
}
try {
// Converting the JSON String to a JSON Node to minimize space usage and to check validity of JSON string
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
} catch (IOException e) {
throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
}
Tuple tuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), new StringField(description), new StringField(logicalPlanJson));
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
IDField id = dataWriter.insertTuple(tuple);
dataWriter.close();
return id;
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class PlanStore method updatePlanInternal.
/**
* Updates both plan description and plan json of a plan with the given plan name.
* If description is null, it will not update plan description.
* If plan json is NULL, it will not update the plan's JSON file.
*
* @param planName, the name of the plan.
* @param description, the new description of the plan.
* @param logicalPlanJson, the new plan json string.
* @throws TextDBException
*/
private void updatePlanInternal(String planName, String description, String logicalPlanJson) throws TextDBException {
Tuple existingPlan = getPlan(planName);
if (existingPlan == null) {
return;
}
// Checking if an updated description or logical plan JSON string has been provided
if (description == null && logicalPlanJson == null) {
return;
}
// Checking if the logical plan JSON string needs to be updated
if (logicalPlanJson != null) {
// Compressing and checking the validity of the logical plan JSON string
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
} catch (IOException e) {
throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
}
}
// Getting the fields in order for performing the update
IDField idField = (IDField) existingPlan.getField(SchemaConstants._ID);
IField descriptionField = description != null ? new StringField(description) : existingPlan.getField(PlanStoreConstants.DESCRIPTION);
IField logicalPlanJsonField = logicalPlanJson != null ? new StringField(logicalPlanJson) : existingPlan.getField(PlanStoreConstants.LOGICAL_PLAN_JSON);
// Creating a tuple out of all the fields
Tuple newTuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), descriptionField, logicalPlanJsonField);
// Writing the updated tuple
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
dataWriter.updateTuple(newTuple, idField);
dataWriter.close();
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class RunTests method main.
/*
* Write Indices Run all performance tests.
*
* Passed in below arguments:
* file folder path (where data set stored)
* result folder path (where performance test results stored)
* standard index folder path (where standard index stored)
* trigram index folder path(where trigram index stored)
* queries folder path (where query files stored)
*
* If above arguments are not passed in, default paths will be used (refer
* to PerfTestUtils.java) If some of the arguments are not applicable,
* define them as empty string.
*
* Make necessary changes for arguments, such as query file name, threshold
* list, and regexQueries
*
*/
public static void main(String[] args) {
try {
PerfTestUtils.setFileFolder(args[0]);
PerfTestUtils.setResultFolder(args[1]);
PerfTestUtils.setStandardIndexFolder(args[2]);
PerfTestUtils.setTrigramIndexFolder(args[3]);
PerfTestUtils.setQueryFolder(args[4]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("missing arguments will be set to default");
}
try {
PerfTestUtils.deleteDirectory(new File(PerfTestUtils.standardIndexFolder));
PerfTestUtils.deleteDirectory(new File(PerfTestUtils.trigramIndexFolder));
PerfTestUtils.writeStandardAnalyzerIndices();
PerfTestUtils.writeTrigramIndices();
List<Double> thresholds = Arrays.asList(0.8, 0.65, 0.5, 0.35);
List<String> regexQueries = Arrays.asList("mosquitos?", "v[ir]{2}[us]{2}", "market(ing)?", "medic(ine|al|ation|are|aid)?", "[A-Z][aeiou|AEIOU][A-Za-z]*");
KeywordMatcherPerformanceTest.runTest("sample_queries.txt");
DictionaryMatcherPerformanceTest.runTest("sample_queries.txt");
FuzzyTokenMatcherPerformanceTest.runTest("sample_queries.txt", thresholds);
RegexMatcherPerformanceTest.runTest(regexQueries);
NlpExtractorPerformanceTest.runTest();
} catch (StorageException | DataFlowException | IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class RelationManager method getTableAnalyzerString.
/**
* Gets the Lucene analyzer string of a table.
*
* @param tableName, the name of the table, case insensitive
* @return
* @throws StorageException
*/
public String getTableAnalyzerString(String tableName) throws StorageException {
// get the tuples with tableName from the table catalog
Tuple tableCatalogTuple = getTableCatalogTuple(tableName);
// if the tuple is not found, then the table name is not found
if (tableCatalogTuple == null) {
throw new StorageException(String.format("The analyzer for table %s is not found.", tableName));
}
// get the lucene analyzer string
IField analyzerField = tableCatalogTuple.getField(CatalogConstants.TABLE_LUCENE_ANALYZER);
String analyzerString = analyzerField.getValue().toString();
return analyzerString;
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class DataWriter method close.
public void close() throws StorageException {
if (this.luceneIndexWriter != null) {
try {
this.luceneIndexWriter.close();
this.isOpen = false;
} catch (IOException e) {
throw new StorageException(e.getMessage(), e);
}
}
}
Aggregations