use of edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator in project textdb by TextDB.
the class SamplerTest method matchSamplerTable.
/*
* To test if the sampled tuples are equal to the first K tuples of the sampler table
* in both the order and content.
*/
public static boolean matchSamplerTable(List<Tuple> sampleList) throws TextDBException {
ScanBasedSourceOperator scanSource = new ScanBasedSourceOperator(new ScanSourcePredicate(SAMPLER_TABLE));
scanSource.open();
ListIterator<Tuple> iter = null;
iter = sampleList.listIterator();
while (iter.hasNext()) {
Tuple nextTableTuple = scanSource.getNextTuple();
Tuple nextSampledTuple = iter.next();
if (!nextSampledTuple.equals(nextTableTuple)) {
scanSource.close();
return false;
}
}
scanSource.close();
return true;
}
use of edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator in project textdb by TextDB.
the class WordCountTest method computePayLoadWordCount.
//Compute result by tuple's PayLoad.
public static HashMap<String, Integer> computePayLoadWordCount(String tableName, String attribute) throws TextDBException {
ScanBasedSourceOperator scanSource = new ScanBasedSourceOperator(new ScanSourcePredicate(tableName));
WordCountOperator wordCount = null;
HashMap<String, Integer> result = new HashMap<String, Integer>();
if (tableName.equals(COUNT_TABLE)) {
wordCount = new WordCountOperator(new WordCountOperatorPredicate(TestConstants.DESCRIPTION, LuceneAnalyzerConstants.standardAnalyzerString()));
} else if (tableName.equals(COUNT_CHINESE_TABLE)) {
wordCount = new WordCountOperator(new WordCountOperatorPredicate(TestConstantsChineseWordCount.DESCRIPTION, LuceneAnalyzerConstants.chineseAnalyzerString()));
}
wordCount.setInputOperator(scanSource);
wordCount.open();
Tuple tuple;
while ((tuple = wordCount.getNextTuple()) != null) {
result.put((String) tuple.getField(WordCountOperator.WORD).getValue(), (Integer) tuple.getField(WordCountOperator.COUNT).getValue());
}
wordCount.close();
return result;
}
use of edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator in project textdb by TextDB.
the class ScanBasedSourceOperatorTest method testFlow.
@Test
public void testFlow() throws TextDBException, ParseException {
List<Tuple> actualTuples = TestConstants.getSamplePeopleTuples();
ScanBasedSourceOperator scanBasedSourceOperator = new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE));
scanBasedSourceOperator.open();
Tuple nextTuple = null;
int numTuples = 0;
List<Tuple> returnedTuples = new ArrayList<Tuple>();
while ((nextTuple = scanBasedSourceOperator.getNextTuple()) != null) {
returnedTuples.add(nextTuple);
numTuples++;
}
Assert.assertEquals(actualTuples.size(), numTuples);
boolean contains = TestUtils.equals(actualTuples, returnedTuples);
Assert.assertTrue(contains);
scanBasedSourceOperator.close();
}
use of edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator in project textdb by TextDB.
the class OneToNBroadcastConnectorTest method testTwoOutputsWithProjection.
/*
* This test connects Connector with Projection
*/
@Test
public void testTwoOutputsWithProjection() throws TextDBException {
IOperator sourceOperator = new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE));
List<String> projectionFields = Arrays.asList(TestConstants.DESCRIPTION);
Schema projectionSchema = new Schema(TestConstants.DESCRIPTION_ATTR);
IField[] fields1 = { new TextField("Tall Angry") };
IField[] fields2 = { new TextField("Short Brown") };
IField[] fields3 = { new TextField("White Angry") };
IField[] fields4 = { new TextField("Lin Clooney is Short and lin clooney is Angry") };
IField[] fields5 = { new TextField("Tall Fair") };
IField[] fields6 = { new TextField("Short angry") };
Tuple tuple1 = new Tuple(projectionSchema, fields1);
Tuple tuple2 = new Tuple(projectionSchema, fields2);
Tuple tuple3 = new Tuple(projectionSchema, fields3);
Tuple tuple4 = new Tuple(projectionSchema, fields4);
Tuple tuple5 = new Tuple(projectionSchema, fields5);
Tuple tuple6 = new Tuple(projectionSchema, fields6);
List<Tuple> expectedResults = Arrays.asList(tuple1, tuple2, tuple3, tuple4, tuple5, tuple6);
ProjectionPredicate projectionPredicate = new ProjectionPredicate(projectionFields);
ProjectionOperator projection1 = new ProjectionOperator(projectionPredicate);
ProjectionOperator projection2 = new ProjectionOperator(projectionPredicate);
OneToNBroadcastConnector connector = new OneToNBroadcastConnector(2);
connector.setInputOperator(sourceOperator);
projection1.setInputOperator(connector.getOutputOperator(0));
projection2.setInputOperator(connector.getOutputOperator(1));
projection1.open();
List<Tuple> projection1Results = new ArrayList<>();
Tuple nextTuple = null;
while ((nextTuple = projection1.getNextTuple()) != null) {
projection1Results.add(nextTuple);
}
projection1.close();
projection2.open();
List<Tuple> projection2Results = new ArrayList<>();
nextTuple = null;
while ((nextTuple = projection2.getNextTuple()) != null) {
projection2Results.add(nextTuple);
}
projection2.close();
Assert.assertTrue(TestUtils.equals(expectedResults, projection1Results));
Assert.assertTrue(TestUtils.equals(expectedResults, projection2Results));
Assert.assertTrue(TestUtils.equals(projection1Results, projection2Results));
}
use of edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator in project textdb by TextDB.
the class ComparableMatcherTest method setDefaultMatcherConfig.
public void setDefaultMatcherConfig(ComparableMatcher comparableMatcher) throws TextDBException {
// Perform the query
ScanBasedSourceOperator sourceOperator = new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE));
comparableMatcher.setInputOperator(sourceOperator);
comparableMatcher.open();
comparableMatcher.setLimit(Integer.MAX_VALUE);
comparableMatcher.setOffset(0);
}
Aggregations