Search in sources :

Example 6 with IField

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

use of edu.uci.ics.textdb.api.field.IField in project textdb by TextDB.

the class PlanStore method getPlan.

/**
     * Retrieves a plan by given name from plan store.
     *
     * @param planName, the name of the plan.
     * @Return ITuple, the tuple consisting of fields of the plan.
     * @throws TextDBException
     */
public Tuple getPlan(String planName) throws TextDBException {
    Query q = new TermQuery(new Term(PlanStoreConstants.NAME, planName));
    DataReader reader = relationManager.getTableDataReader(PlanStoreConstants.TABLE_NAME, q);
    reader.open();
    Tuple inputTuple = null;
    while ((inputTuple = reader.getNextTuple()) != null) {
        IField nameField = inputTuple.getField(PlanStoreConstants.NAME);
        if (nameField.getValue().toString().equals(planName)) {
            reader.close();
            return inputTuple;
        }
    }
    reader.close();
    return null;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) DataReader(edu.uci.ics.textdb.storage.DataReader) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) IField(edu.uci.ics.textdb.api.field.IField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 8 with IField

use of edu.uci.ics.textdb.api.field.IField in project textdb by TextDB.

the class JoinDistancePredicate method compareField.

/**
	 * Used to compare the value's of a field from the inner and outer tuples'.
	 * 
	 * @param innerTuple
	 * @param outerTuple
	 * @param attributeName
	 * @return True if both the tuples have the field and the values are equal.
	 */
private boolean compareField(Tuple innerTuple, Tuple outerTuple, String attributeName) {
    IField innerField = innerTuple.getField(attributeName);
    IField outerField = outerTuple.getField(attributeName);
    if (innerField == null || outerField == null) {
        return false;
    }
    return innerField.getValue().equals(outerField.getValue());
}
Also used : IField(edu.uci.ics.textdb.api.field.IField)

Example 9 with IField

use of edu.uci.ics.textdb.api.field.IField in project textdb by TextDB.

the class DataReader method constructTuple.

private Tuple constructTuple(int docID) throws IOException, ParseException {
    Document luceneDocument = luceneIndexSearcher.doc(docID);
    ArrayList<IField> docFields = documentToFields(luceneDocument);
    if (payloadAdded) {
        ArrayList<Span> payloadSpanList = buildPayloadFromTermVector(docFields, docID);
        ListField<Span> payloadField = new ListField<Span>(payloadSpanList);
        docFields.add(payloadField);
    }
    Tuple resultTuple = new Tuple(outputSchema, docFields.stream().toArray(IField[]::new));
    return resultTuple;
}
Also used : ListField(edu.uci.ics.textdb.api.field.ListField) Document(org.apache.lucene.document.Document) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span)

Example 10 with IField

use of edu.uci.ics.textdb.api.field.IField in project textdb by TextDB.

the class MedlineIndexWriter method recordToTuple.

public static Tuple recordToTuple(String record) throws IOException, ParseException {
    JsonNode jsonNode = new ObjectMapper().readValue(record, JsonNode.class);
    ArrayList<IField> fieldList = new ArrayList<IField>();
    for (Attribute attr : ATTRIBUTES_MEDLINE) {
        fieldList.add(StorageUtils.getField(attr.getAttributeType(), jsonNode.get(attr.getAttributeName()).toString()));
    }
    IField[] fieldArray = new IField[fieldList.size()];
    Tuple tuple = new Tuple(SCHEMA_MEDLINE, fieldList.toArray(fieldArray));
    return tuple;
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IField(edu.uci.ics.textdb.api.field.IField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Aggregations

IField (edu.uci.ics.textdb.api.field.IField)140 ArrayList (java.util.ArrayList)110 TextField (edu.uci.ics.textdb.api.field.TextField)105 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)102 Schema (edu.uci.ics.textdb.api.schema.Schema)90 Span (edu.uci.ics.textdb.api.span.Span)85 StringField (edu.uci.ics.textdb.api.field.StringField)84 Attribute (edu.uci.ics.textdb.api.schema.Attribute)84 Test (org.junit.Test)84 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)80 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)68 DateField (edu.uci.ics.textdb.api.field.DateField)64 SimpleDateFormat (java.text.SimpleDateFormat)63 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)24 ListField (edu.uci.ics.textdb.api.field.ListField)16 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)9 AttributeType (edu.uci.ics.textdb.api.schema.AttributeType)5 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)4 StorageException (edu.uci.ics.textdb.api.exception.StorageException)4