use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class Join method open.
@Override
public void open() throws TextDBException {
if (cursor != CLOSED) {
return;
}
if (innerOperator == null) {
throw new DataFlowException("Inner Input Operator is not set.");
}
if (outerOperator == null) {
throw new DataFlowException("Outer Input Operator is not set.");
}
// generate output schema from schema of inner and outer operator
innerOperator.open();
Schema innerOperatorSchema = innerOperator.getOutputSchema();
outerOperator.open();
Schema outerOperatorSchema = outerOperator.getOutputSchema();
this.outputSchema = joinPredicate.generateOutputSchema(innerOperatorSchema, outerOperatorSchema);
cursor = OPENED;
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class TupleSourceOperatorTest method test1.
@Test
public void test1() throws TextDBException {
TupleSourceOperator tupleSource = new TupleSourceOperator(TestConstants.getSamplePeopleTuples(), TestConstants.SCHEMA_PEOPLE);
tupleSource.open();
Tuple tuple;
List<Tuple> results = new ArrayList<>();
Schema outputSchema = tupleSource.getOutputSchema();
while ((tuple = tupleSource.getNextTuple()) != null) {
results.add(tuple);
}
tupleSource.close();
// assert result is equal to input
Assert.assertTrue(TestUtils.equals(TestConstants.getSamplePeopleTuples(), results));
// assert _id is added to schema
Assert.assertTrue(outputSchema.equals(Utils.getSchemaWithID(TestConstants.SCHEMA_PEOPLE)));
// assert all tuples contain _id field
for (Tuple resultTuple : results) {
Assert.assertTrue(resultTuple.getField(SchemaConstants._ID).getClass().equals(IDField.class));
}
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class DataWriter method getTupleWithID.
/*
* Adds the _id to the front of the tuple, if the _id field doesn't exist in the tuple.
*/
private static Tuple getTupleWithID(Tuple tuple, IDField _id) {
Tuple tupleWithID = tuple;
Schema tupleSchema = tuple.getSchema();
if (!tupleSchema.containsField(SchemaConstants._ID)) {
tupleSchema = Utils.getSchemaWithID(tupleSchema);
List<IField> newTupleFields = new ArrayList<>();
newTupleFields.add(_id);
newTupleFields.addAll(tuple.getFields());
tupleWithID = new Tuple(tupleSchema, newTupleFields.stream().toArray(IField[]::new));
}
return tupleWithID;
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class FileSourceOperatorTest method test3.
/*
* Test FileSourceOperator with a Directory with recursive = true and maxDepth = null.
*
* All the files under the recursive sub-directories will be read.
*
* expected results: test1.txt, test2.txt, test4.txt and test5.txt will be included
*/
@Test
public void test3() throws Exception {
String attrName = "content";
Schema schema = new Schema(new Attribute(attrName, AttributeType.TEXT));
FileSourcePredicate predicate = new FileSourcePredicate(tempFolderPath.toString(), attrName, true, null, null);
FileSourceOperator fileSource = new FileSourceOperator(predicate);
Tuple tuple;
ArrayList<Tuple> exactResults = new ArrayList<>();
fileSource.open();
while ((tuple = fileSource.getNextTuple()) != null) {
exactResults.add(tuple);
}
fileSource.close();
List<Tuple> expectedResults = Arrays.asList(new Tuple(schema, new TextField(tempFile1String)), new Tuple(schema, new TextField(tempFile2String)), new Tuple(schema, new TextField(tempFile4String)), new Tuple(schema, new TextField(tempFile5String)));
Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
use of edu.uci.ics.textdb.api.schema.Schema in project textdb by TextDB.
the class FileSourceOperatorTest method test4.
/*
* Test FileSourceOperator with a Directory with recursive = true and maxDepth = 2.
*
* The files under the recursive sub-directories with recursive depth 2 will be read.
*
* expected results: test1.txt, test2.txt and test4.txt will be included
*/
@Test
public void test4() throws Exception {
String attrName = "content";
Schema schema = new Schema(new Attribute(attrName, AttributeType.TEXT));
FileSourcePredicate predicate = new FileSourcePredicate(tempFolderPath.toString(), attrName, true, 2, null);
FileSourceOperator fileSource = new FileSourceOperator(predicate);
Tuple tuple;
ArrayList<Tuple> exactResults = new ArrayList<>();
fileSource.open();
while ((tuple = fileSource.getNextTuple()) != null) {
exactResults.add(tuple);
}
fileSource.close();
List<Tuple> expectedResults = Arrays.asList(new Tuple(schema, new TextField(tempFile1String)), new Tuple(schema, new TextField(tempFile2String)), new Tuple(schema, new TextField(tempFile4String)));
Assert.assertTrue(TestUtils.equals(expectedResults, exactResults));
}
Aggregations