Search in sources :

Example 21 with StorageException

use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.

the class DataWriter method insertTuple.

public IDField insertTuple(Tuple tuple) throws StorageException {
    if (!isOpen) {
        throw new StorageException(ErrorMessages.OPERATOR_NOT_OPENED);
    }
    try {
        // tuple must not contain _id field
        if (tuple.getSchema().containsAttribute(SchemaConstants._ID)) {
            throw new StorageException("Tuple must not contain _id field. _id must be generated by the system");
        }
        // generate a random ID for this tuple
        IDField idField = new IDField(UUID.randomUUID().toString());
        Tuple tupleWithID = getTupleWithID(tuple, idField);
        // make sure the tuple's schema agrees with the table's schema
        if (!tupleWithID.getSchema().equals(this.schema)) {
            throw new StorageException("Tuple's schema is not the same as the table's schema");
        }
        Document document = getLuceneDocument(tupleWithID);
        this.luceneIndexWriter.addDocument(document);
        this.dataStore.incrementNumDocuments(1);
        return idField;
    } catch (IOException e) {
        close();
        throw new StorageException(e.getMessage(), e);
    }
}
Also used : IDField(edu.uci.ics.texera.api.field.IDField) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) StorageException(edu.uci.ics.texera.api.exception.StorageException) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 22 with StorageException

use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.

the class RelationManager method deleteTable.

/**
 * Deletes a table by its name.
 * If the table doesn't exist, it won't do anything.
 * Deleting system catalog tables is prohibited.
 *
 * @param tableName, the name of a table, case insensitive
 * @throws StorageException
 */
public void deleteTable(String tableName) throws StorageException {
    tableName = tableName.toLowerCase();
    // User can't delete catalog table
    if (isSystemCatalog(tableName)) {
        throw new StorageException("Deleting a system catalog table is prohibited.");
    }
    // if table doesn't exist, then do nothing
    if (!checkTableExistence(tableName)) {
        return;
    }
    // try to clear all data in the table
    DataWriter dataWriter = getTableDataWriter(tableName);
    dataWriter.open();
    dataWriter.clearData();
    dataWriter.close();
    StorageUtils.deleteDirectory(getTableDirectory(tableName));
    // generate a query for the table name
    Query catalogTableNameQuery = new TermQuery(new Term(CatalogConstants.TABLE_NAME, tableName));
    // delete the table from table catalog
    DataWriter tableCatalogWriter = new DataWriter(CatalogConstants.TABLE_CATALOG_DATASTORE, LuceneAnalyzerConstants.getStandardAnalyzer());
    tableCatalogWriter.open();
    tableCatalogWriter.deleteTuple(catalogTableNameQuery);
    tableCatalogWriter.close();
    // delete the table from schema catalog
    DataWriter schemaCatalogWriter = new DataWriter(CatalogConstants.SCHEMA_CATALOG_DATASTORE, LuceneAnalyzerConstants.getStandardAnalyzer());
    schemaCatalogWriter.open();
    schemaCatalogWriter.deleteTuple(catalogTableNameQuery);
    schemaCatalogWriter.close();
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) StorageException(edu.uci.ics.texera.api.exception.StorageException)

Example 23 with StorageException

use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.

the class RelationManager method initializeCatalog.

/*
     * Initializes the system catalog tables.
     */
private void initializeCatalog() throws StorageException {
    try {
        // create table catalog
        writeTableInfoToCatalog(CatalogConstants.TABLE_CATALOG.toLowerCase(), CatalogConstants.TABLE_CATALOG_DIRECTORY.toRealPath(), CatalogConstants.TABLE_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
        // create schema catalog
        writeTableInfoToCatalog(CatalogConstants.SCHEMA_CATALOG.toLowerCase(), CatalogConstants.SCHEMA_CATALOG_DIRECTORY.toRealPath(), CatalogConstants.SCHEMA_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : IOException(java.io.IOException) StorageException(edu.uci.ics.texera.api.exception.StorageException)

Example 24 with StorageException

use of edu.uci.ics.texera.api.exception.StorageException in project textdb by TextDB.

the class RelationManager method getTableDirectory.

/**
 * Gets the directory of a table.
 *
 * @param tableName, the name of the table, case insensitive
 * @return
 * @throws StorageException
 */
public String getTableDirectory(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 directory for table %s is not found.", tableName));
    }
    // get the directory field
    IField directoryField = tableCatalogTuple.getField(CatalogConstants.TABLE_DIRECTORY);
    return directoryField.getValue().toString();
}
Also used : IField(edu.uci.ics.texera.api.field.IField) StorageException(edu.uci.ics.texera.api.exception.StorageException) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

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