Search in sources :

Example 16 with StorageException

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);
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) File(java.io.File) StorageException(edu.uci.ics.texera.api.exception.StorageException) Test(org.junit.Test)

Example 17 with StorageException

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;
}
Also used : Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) ParseException(org.apache.lucene.queryparser.classic.ParseException) StorageException(edu.uci.ics.texera.api.exception.StorageException)

Example 18 with StorageException

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);
        }
    }
}
Also used : IOException(java.io.IOException) StorageException(edu.uci.ics.texera.api.exception.StorageException)

Example 19 with StorageException

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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) Schema(edu.uci.ics.texera.api.schema.Schema) IOException(java.io.IOException) StorageException(edu.uci.ics.texera.api.exception.StorageException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 20 with StorageException

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;
}
Also used : IOException(java.io.IOException) ParseException(java.text.ParseException) StorageException(edu.uci.ics.texera.api.exception.StorageException)

Aggregations

StorageException (edu.uci.ics.texera.api.exception.StorageException)24 IOException (java.io.IOException)16 Tuple (edu.uci.ics.texera.api.tuple.Tuple)8 Schema (edu.uci.ics.texera.api.schema.Schema)4 Term (org.apache.lucene.index.Term)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 Query (org.apache.lucene.search.Query)4 TermQuery (org.apache.lucene.search.TermQuery)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)3 IDField (edu.uci.ics.texera.api.field.IDField)3 IField (edu.uci.ics.texera.api.field.IField)3 DataWriter (edu.uci.ics.texera.storage.DataWriter)3 StringField (edu.uci.ics.texera.api.field.StringField)2 Attribute (edu.uci.ics.texera.api.schema.Attribute)2 File (java.io.File)2 Path (java.nio.file.Path)2 ParseException (java.text.ParseException)2 Analyzer (org.apache.lucene.analysis.Analyzer)2