Search in sources :

Example 6 with StorageException

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

the class RelationManager method getTableCatalogTuple.

/*
     * Gets the a tuple of a table from table catalog.
     */
private static Tuple getTableCatalogTuple(String tableName) throws StorageException {
    tableName = tableName.toLowerCase();
    Query tableNameQuery = new TermQuery(new Term(CatalogConstants.TABLE_NAME, tableName));
    DataReader tableCatalogDataReader = new DataReader(CatalogConstants.TABLE_CATALOG_DATASTORE, tableNameQuery);
    tableCatalogDataReader.setPayloadAdded(false);
    tableCatalogDataReader.open();
    List<Tuple> tupleList = new ArrayList<>();
    Tuple nextTuple;
    while ((nextTuple = tableCatalogDataReader.getNextTuple()) != null) {
        tupleList.add(nextTuple);
    }
    tableCatalogDataReader.close();
    if (tupleList.size() == 0) {
        return null;
    } else if (tupleList.size() == 1) {
        return tupleList.get(0);
    } else {
        throw new StorageException("Catalog corrupted: duplicate table name found in catalog.");
    }
}
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) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 7 with StorageException

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

the class PlanStore method addPlan.

/**
     * Adds a Logical Plan JSON to the plan store.
     *
     * @param planName, the name of the plan.
     * @param description, the description of the plan.
     * @param logicalPlanJson, the logical plan JSON string
     * @Return IDField, the id field of the plan stored.
     * @throws TextDBException, when there are null fields or the given name is invalid or there is an existing plan with same name.
     */
public IDField addPlan(String planName, String description, String logicalPlanJson) throws TextDBException {
    if (planName == null || description == null || logicalPlanJson == null) {
        throw new TextDBException("Arguments cannot be null when adding a plan");
    }
    if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
        throw new TextDBException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
    }
    if (getPlan(planName) != null) {
        throw new TextDBException("A plan with the same name already exists");
    }
    try {
        // Converting the JSON String to a JSON Node to minimize space usage and to check validity of JSON string
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
        logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
    } catch (IOException e) {
        throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
    }
    Tuple tuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), new StringField(description), new StringField(logicalPlanJson));
    DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
    dataWriter.open();
    IDField id = dataWriter.insertTuple(tuple);
    dataWriter.close();
    return id;
}
Also used : IDField(edu.uci.ics.textdb.api.field.IDField) StringField(edu.uci.ics.textdb.api.field.StringField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 8 with StorageException

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

the class PlanStore method updatePlanInternal.

/**
     * Updates both plan description and plan json of a plan with the given plan name.
     * If description is null, it will not update plan description.
     * If plan json is NULL, it will not update the plan's JSON file.
     *
     * @param planName, the name of the plan.
     * @param description, the new description of the plan.
     * @param logicalPlanJson, the new plan json string.
     * @throws TextDBException
     */
private void updatePlanInternal(String planName, String description, String logicalPlanJson) throws TextDBException {
    Tuple existingPlan = getPlan(planName);
    if (existingPlan == null) {
        return;
    }
    // Checking if an updated description or logical plan JSON string has been provided
    if (description == null && logicalPlanJson == null) {
        return;
    }
    // Checking if the logical plan JSON string needs to be updated
    if (logicalPlanJson != null) {
        // Compressing and checking the validity of the logical plan JSON string
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
            logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
        } catch (IOException e) {
            throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
        }
    }
    // Getting the fields in order for performing the update
    IDField idField = (IDField) existingPlan.getField(SchemaConstants._ID);
    IField descriptionField = description != null ? new StringField(description) : existingPlan.getField(PlanStoreConstants.DESCRIPTION);
    IField logicalPlanJsonField = logicalPlanJson != null ? new StringField(logicalPlanJson) : existingPlan.getField(PlanStoreConstants.LOGICAL_PLAN_JSON);
    // Creating a tuple out of all the fields
    Tuple newTuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), descriptionField, logicalPlanJsonField);
    // Writing the updated tuple
    DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
    dataWriter.open();
    dataWriter.updateTuple(newTuple, idField);
    dataWriter.close();
}
Also used : IDField(edu.uci.ics.textdb.api.field.IDField) StringField(edu.uci.ics.textdb.api.field.StringField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) IField(edu.uci.ics.textdb.api.field.IField) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 9 with StorageException

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

the class RunTests method main.

/*
     * Write Indices Run all performance tests.
     * 
     * Passed in below arguments: 
     * file folder path (where data set stored)
     * result folder path (where performance test results stored) 
     * standard index folder path (where standard index stored) 
     * trigram index folder path(where trigram index stored) 
     * queries folder path (where query files stored)
     * 
     * If above arguments are not passed in, default paths will be used (refer
     * to PerfTestUtils.java) If some of the arguments are not applicable,
     * define them as empty string.
     * 
     * Make necessary changes for arguments, such as query file name, threshold
     * list, and regexQueries
     *
     */
public static void main(String[] args) {
    try {
        PerfTestUtils.setFileFolder(args[0]);
        PerfTestUtils.setResultFolder(args[1]);
        PerfTestUtils.setStandardIndexFolder(args[2]);
        PerfTestUtils.setTrigramIndexFolder(args[3]);
        PerfTestUtils.setQueryFolder(args[4]);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("missing arguments will be set to default");
    }
    try {
        PerfTestUtils.deleteDirectory(new File(PerfTestUtils.standardIndexFolder));
        PerfTestUtils.deleteDirectory(new File(PerfTestUtils.trigramIndexFolder));
        PerfTestUtils.writeStandardAnalyzerIndices();
        PerfTestUtils.writeTrigramIndices();
        List<Double> thresholds = Arrays.asList(0.8, 0.65, 0.5, 0.35);
        List<String> regexQueries = Arrays.asList("mosquitos?", "v[ir]{2}[us]{2}", "market(ing)?", "medic(ine|al|ation|are|aid)?", "[A-Z][aeiou|AEIOU][A-Za-z]*");
        KeywordMatcherPerformanceTest.runTest("sample_queries.txt");
        DictionaryMatcherPerformanceTest.runTest("sample_queries.txt");
        FuzzyTokenMatcherPerformanceTest.runTest("sample_queries.txt", thresholds);
        RegexMatcherPerformanceTest.runTest(regexQueries);
        NlpExtractorPerformanceTest.runTest();
    } catch (StorageException | DataFlowException | IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) IOException(java.io.IOException) File(java.io.File) StorageException(edu.uci.ics.textdb.api.exception.StorageException) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) IOException(java.io.IOException)

Example 10 with StorageException

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

the class PlanStoreTest method assertCorrectPlanExists.

/**
     * This is a helper function that checks whether the plan corresponding to the plan name corresponds to the
     * logical plan JSON string that is fed to this function
     * @param planName - Name of the plan name to check with
     * @param logicalPlanJson - Expected LogicalPlan JSON string
     * @throws TextDBException
     */
public static void assertCorrectPlanExists(String planName, String logicalPlanJson) throws TextDBException {
    Tuple res = planStore.getPlan(planName);
    Assert.assertNotNull(res);
    try {
        String returnedPlan = res.getField(PlanStoreConstants.LOGICAL_PLAN_JSON).getValue().toString();
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
        JsonNode returnedJsonNode = objectMapper.readValue(returnedPlan, JsonNode.class);
        Assert.assertEquals(jsonNode, returnedJsonNode);
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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