use of edu.uci.ics.texera.api.field.IDField in project textdb by TextDB.
the class RelationManagerTest method test10.
/*
* Test inserting multiple tuples to a table, getting them by a query, then deleting them by a query
*/
@Test
public void test10() throws Exception {
String tableName = "relation_manager_test_table";
String tableDirectory = "./index/test_table";
Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING), new Attribute("number", AttributeType.STRING));
RelationManager relationManager = RelationManager.getInstance();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, Paths.get(tableDirectory), tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
dataWriter.open();
Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"), new StringField("1"));
dataWriter.insertTuple(insertedTuple);
Tuple insertedTuple2 = new Tuple(tableSchema, new StringField("test"), new StringField("2"));
IDField idField2 = dataWriter.insertTuple(insertedTuple2);
Tuple insertedTuple3 = new Tuple(tableSchema, new StringField("test"), new StringField("3"));
dataWriter.insertTuple(insertedTuple3);
dataWriter.close();
// test should match all 3 tuples
Query allTupleQuery = new TermQuery(new Term("content", "test"));
DataReader allTupleReader = relationManager.getTableDataReader(tableName, allTupleQuery);
int tupleCounter = 0;
allTupleReader.open();
while (allTupleReader.getNextTuple() != null) {
tupleCounter++;
}
allTupleReader.close();
Assert.assertEquals(3, tupleCounter);
// tuple 2 should be deleted
Query tuple2Query = new TermQuery(new Term("number", "2"));
dataWriter.open();
dataWriter.deleteTuple(tuple2Query);
dataWriter.close();
Tuple deletedTuple = relationManager.getTupleByID(tableName, idField2);
Assert.assertNull(deletedTuple);
relationManager.deleteTable(tableName);
}
use of edu.uci.ics.texera.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.getInstance();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, Paths.get(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);
}
use of edu.uci.ics.texera.api.field.IDField 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.getInstance();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, Paths.get(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);
}
use of edu.uci.ics.texera.api.field.IDField in project textdb by TextDB.
the class SimilarityJoinPredicate method mergeTuples.
private Tuple mergeTuples(Tuple innerTuple, Tuple outerTuple, Schema outputSchema, List<Span> mergeSpanList) {
List<IField> resultFields = new ArrayList<>();
for (String attrName : outputSchema.getAttributeNames()) {
// generate a new _ID field for this tuple
if (attrName.equals(SchemaConstants._ID)) {
IDField newID = new IDField(UUID.randomUUID().toString());
resultFields.add(newID);
// use the generated spanList
} else if (attrName.equals(SchemaConstants.SPAN_LIST)) {
resultFields.add(new ListField<Span>(mergeSpanList));
// put the payload of two tuples together
} else if (attrName.equals(SchemaConstants.PAYLOAD)) {
ListField<Span> innerPayloadField = innerTuple.getField(SchemaConstants.PAYLOAD);
List<Span> innerPayload = innerPayloadField.getValue();
ListField<Span> outerPayloadField = outerTuple.getField(SchemaConstants.PAYLOAD);
List<Span> outerPayload = outerPayloadField.getValue();
List<Span> resultPayload = new ArrayList<>();
resultPayload.addAll(innerPayload.stream().map(span -> addFieldPrefix(span, INNER_PREFIX)).collect(Collectors.toList()));
resultPayload.addAll(outerPayload.stream().map(span -> addFieldPrefix(span, "outer_")).collect(Collectors.toList()));
resultFields.add(new ListField<Span>(resultPayload));
// add other fields from inner/outer tuples
} else {
if (attrName.startsWith(INNER_PREFIX)) {
resultFields.add(innerTuple.getField(attrName.substring(INNER_PREFIX.length())));
} else if (attrName.startsWith(OUTER_PREFIX)) {
resultFields.add(outerTuple.getField(attrName.substring(OUTER_PREFIX.length())));
}
}
}
return new Tuple(outputSchema, resultFields);
}
use of edu.uci.ics.texera.api.field.IDField in project textdb by TextDB.
the class PlanStore method deletePlan.
/**
* Removess a plan by given name from plan store.
*
* @param planName, the name of the plan.
* @throws TexeraException
*/
public void deletePlan(String planName) throws TexeraException {
Tuple plan = getPlan(planName);
if (plan == null) {
return;
}
IDField idField = (IDField) plan.getField(SchemaConstants._ID);
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
dataWriter.deleteTupleByID(idField);
dataWriter.close();
}
Aggregations