use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class JoinDistanceTest method testOffsetGreaterThanNumberOfResults.
/*
* This case tests for the scenario when offset is some integer greater
* than 0 and greater than the actual number of results and join is
* performed.
* Test result: An empty list.
*/
@Test
public void testOffsetGreaterThanNumberOfResults() throws Exception {
List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
List<Tuple> resultList = JoinTestHelper.getJoinDistanceResults(keywordSourceInner, keywordSourceOuter, new JoinDistancePredicate(JoinTestConstants.REVIEW, 90), 1, 10);
Assert.assertEquals(0, resultList.size());
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class JoinTestHelper method insertToTable.
public static void insertToTable(String tableName, Tuple... tuples) throws StorageException {
RelationManager relationManager = RelationManager.getInstance();
DataWriter tableDataWriter = relationManager.getTableDataWriter(tableName);
tableDataWriter.open();
for (Tuple tuple : Arrays.asList(tuples)) {
tableDataWriter.insertTuple(tuple);
}
tableDataWriter.close();
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class JoinTestHelper method alterField.
/**
* Alter a field of a tuple. ( The schema will also be changed accordingly. )
* @param originalTuple
* @param fieldIndex
* @param newField
* @return
*/
public static Tuple alterField(Tuple originalTuple, int fieldIndex, IField newField) {
List<Attribute> originalAttributes = originalTuple.getSchema().getAttributes();
List<Attribute> newAttributes = new ArrayList<>();
List<IField> newFields = new ArrayList<>();
for (int i = 0; i < originalAttributes.size(); i++) {
if (i == fieldIndex) {
newAttributes.add(new Attribute(originalAttributes.get(i).getName(), AttributeType.getAttributeType(newField.getClass())));
newFields.add(newField);
} else {
newAttributes.add(originalAttributes.get(i));
newFields.add(originalTuple.getFields().get(i));
}
}
return new Tuple(new Schema(newAttributes.stream().toArray(Attribute[]::new)), newFields.stream().toArray(IField[]::new));
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class KeywordConjunctionTest method testSingleWordQueryInTextFieldChinese.
/**
* Verifies GetNextTuple of Keyword Matcher and single word queries in Text
* Field using Chinese.
*
* @throws Exception
*/
@Test
public void testSingleWordQueryInTextFieldChinese() throws Exception {
// Prepare the query
String query = "北京大学";
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstantsChinese.FIRST_NAME);
attributeNames.add(TestConstantsChinese.LAST_NAME);
attributeNames.add(TestConstantsChinese.DESCRIPTION);
// Prepare the expected result list
List<Span> list = new ArrayList<>();
Span span = new Span("description", 0, 4, "北京大学", "北京大学", 0);
list.add(span);
Attribute[] schemaAttributes = new Attribute[TestConstantsChinese.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstantsChinese.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
IField[] fields1 = { new StringField("无忌"), new StringField("长孙"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("北京大学电气工程学院"), new ListField<>(list) };
IField[] fields2 = { new StringField("孔明"), new StringField("洛克贝尔"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("北京大学计算机学院"), new ListField<>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
List<Tuple> expectedResultList = new ArrayList<>();
expectedResultList.add(tuple1);
expectedResultList.add(tuple2);
// Perform the query
List<Tuple> resultList = KeywordTestHelper.getQueryResults(CHINESE_TABLE, query, attributeNames, conjunction, Integer.MAX_VALUE, 0);
// check the results
boolean contains = TestUtils.equals(expectedResultList, resultList);
Assert.assertTrue(contains);
}
use of edu.uci.ics.texera.api.tuple.Tuple in project textdb by TextDB.
the class KeywordConjunctionTest method testMatchingWithLimit.
@Test
public void testMatchingWithLimit() throws TexeraException, ParseException, java.text.ParseException {
String query = "angry";
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.DESCRIPTION);
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] = new Attribute(RESULTS, AttributeType.LIST);
List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, conjunction, 3, 0);
List<Tuple> expectedList = new ArrayList<>();
Span span1 = new Span("description", 5, 10, "angry", "Angry", 1);
Span span2 = new Span("description", 6, 11, "angry", "Angry", 1);
Span span3 = new Span("description", 40, 45, "angry", "Angry", 8);
Span span4 = new Span("description", 6, 11, "angry", "angry", 1);
List<Span> list1 = new ArrayList<>();
list1.add(span1);
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<>(list1) };
List<Span> list2 = new ArrayList<>();
list2.add(span2);
IField[] fields2 = { new StringField("brad lie angelina"), new StringField("pitt"), new IntegerField(44), new DoubleField(6.10), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-12-1972")), new TextField("White Angry"), new ListField<>(list2) };
List<Span> list3 = new ArrayList<>();
list3.add(span3);
IField[] fields3 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is Angry"), new ListField<>(list3) };
List<Span> list4 = new ArrayList<>();
list4.add(span4);
IField[] fields4 = { new StringField("Mary brown"), new StringField("Lake Forest"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Short angry"), new ListField<>(list4) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
Tuple tuple3 = new Tuple(new Schema(schemaAttributes), fields3);
Tuple tuple4 = new Tuple(new Schema(schemaAttributes), fields4);
expectedList.add(tuple1);
expectedList.add(tuple2);
expectedList.add(tuple3);
expectedList.add(tuple4);
Assert.assertEquals(expectedList.size(), 4);
Assert.assertEquals(resultList.size(), 3);
Assert.assertTrue(TestUtils.containsAll(expectedList, resultList));
}
Aggregations