use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class SchemaTest method testGetAttribute.
@Test
public void testGetAttribute() {
Attribute expectedAttribute1 = new Attribute("sampleAttribute_1", AttributeType.STRING);
Attribute expectedAttribute2 = new Attribute("sampleAttribute_2", AttributeType.STRING);
Attribute retrievedAttribute1 = schema.getAttribute(attributeName1);
Attribute retrievedAttribute2 = schema.getAttribute(attributeName2.toUpperCase());
Assert.assertEquals(expectedAttribute1, retrievedAttribute1);
Assert.assertEquals(expectedAttribute2, retrievedAttribute2);
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class SchemaTest method testAddingInBetween.
@Test(expected = UnsupportedOperationException.class)
public void testAddingInBetween() {
// Should fail due to immutability
List<Attribute> attributes = schema.getAttributes();
attributes.add(0, new Attribute("sampleField_3", AttributeType.STRING));
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class SpanTupleTest method testGetters.
@Test
public void testGetters() throws ParseException {
// create data tuple first
Attribute[] attributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < attributes.length - 1; count++) {
attributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
attributes[attributes.length - 1] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
List<IField> fields = new ArrayList<IField>(Arrays.asList(new IField[] { new StringField("bruce"), new StringField("lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("bruce was born in new york city and was grown up in los angeles") }));
IField spanField = createSpanListField();
fields.add(spanField);
spanTuple = new Tuple(new Schema(attributes), fields.toArray(new IField[fields.size()]));
IField spanFieldRetrieved = spanTuple.getField(SchemaConstants.SPAN_LIST);
Assert.assertTrue(spanFieldRetrieved instanceof ListField);
Assert.assertSame(spanField, spanFieldRetrieved);
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class ExcelSinkTest method testOpen.
@Test
public void testOpen() throws Exception {
excelSink.open();
// // verify that inputOperator called open() method
Mockito.verify(inputOperator).open();
// // assert that the tuple stream sink removes the _ID and PAYLOAD attribute
Assert.assertEquals(new Schema(new Attribute("content", AttributeType.TEXT)), excelSink.getOutputSchema());
excelSink.close();
Files.deleteIfExists(excelSink.getFilePath());
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class ExcelSinkTest method attributeTypeTest.
@Test
public // writing 10000 tuples
void attributeTypeTest() throws Exception {
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.AGE);
attributeNames.add(TestConstants.HEIGHT);
attributeNames.add(TestConstants.DATE_OF_BIRTH);
attributeNames.add(TestConstants.DESCRIPTION);
// Prepare Schema
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length];
for (int count = 0; count < schemaAttributes.length; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
// Prepare 10000 tuples as a tupleList
int testSize = 10000;
Random rand = new Random();
List<Tuple> tupleList = new ArrayList<Tuple>();
for (int i = 0; i < testSize; i++) {
IField[] fields = { new StringField(getRandomString()), new StringField(getRandomString()), new IntegerField(rand.nextInt()), new DoubleField(rand.nextDouble() * rand.nextInt()), new DateField(getRandomDate()), new TextField(getRandomString()) };
tupleList.add(new Tuple(new Schema(schemaAttributes), fields));
}
assert (tupleList.size() == testSize);
IOperator inputOperator = Mockito.mock(IOperator.class);
Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
OngoingStubbing<Tuple> stubbing = Mockito.when(inputOperator.getNextTuple());
for (Tuple t : tupleList) {
stubbing = stubbing.thenReturn(t);
}
stubbing = stubbing.thenReturn(null);
// excel writing test
excelSink = new ExcelSink(new ExcelSinkPredicate());
excelSink.setInputOperator(inputOperator);
excelSink.open();
excelSink.collectAllTuples();
excelSink.close();
Files.deleteIfExists(excelSink.getFilePath());
}
Aggregations