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();
}
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;
}
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());
}
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;
}
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;
}
Aggregations