Search in sources :

Example 11 with IDField

use of edu.uci.ics.texera.api.field.IDField 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);
    }
}
Also used : IDField(edu.uci.ics.texera.api.field.IDField) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) StorageException(edu.uci.ics.texera.api.exception.StorageException) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Aggregations

IDField (edu.uci.ics.texera.api.field.IDField)11 Tuple (edu.uci.ics.texera.api.tuple.Tuple)10 Test (org.junit.Test)6 StringField (edu.uci.ics.texera.api.field.StringField)5 Schema (edu.uci.ics.texera.api.schema.Schema)5 StorageException (edu.uci.ics.texera.api.exception.StorageException)3 Attribute (edu.uci.ics.texera.api.schema.Attribute)3 Span (edu.uci.ics.texera.api.span.Span)3 DataWriter (edu.uci.ics.texera.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.texera.api.field.IField)2 IntegerField (edu.uci.ics.texera.api.field.IntegerField)2 TextField (edu.uci.ics.texera.api.field.TextField)2 SimilarityJoinPredicate (edu.uci.ics.texera.dataflow.join.SimilarityJoinPredicate)2 RegexMatcher (edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher)2 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 ListField (edu.uci.ics.texera.api.field.ListField)1 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)1