Search in sources :

Example 1 with ProjectionPredicate

use of edu.uci.ics.texera.dataflow.projection.ProjectionPredicate in project textdb by TextDB.

the class SelectStatementTest method testSelectStatementBeansBuilder02.

/**
 * Test the correctness of the generated beans by a SelectStatement with a
 * ProjectSomeFieldsPredicate.
 * Get a graph by calling getInternalPredicateBases() and getInternalLinkBeans()
 * methods and check if the generated path form the node getInputNodeID() to
 * the node getOutputNodeID() is correct. Also check whether getInputViews()
 * is returning the correct dependencies.
 */
@Test
public void testSelectStatementBeansBuilder02() {
    ProjectPredicate projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("a", "b"));
    SelectStatement selectStatement = new SelectStatement("idX", projectPredicate, null, "from", null, null);
    List<PredicateBase> expectedGeneratedBeans = Arrays.asList(new ProjectionPredicate(Arrays.asList("a", "b")));
    List<String> dependencies = Arrays.asList("from");
    Assert.assertEquals(selectStatement.getInputViews(), dependencies);
    StatementTestUtils.assertGeneratedBeans(selectStatement, expectedGeneratedBeans);
}
Also used : SelectStatement(edu.uci.ics.texera.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectPredicate) PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) ProjectSomeFieldsPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectSomeFieldsPredicate) ProjectionPredicate(edu.uci.ics.texera.dataflow.projection.ProjectionPredicate) Test(org.junit.Test)

Example 2 with ProjectionPredicate

use of edu.uci.ics.texera.dataflow.projection.ProjectionPredicate in project textdb by TextDB.

the class ProjectSomeFieldsPredicateTest method testGenerateOperatorBean02.

/**
 * Test the generateOperatorBean method.
 * Build a SelectSomeFieldsPredicate, invoke the generateOperatorBean and check
 * whether a ProjectionBean with the right attributes is returned.
 * A list with some unordered field names is used as the list of projected fields.
 */
@Test
public void testGenerateOperatorBean02() {
    String operatorId = "op00";
    List<String> projectedFields = Arrays.asList("c", "a", "b");
    ProjectSomeFieldsPredicate projectSomeFieldsPredicate = new ProjectSomeFieldsPredicate(projectedFields);
    PredicateBase computedProjectionBean = projectSomeFieldsPredicate.generateOperatorBean(operatorId);
    PredicateBase expectedProjectionBean = new ProjectionPredicate(Arrays.asList("c", "a", "b"));
    expectedProjectionBean.setID(operatorId);
    Assert.assertEquals(expectedProjectionBean, computedProjectionBean);
}
Also used : PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) ProjectionPredicate(edu.uci.ics.texera.dataflow.projection.ProjectionPredicate) Test(org.junit.Test)

Example 3 with ProjectionPredicate

use of edu.uci.ics.texera.dataflow.projection.ProjectionPredicate in project textdb by TextDB.

the class ProjectSomeFieldsPredicateTest method testGenerateOperatorBean01.

/**
 * Test the generateOperatorBean method.
 * Build a SelectSomeFieldsPredicate, invoke the generateOperatorBean and check
 * whether a ProjectionBean with the right attributes is returned.
 * A list with some field names is used as the list of projected fields.
 */
@Test
public void testGenerateOperatorBean01() {
    String operatorId = "zwx";
    List<String> projectedFields = Arrays.asList("field0", "field1");
    ProjectSomeFieldsPredicate projectSomeFieldsPredicate = new ProjectSomeFieldsPredicate(projectedFields);
    PredicateBase computedProjectionBean = projectSomeFieldsPredicate.generateOperatorBean(operatorId);
    PredicateBase expectedProjectionBean = new ProjectionPredicate(Arrays.asList("field0", "field1"));
    expectedProjectionBean.setID(operatorId);
    Assert.assertEquals(expectedProjectionBean, computedProjectionBean);
}
Also used : PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) ProjectionPredicate(edu.uci.ics.texera.dataflow.projection.ProjectionPredicate) Test(org.junit.Test)

Example 4 with ProjectionPredicate

use of edu.uci.ics.texera.dataflow.projection.ProjectionPredicate in project textdb by TextDB.

the class OneToNBroadcastConnectorTest method testTwoOutputsWithProjection.

/*
     * This test connects Connector with Projection
     */
@Test
public void testTwoOutputsWithProjection() throws TexeraException {
    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));
}
Also used : ProjectionOperator(edu.uci.ics.texera.dataflow.projection.ProjectionOperator) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IField(edu.uci.ics.texera.api.field.IField) ProjectionPredicate(edu.uci.ics.texera.dataflow.projection.ProjectionPredicate) ScanBasedSourceOperator(edu.uci.ics.texera.dataflow.source.scan.ScanBasedSourceOperator) TextField(edu.uci.ics.texera.api.field.TextField) ScanSourcePredicate(edu.uci.ics.texera.dataflow.source.scan.ScanSourcePredicate) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 5 with ProjectionPredicate

use of edu.uci.ics.texera.dataflow.projection.ProjectionPredicate in project textdb by TextDB.

the class JoinDistanceTest method testOneOfTheOperatorResultContainsNoSpan.

// This case tests for the scenario when one of the operators result lists has no span.
// If one of the operators doesn't have span, then an exception will be thrown.
// Test result: DataflowException is thrown
@Test(expected = DataflowException.class)
public void testOneOfTheOperatorResultContainsNoSpan() throws Exception {
    JoinTestHelper.insertToTable(BOOK_TABLE, JoinTestConstants.bookGroup1.get(0));
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "special", conjunction);
    String fuzzyTokenQuery = "this writer writes well";
    double thresholdRatio = 0.25;
    List<String> textAttributeNames = JoinTestConstants.BOOK_SCHEMA.getAttributes().stream().filter(attr -> attr.getType() != AttributeType.TEXT).map(Attribute::getName).collect(Collectors.toList());
    FuzzyTokenSourcePredicate fuzzySourcePredicateInner = new FuzzyTokenSourcePredicate(fuzzyTokenQuery, textAttributeNames, LuceneAnalyzerConstants.standardAnalyzerString(), thresholdRatio, BOOK_TABLE, SchemaConstants.SPAN_LIST);
    FuzzyTokenMatcherSourceOperator fuzzyMatcherInner = new FuzzyTokenMatcherSourceOperator(fuzzySourcePredicateInner);
    ProjectionPredicate removeSpanListPredicate = new ProjectionPredicate(JoinTestConstants.BOOK_SCHEMA.getAttributeNames());
    ProjectionOperator removeSpanListProjection = new ProjectionOperator(removeSpanListPredicate);
    removeSpanListProjection.setInputOperator(fuzzyMatcherInner);
    JoinTestHelper.getJoinDistanceResults(keywordSourceOuter, removeSpanListProjection, new JoinDistancePredicate(JoinTestConstants.REVIEW, 20), Integer.MAX_VALUE, 0);
}
Also used : FuzzyTokenMatcherSourceOperator(edu.uci.ics.texera.dataflow.fuzzytokenmatcher.FuzzyTokenMatcherSourceOperator) ProjectionOperator(edu.uci.ics.texera.dataflow.projection.ProjectionOperator) FuzzyTokenSourcePredicate(edu.uci.ics.texera.dataflow.fuzzytokenmatcher.FuzzyTokenSourcePredicate) ProjectionPredicate(edu.uci.ics.texera.dataflow.projection.ProjectionPredicate) JoinDistancePredicate(edu.uci.ics.texera.dataflow.join.JoinDistancePredicate) KeywordMatcherSourceOperator(edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Aggregations

ProjectionPredicate (edu.uci.ics.texera.dataflow.projection.ProjectionPredicate)9 Test (org.junit.Test)8 PredicateBase (edu.uci.ics.texera.dataflow.common.PredicateBase)5 ProjectionOperator (edu.uci.ics.texera.dataflow.projection.ProjectionOperator)2 SelectStatement (edu.uci.ics.texera.textql.statements.SelectStatement)2 ProjectPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectPredicate)2 ProjectSomeFieldsPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectSomeFieldsPredicate)2 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)1 IField (edu.uci.ics.texera.api.field.IField)1 TextField (edu.uci.ics.texera.api.field.TextField)1 Schema (edu.uci.ics.texera.api.schema.Schema)1 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1 FuzzyTokenMatcherSourceOperator (edu.uci.ics.texera.dataflow.fuzzytokenmatcher.FuzzyTokenMatcherSourceOperator)1 FuzzyTokenSourcePredicate (edu.uci.ics.texera.dataflow.fuzzytokenmatcher.FuzzyTokenSourcePredicate)1 JoinDistancePredicate (edu.uci.ics.texera.dataflow.join.JoinDistancePredicate)1 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)1 KeywordPredicate (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordPredicate)1 ScanBasedSourceOperator (edu.uci.ics.texera.dataflow.source.scan.ScanBasedSourceOperator)1 ScanSourcePredicate (edu.uci.ics.texera.dataflow.source.scan.ScanSourcePredicate)1 ExtractPredicate (edu.uci.ics.texera.textql.statements.predicates.ExtractPredicate)1