use of edu.uci.ics.texera.api.field.StringField 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.StringField in project textdb by TextDB.
the class TwitterJsonConverterTest method getAllSampleTwitterTuples.
public static List<Tuple> getAllSampleTwitterTuples() 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(SchemaConstants._ID_ATTRIBUTE, new Attribute("twitterJson", AttributeType.STRING));
for (JsonNode tweet : jsonNode) {
Tuple tuple = new Tuple(tupleSourceSchema, IDField.newRandomID(), new StringField(tweet.toString()));
jsonStringTupleList.add(tuple);
}
// setup the twitter converter DAG
// TupleSource --> TwitterJsonConverter --> TupleSink
TupleSourceOperator tupleSource = new TupleSourceOperator(jsonStringTupleList, tupleSourceSchema);
TwitterJsonConverter twitterJsonConverter = new TwitterJsonConverterPredicate("twitterJson").newOperator();
TupleSink tupleSink = new TupleSinkPredicate(null, null).newOperator();
twitterJsonConverter.setInputOperator(tupleSource);
tupleSink.setInputOperator(twitterJsonConverter);
tupleSink.open();
List<Tuple> tuples = tupleSink.collectAllTuples();
tupleSink.close();
return tuples;
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class SampleExtraction method parsePromedHTML.
public static Tuple parsePromedHTML(String fileName, String content) {
try {
Document parsedDocument = Jsoup.parse(content);
String mainText = parsedDocument.getElementById("preview").text();
Tuple tuple = new Tuple(PromedSchema.PROMED_SCHEMA, new StringField(fileName), new TextField(mainText));
return tuple;
} catch (Exception e) {
return null;
}
}
use of edu.uci.ics.texera.api.field.StringField 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.field.StringField 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