use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.
the class RelationManagerTest method test7.
/*
* Test creating and deleting multiple tables in relation manager.
*/
@Test
public void test7() throws Exception {
String tableName = "relation_manager_test_table";
String tableDirectory = "./index/test_table";
Schema tableSchema = new Schema(new Attribute("city", AttributeType.STRING), new Attribute("description", AttributeType.TEXT), new Attribute("tax rate", AttributeType.DOUBLE), new Attribute("population", AttributeType.INTEGER), new Attribute("record time", AttributeType.DATE));
int NUM_OF_LOOPS = 10;
RelationManager relationManager = RelationManager.getInstance();
// create tables
for (int i = 0; i < NUM_OF_LOOPS; i++) {
// delete previously inserted tables first
relationManager.deleteTable(tableName + '_' + i);
relationManager.createTable(tableName + '_' + i, Paths.get(tableDirectory + '_' + i), tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
}
// assert tables are correctly created
for (int i = 0; i < NUM_OF_LOOPS; i++) {
Assert.assertEquals(new File(tableDirectory + '_' + i).getCanonicalPath(), relationManager.getTableDirectory(tableName + '_' + i));
Assert.assertEquals(Schema.Builder.getSchemaWithID(tableSchema), relationManager.getTableSchema(tableName + '_' + i));
}
// delete tables
for (int i = 0; i < NUM_OF_LOOPS; i++) {
relationManager.deleteTable(tableName + '_' + i);
}
// assert tables are correctly deleted
int errorCount = 0;
for (int i = 0; i < NUM_OF_LOOPS; i++) {
try {
relationManager.getTableDirectory(tableName + '_' + i);
} catch (StorageException e) {
errorCount++;
}
}
Assert.assertEquals(NUM_OF_LOOPS, errorCount);
}
use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.
the class RegexMatcherSourceOperator method createLuceneQuery.
public static Query createLuceneQuery(RegexSourcePredicate predicate) throws StorageException {
Query luceneQuery;
String queryString;
// Try to apply translator. If it fails, use scan query.
try {
queryString = RegexToGramQueryTranslator.translate(predicate.getRegex()).getLuceneQueryString();
} catch (com.google.re2j.PatternSyntaxException e) {
queryString = DataflowUtils.LUCENE_SCAN_QUERY;
}
// Try to parse the query string. It if fails, raise an exception.
try {
luceneQuery = new MultiFieldQueryParser(predicate.getAttributeNames().stream().toArray(String[]::new), RelationManager.getInstance().getTableAnalyzer(predicate.getTableName())).parse(queryString);
} catch (ParseException e) {
throw new StorageException(e);
}
return luceneQuery;
}
use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.
the class DataReader method close.
@Override
public void close() throws StorageException {
cursor = CLOSED;
if (luceneIndexReader != null) {
try {
luceneIndexReader.close();
luceneIndexReader = null;
} catch (IOException e) {
throw new StorageException(e.getMessage(), e);
}
}
}
use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.
the class DataReader method open.
@Override
public void open() throws StorageException {
if (cursor != CLOSED) {
return;
}
try {
Directory indexDirectory = FSDirectory.open(this.dataStore.getDataDirectory());
luceneIndexReader = DirectoryReader.open(indexDirectory);
luceneIndexSearcher = new IndexSearcher(luceneIndexReader);
TopDocs topDocs = luceneIndexSearcher.search(query, Integer.MAX_VALUE);
scoreDocs = topDocs.scoreDocs;
inputSchema = this.dataStore.getSchema();
if (payloadAdded) {
outputSchema = new Schema.Builder(inputSchema).add(SchemaConstants.PAYLOAD_ATTRIBUTE).build();
} else {
outputSchema = inputSchema;
}
} catch (IOException e) {
throw new StorageException(e.getMessage(), e);
}
cursor = OPENED;
}
use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.
the class DataReader method getNextTuple.
@Override
public Tuple getNextTuple() throws StorageException {
if (cursor == CLOSED) {
throw new StorageException(ErrorMessages.OPERATOR_NOT_OPENED);
}
Tuple resultTuple;
try {
if (cursor >= scoreDocs.length) {
return null;
}
int docID = scoreDocs[cursor].doc;
resultTuple = constructTuple(docID);
} catch (IOException | ParseException e) {
throw new StorageException(e.getMessage(), e);
}
cursor++;
return resultTuple;
}
Aggregations