use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class TwitterSample method writeTwitterIndex.
/**
* Writes the sample twitter data into the twitter_sample table
* @throws Exception
*/
public static void writeTwitterIndex() throws Exception {
// read the JSON file into a list of JSON string tuples
JsonNode jsonNode = new ObjectMapper().readTree(new File(twitterFilePath));
ArrayList<Tuple> jsonStringTupleList = new ArrayList<>();
Schema tupleSourceSchema = new Schema(new Attribute("twitterJson", AttributeType.STRING));
for (JsonNode tweet : jsonNode) {
Tuple tuple = new Tuple(tupleSourceSchema, new StringField(tweet.toString()));
jsonStringTupleList.add(tuple);
}
// setup the twitter converter DAG
// TupleSource --> TwitterJsonConverter --> TupleSink
TupleSourceOperator tupleSource = new TupleSourceOperator(jsonStringTupleList, tupleSourceSchema, false);
createTwitterTable(twitterClimateTable, tupleSource);
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class BarChartSinkTest method test1.
@Test
public void test1() {
TupleSourceOperator tupleSource = new TupleSourceOperator(BarChartSinkTestConstants.getTuples(), BarChartSinkTestConstants.BAR_SCHEMA);
BarChartSink barChartSink = new BarChartSink(new BarChartSinkPredicate("name", Arrays.asList("grade")));
barChartSink.setInputOperator(tupleSource);
barChartSink.open();
List<Tuple> resultTuples = barChartSink.collectAllTuples();
assertTrue(TestUtils.equals(BarChartSinkTestConstants.getResultTuples(), resultTuples));
}
use of edu.uci.ics.texera.api.tuple.Tuple 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());
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class LineChartSinkTest method test1.
@Test
public void test1() {
TupleSourceOperator tupleSource = new TupleSourceOperator(LineChartSinkTestConstants.getTuples(), LineChartSinkTestConstants.BAR_SCHEMA);
LineChartSink lineChartSink = new LineChartSink(new LineChartSinkPredicate("name", Arrays.asList("grade"), LineChartEnum.LINE));
lineChartSink.setInputOperator(tupleSource);
lineChartSink.open();
List<Tuple> resultTuples = lineChartSink.collectAllTuples();
assertTrue(TestUtils.equals(LineChartSinkTestConstants.getResultTuples(), resultTuples));
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class MysqlSinkTest method test2TupleInsertion.
/**
* Create two tuples, insert into mysql
* @throws ParseException
*/
public void test2TupleInsertion() throws Exception {
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.DESCRIPTION);
// Prepare the expected result list
List<Span> list = new ArrayList<>();
Span span1 = new Span("firstName", 0, 5, "bruce", "bruce");
Span span2 = new Span("lastnName", 0, 5, "jacki", "jacki");
list.add(span1);
list.add(span2);
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list) };
IField[] fields2 = { new StringField("test"), new StringField("jackie chan"), new IntegerField(0), new DoubleField(6.0), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("09-18-1994")), new TextField("Angry Bird"), new ListField<>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
IOperator localInputOperator = Mockito.mock(IOperator.class);
Mockito.when(localInputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes)).thenReturn(null);
Mockito.when(localInputOperator.getNextTuple()).thenReturn(tuple1).thenReturn(tuple2).thenReturn(null);
mysqlSink.setInputOperator(localInputOperator);
mysqlSink.open();
mysqlSink.processTuples();
mysqlSink.close();
}
Aggregations