Search in sources :

Example 11 with PredicateBase

use of edu.uci.ics.textdb.exp.common.PredicateBase 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.textdb.exp.common.PredicateBase) ProjectionPredicate(edu.uci.ics.textdb.exp.projection.ProjectionPredicate) Test(org.junit.Test)

Example 12 with PredicateBase

use of edu.uci.ics.textdb.exp.common.PredicateBase in project textdb by TextDB.

the class SelectStatement method getInternalOperatorBeans.

/**
     * Return a list of operators generated when this statement is converted to beans.
     * Beans will be generated for the Alias, Projection, Extraction and Source operators.
     * @return The list of operator beans generated by this statement.
     */
@Override
public List<PredicateBase> getInternalOperatorBeans() {
    List<PredicateBase> operators = new ArrayList<>();
    // Build and append a PassThroughBean as an alias for this Statement
    operators.add(new PassThroughPredicate(getOutputNodeID()));
    // Build and append bean for Projection
    if (this.projectPredicate == null) {
        operators.add(new PassThroughPredicate(getProjectionNodeID()));
    } else {
        operators.add(this.projectPredicate.generateOperatorBean(getProjectionNodeID()));
    }
    // Build and append bean for Extraction predicate
    if (this.extractPredicate == null) {
        operators.add(new PassThroughPredicate(getExtractionNodeID()));
    } else {
        operators.add(this.extractPredicate.generateOperatorBean(getExtractionNodeID()));
    }
    // Build and append bean for the Source
    operators.add(new PassThroughPredicate(getInputNodeID()));
    // return the built operators
    return operators;
}
Also used : PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) PassThroughPredicate(edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate) ArrayList(java.util.ArrayList)

Example 13 with PredicateBase

use of edu.uci.ics.textdb.exp.common.PredicateBase in project textdb by TextDB.

the class SelectStatementTest method testSelectStatementBeansBuilder04.

/**
     * Test the correctness of the generated beans by a SelectStatement with a
     * ProjectAllFieldsPredicate and a KeywordExtractPredicate.
     * 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 testSelectStatementBeansBuilder04() {
    ProjectPredicate projectPredicate = new ProjectAllFieldsPredicate();
    ExtractPredicate extractPredicate = new KeywordExtractPredicate(Arrays.asList("f1"), "keyword", KeywordMatchingType.CONJUNCTION_INDEXBASED.toString());
    SelectStatement selectStatement = new SelectStatement("id", projectPredicate, extractPredicate, "source", null, null);
    List<PredicateBase> expectedGeneratedBeans = Arrays.asList(new KeywordPredicate("keyword", Arrays.asList("f1"), null, KeywordMatchingType.CONJUNCTION_INDEXBASED, "id_e"));
    List<String> dependencies = Arrays.asList("source");
    Assert.assertEquals(selectStatement.getInputViews(), dependencies);
    StatementTestUtils.assertGeneratedBeans(selectStatement, expectedGeneratedBeans);
}
Also used : SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) ExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate) ProjectAllFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Example 14 with PredicateBase

use of edu.uci.ics.textdb.exp.common.PredicateBase in project textdb by TextDB.

the class KeywordExtractPredicateTest method testGeneratePredicateBase02.

/**
     * Test the generatePredicateBase method.
     * Build a KeywordExtractPredicate, invoke the generatePredicateBase and
     * check whether a KeywordMatcherBean with the right attributes is returned.
     * A list with some fields is used as the list of fields to perform the match.
     */
@Test
public void testGeneratePredicateBase02() {
    String operatorId = "keywordExtract00";
    List<String> matchingFields = Arrays.asList("field0", "field1");
    String keywords = "xxx";
    String matchingType = KeywordMatchingType.SUBSTRING_SCANBASED.toString();
    KeywordExtractPredicate keywordExtractPredicate = new KeywordExtractPredicate(matchingFields, keywords, matchingType);
    PredicateBase computedProjectionBean = keywordExtractPredicate.generateOperatorBean(operatorId);
    PredicateBase expectedProjectionBean = new KeywordPredicate(keywords, matchingFields, null, KeywordMatchingType.fromName(matchingType), operatorId);
    expectedProjectionBean.setID(operatorId);
    Assert.assertEquals(expectedProjectionBean, computedProjectionBean);
}
Also used : PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Example 15 with PredicateBase

use of edu.uci.ics.textdb.exp.common.PredicateBase in project textdb by TextDB.

the class KeywordExtractPredicateTest method testGeneratePredicateBase00.

/**
     * Test the generatePredicateBase method.
     * Build a KeywordExtractPredicate, invoke the generatePredicateBase and
     * check whether a KeywordMatcherBean with the right attributes is returned.
     * An empty list is used as the list of fields to perform the match.
     */
@Test
public void testGeneratePredicateBase00() {
    String operatorId = "xxx";
    List<String> matchingFields = Collections.emptyList();
    String keywords = "keyword";
    String matchingType = KeywordMatchingType.CONJUNCTION_INDEXBASED.toString();
    KeywordExtractPredicate keywordExtractPredicate = new KeywordExtractPredicate(matchingFields, keywords, matchingType);
    PredicateBase computedProjectionBean = keywordExtractPredicate.generateOperatorBean(operatorId);
    PredicateBase expectedProjectionBean = new KeywordPredicate(keywords, matchingFields, null, KeywordMatchingType.fromName(matchingType), operatorId);
    expectedProjectionBean.setID(operatorId);
    Assert.assertEquals(expectedProjectionBean, computedProjectionBean);
}
Also used : PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Aggregations

PredicateBase (edu.uci.ics.textdb.exp.common.PredicateBase)17 Test (org.junit.Test)15 SelectStatement (edu.uci.ics.textdb.textql.statements.SelectStatement)8 KeywordPredicate (edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate)6 ProjectionPredicate (edu.uci.ics.textdb.exp.projection.ProjectionPredicate)5 ProjectPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate)5 ExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate)4 KeywordExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate)4 PassThroughPredicate (edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate)3 Statement (edu.uci.ics.textdb.textql.statements.Statement)3 ProjectSomeFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate)3 CreateViewStatement (edu.uci.ics.textdb.textql.statements.CreateViewStatement)2 ProjectAllFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate)2 OperatorLink (edu.uci.ics.textdb.exp.plangen.OperatorLink)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assert (org.junit.Assert)1