Search in sources :

Example 11 with IDField

use of edu.uci.ics.textdb.api.field.IDField 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

IDField (edu.uci.ics.textdb.api.field.IDField)11 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)10 Test (org.junit.Test)6 StringField (edu.uci.ics.textdb.api.field.StringField)5 Schema (edu.uci.ics.textdb.api.schema.Schema)5 StorageException (edu.uci.ics.textdb.api.exception.StorageException)3 Attribute (edu.uci.ics.textdb.api.schema.Attribute)3 Span (edu.uci.ics.textdb.api.span.Span)3 DataWriter (edu.uci.ics.textdb.storage.DataWriter)3 IOException (java.io.IOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IField (edu.uci.ics.textdb.api.field.IField)2 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)2 TextField (edu.uci.ics.textdb.api.field.TextField)2 SimilarityJoinPredicate (edu.uci.ics.textdb.exp.join.SimilarityJoinPredicate)2 RegexMatcher (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher)2 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)1 ListField (edu.uci.ics.textdb.api.field.ListField)1 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)1