Search in sources :

Example 91 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class SchemaTest method testAddingInBetween.

@Test(expected = UnsupportedOperationException.class)
public void testAddingInBetween() {
    // Should fail due to immutability
    List<Attribute> attributes = schema.getAttributes();
    attributes.add(0, new Attribute("sampleField_3", AttributeType.STRING));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Test(org.junit.Test)

Example 92 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class RelationManagerTest method test15.

@Test
public void test15() throws Exception {
    String tableName1 = "relation_manager_test_table_15_1";
    String tableName2 = "relation_manager_test_table_15_2";
    String indexDirectory = "./index/test_table/relation_manager_test_table_15";
    Schema schema = new Schema(new Attribute("content", AttributeType.TEXT));
    String luceneAnalyzerString = "standard";
    relationManager.deleteTable(tableName1);
    relationManager.deleteTable(tableName2);
    relationManager.createTable(tableName1, indexDirectory, schema, luceneAnalyzerString);
    // create another table with the same directory should fail
    try {
        relationManager.createTable(tableName2, indexDirectory, schema, luceneAnalyzerString);
        System.out.println(relationManager.getTableDirectory(tableName1));
        System.out.println(relationManager.getTableDirectory(tableName2));
        Assert.fail("Storage exception should be thrown because of duplicate index directories");
    } catch (StorageException e) {
    }
    relationManager.deleteTable(tableName1);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Test(org.junit.Test)

Example 93 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute 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.getRelationManager();
    // create tables
    for (int i = 0; i < NUM_OF_LOOPS; i++) {
        // delete previously inserted tables first
        relationManager.deleteTable(tableName + '_' + i);
        relationManager.createTable(tableName + '_' + i, 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(Utils.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.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) File(java.io.File) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Test(org.junit.Test)

Example 94 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class RelationManagerTest method test8.

/*
     * Test inserting a tuple to a table and then delete it 
     */
@Test
public void test8() throws Exception {
    String tableName = "relation_manager_test_table";
    String tableDirectory = "./index/test_table";
    Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
    RelationManager relationManager = RelationManager.getRelationManager();
    relationManager.deleteTable(tableName);
    relationManager.createTable(tableName, tableDirectory, tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
    IDField idField = dataWriter.insertTuple(insertedTuple);
    dataWriter.close();
    Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
    dataWriter.open();
    dataWriter.deleteTupleByID(idField);
    dataWriter.close();
    Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertNull(deletedTuple);
    relationManager.deleteTable(tableName);
}
Also used : IDField(edu.uci.ics.textdb.api.field.IDField) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) StringField(edu.uci.ics.textdb.api.field.StringField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 95 with Attribute

use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.

the class RelationManagerTest method test9.

/*
     * Test inserting a tuple to a table, then update it, then delete it 
     */
@Test
public void test9() throws Exception {
    String tableName = "relation_manager_test_table";
    String tableDirectory = "./index/test_table";
    Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
    RelationManager relationManager = RelationManager.getRelationManager();
    relationManager.deleteTable(tableName);
    relationManager.createTable(tableName, tableDirectory, tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
    IDField idField = dataWriter.insertTuple(insertedTuple);
    dataWriter.close();
    Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
    dataWriter.open();
    Tuple updatedTuple = new Tuple(tableSchema, new StringField("testUpdate"));
    dataWriter.updateTuple(updatedTuple, idField);
    dataWriter.close();
    Tuple returnedUpdatedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(updatedTuple.getField("content").getValue().toString(), returnedUpdatedTuple.getField("content").getValue().toString());
    dataWriter.open();
    dataWriter.deleteTupleByID(idField);
    dataWriter.close();
    Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertNull(deletedTuple);
    relationManager.deleteTable(tableName);
}
Also used : IDField(edu.uci.ics.textdb.api.field.IDField) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) StringField(edu.uci.ics.textdb.api.field.StringField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

Attribute (edu.uci.ics.textdb.api.schema.Attribute)118 ArrayList (java.util.ArrayList)94 Schema (edu.uci.ics.textdb.api.schema.Schema)93 Test (org.junit.Test)88 IField (edu.uci.ics.textdb.api.field.IField)87 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)85 TextField (edu.uci.ics.textdb.api.field.TextField)74 Span (edu.uci.ics.textdb.api.span.Span)69 StringField (edu.uci.ics.textdb.api.field.StringField)61 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)58 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)57 DateField (edu.uci.ics.textdb.api.field.DateField)54 SimpleDateFormat (java.text.SimpleDateFormat)53 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)23 ListField (edu.uci.ics.textdb.api.field.ListField)14 AttributeType (edu.uci.ics.textdb.api.schema.AttributeType)9 List (java.util.List)7 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)6 Collectors (java.util.stream.Collectors)6 SchemaConstants (edu.uci.ics.textdb.api.constants.SchemaConstants)5