Search in sources :

Example 16 with StorageException

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

the class DataWriter method open.

public void open() throws StorageException {
    if (this.luceneIndexWriter == null || !this.luceneIndexWriter.isOpen()) {
        try {
            Directory directory = FSDirectory.open(Paths.get(this.indexDirectory));
            IndexWriterConfig conf = new IndexWriterConfig(analyzer);
            this.luceneIndexWriter = new IndexWriter(directory, conf);
            this.isOpen = true;
        } catch (IOException e) {
            throw new StorageException(e.getMessage(), e);
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 17 with StorageException

use of edu.uci.ics.textdb.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(), new File(CatalogConstants.TABLE_CATALOG_DIRECTORY).getCanonicalPath(), CatalogConstants.TABLE_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
        // create schema catalog
        writeTableInfoToCatalog(CatalogConstants.SCHEMA_CATALOG.toLowerCase(), new File(CatalogConstants.SCHEMA_CATALOG_DIRECTORY).getCanonicalPath(), CatalogConstants.SCHEMA_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Example 18 with StorageException

use of edu.uci.ics.textdb.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.textdb.api.field.IField) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 19 with StorageException

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

the class RelationManager method getTableAnalyzer.

/**
     * Gets the Lucene analyzer of a table.
     *   
     * @param tableName, the name of the table, case insensitive
     * @return
     * @throws StorageException
     */
public Analyzer getTableAnalyzer(String tableName) throws StorageException {
    String analyzerString = getTableAnalyzerString(tableName);
    // convert a lucene analyzer string to an analyzer object
    Analyzer luceneAnalyzer = null;
    try {
        luceneAnalyzer = LuceneAnalyzerConstants.getLuceneAnalyzer(analyzerString);
    } catch (DataFlowException e) {
        throw new StorageException(e);
    }
    return luceneAnalyzer;
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Analyzer(org.apache.lucene.analysis.Analyzer) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Example 20 with StorageException

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

the class Utils method getTextdbHomePath.

/**
     * Gets the path of the textdb home directory by:
     *   1): try to use TEXTDB_HOME environment variable, 
     *   if it fails then:
     *   2): compare if the current directory is textdb (where TEXTDB_HOME should be), 
     *   if it's not then:
     *   3): compare if the current directory is a textdb subproject, 
     *   if it's not then:
     *   
     *   Finding textdb home directory will fail
     * 
     * @return the real absolute path to textdb home directory
     * @throws StorageException if can not find textdb home
     */
public static String getTextdbHomePath() throws StorageException {
    try {
        // try to use TEXTDB_HOME environment variable first
        if (System.getenv(DataConstants.HOME_ENV_VAR) != null) {
            String textdbHome = System.getenv(DataConstants.HOME_ENV_VAR);
            return Paths.get(textdbHome).toRealPath().toString();
        } else {
            // if the environment variable is not found, try if the current directory is textdb
            String currentWorkingDirectory = Paths.get("").toRealPath().toString();
            // if the current directory ends with textdb (TEXTDB_HOME location)
            boolean isTextdbHome = currentWorkingDirectory.endsWith(DataConstants.HOME_FOLDER_NAME);
            // if the current directory is one of the sub-projects
            boolean isSubProject = Arrays.asList(TextdbProject.values()).stream().map(project -> project.getProjectName()).filter(project -> currentWorkingDirectory.endsWith(project)).findAny().isPresent();
            if (isTextdbHome) {
                return Paths.get(currentWorkingDirectory).toRealPath().toString();
            }
            if (isSubProject) {
                return Paths.get(currentWorkingDirectory, "../").toRealPath().toString();
            }
            throw new StorageException("Finding textdb home path failed. Current working directory is " + currentWorkingDirectory);
        }
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : IntStream(java.util.stream.IntStream) SchemaConstants(edu.uci.ics.textdb.api.constants.SchemaConstants) DataConstants(edu.uci.ics.textdb.api.constants.DataConstants) Arrays(java.util.Arrays) Attribute(edu.uci.ics.textdb.api.schema.Attribute) TextdbProject(edu.uci.ics.textdb.api.constants.DataConstants.TextdbProject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Schema(edu.uci.ics.textdb.api.schema.Schema) List(java.util.List) Paths(java.nio.file.Paths) IField(edu.uci.ics.textdb.api.field.IField) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) IOException(java.io.IOException) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Aggregations

StorageException (edu.uci.ics.textdb.api.exception.StorageException)22 IOException (java.io.IOException)14 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)9 IField (edu.uci.ics.textdb.api.field.IField)4 Schema (edu.uci.ics.textdb.api.schema.Schema)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 Query (org.apache.lucene.search.Query)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)3 IDField (edu.uci.ics.textdb.api.field.IDField)3 Attribute (edu.uci.ics.textdb.api.schema.Attribute)3 DataWriter (edu.uci.ics.textdb.storage.DataWriter)3 File (java.io.File)3 Term (org.apache.lucene.index.Term)3 TermQuery (org.apache.lucene.search.TermQuery)3 StringField (edu.uci.ics.textdb.api.field.StringField)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Analyzer (org.apache.lucene.analysis.Analyzer)2