use of edu.uci.ics.texera.api.field.IField 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();
}
use of edu.uci.ics.texera.api.field.IField in project textdb by TextDB.
the class MedlineIndexWriter method recordToTuple.
public static Tuple recordToTuple(String record) throws IOException, ParseException {
JsonNode jsonNode = new ObjectMapper().readValue(record, JsonNode.class);
ArrayList<IField> fieldList = new ArrayList<IField>();
for (Attribute attr : ATTRIBUTES_MEDLINE) {
fieldList.add(StorageUtils.getField(attr.getType(), jsonNode.get(attr.getName()).toString()));
}
IField[] fieldArray = new IField[fieldList.size()];
Tuple tuple = new Tuple(SCHEMA_MEDLINE, fieldList.toArray(fieldArray));
return tuple;
}
use of edu.uci.ics.texera.api.field.IField in project textdb by TextDB.
the class DataReader method documentToFields.
private ArrayList<IField> documentToFields(Document luceneDocument) throws ParseException {
ArrayList<IField> fields = new ArrayList<>();
for (Attribute attr : inputSchema.getAttributes()) {
AttributeType attributeType = attr.getType();
String fieldValue = luceneDocument.get(attr.getName());
fields.add(StorageUtils.getField(attributeType, fieldValue));
}
return fields;
}
use of edu.uci.ics.texera.api.field.IField in project textdb by TextDB.
the class RelationManager method getTableAnalyzerString.
/**
* Gets the Lucene analyzer string of a table.
*
* @param tableName, the name of the table, case insensitive
* @return
* @throws StorageException
*/
public String getTableAnalyzerString(String tableName) throws StorageException {
// get the tuples with tableName from the table catalog
Tuple tableCatalogTuple = getTableCatalogTuple(tableName);
// if the tuple is not found, then the table name is not found
if (tableCatalogTuple == null) {
throw new StorageException(String.format("The analyzer for table %s is not found.", tableName));
}
// get the lucene analyzer string
IField analyzerField = tableCatalogTuple.getField(CatalogConstants.TABLE_LUCENE_ANALYZER);
String analyzerString = analyzerField.getValue().toString();
return analyzerString;
}
use of edu.uci.ics.texera.api.field.IField in project textdb by TextDB.
the class WordCountIndexSource method computeNextMatchingTuple.
private Tuple computeNextMatchingTuple() throws TexeraException {
if (sortedWordCountMap == null) {
computeWordCount();
}
if (wordCountIterator.hasNext()) {
Entry<String, Integer> entry = wordCountIterator.next();
List<IField> tupleFieldList = new ArrayList<>();
// Generate the new UUID.
tupleFieldList.add(IDField.newRandomID());
tupleFieldList.add(new StringField(entry.getKey()));
tupleFieldList.add(new IntegerField(entry.getValue()));
cursor++;
return new Tuple(SCHEMA_WORD_COUNT, tupleFieldList);
}
return null;
}
Aggregations