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