Search in sources :

Example 11 with SelectStatement

use of edu.uci.ics.textdb.textql.statements.SelectStatement in project textdb by TextDB.

the class SelectStatementTest method testSettersAndGetters.

/**
     * Test the setter methods and the getter methods.
     * Call the setter of SelectStatement and test if the returned
     * value by the getter is the same.
     */
@Test
public void testSettersAndGetters() {
    ProjectPredicate projectPredicate;
    ExtractPredicate extractPredicate;
    SelectStatement selectExtractStatement = new SelectStatement();
    // Tests for the id attribute
    selectExtractStatement.setId(null);
    Assert.assertEquals(selectExtractStatement.getId(), null);
    selectExtractStatement.setId("idx");
    Assert.assertEquals(selectExtractStatement.getId(), "idx");
    selectExtractStatement.setId("_sid9");
    Assert.assertEquals(selectExtractStatement.getId(), "_sid9");
    // Tests for the projectPredicate attribute
    selectExtractStatement.setProjectPredicate(null);
    Assert.assertEquals(selectExtractStatement.getProjectPredicate(), null);
    projectPredicate = new ProjectAllFieldsPredicate();
    selectExtractStatement.setProjectPredicate(projectPredicate);
    Assert.assertEquals(selectExtractStatement.getProjectPredicate(), projectPredicate);
    projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("a", "b", "c"));
    selectExtractStatement.setProjectPredicate(projectPredicate);
    Assert.assertEquals(selectExtractStatement.getProjectPredicate(), projectPredicate);
    projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("f0", "f1"));
    selectExtractStatement.setProjectPredicate(projectPredicate);
    Assert.assertEquals(selectExtractStatement.getProjectPredicate(), projectPredicate);
    // Tests for the extractPredicate attribute
    selectExtractStatement.setExtractPredicate(null);
    Assert.assertEquals(selectExtractStatement.getExtractPredicate(), null);
    extractPredicate = new KeywordExtractPredicate(Arrays.asList("a", "c"), "search", KeywordMatchingType.PHRASE_INDEXBASED.toString());
    selectExtractStatement.setExtractPredicate(extractPredicate);
    Assert.assertEquals(selectExtractStatement.getExtractPredicate(), extractPredicate);
    extractPredicate = new KeywordExtractPredicate(Arrays.asList("u", "v"), "news", KeywordMatchingType.CONJUNCTION_INDEXBASED.toString());
    selectExtractStatement.setExtractPredicate(extractPredicate);
    Assert.assertEquals(selectExtractStatement.getExtractPredicate(), extractPredicate);
    // Tests for the fromClause attribute
    selectExtractStatement.setFromClause(null);
    Assert.assertEquals(selectExtractStatement.getFromClause(), null);
    selectExtractStatement.setFromClause("table");
    Assert.assertEquals(selectExtractStatement.getFromClause(), "table");
    selectExtractStatement.setFromClause("t3");
    Assert.assertEquals(selectExtractStatement.getFromClause(), "t3");
    // Tests for the limitClause attribute
    selectExtractStatement.setLimitClause(null);
    Assert.assertEquals(selectExtractStatement.getLimitClause(), null);
    selectExtractStatement.setLimitClause(0);
    Assert.assertEquals(selectExtractStatement.getLimitClause(), Integer.valueOf(0));
    selectExtractStatement.setLimitClause(5);
    Assert.assertEquals(selectExtractStatement.getLimitClause(), Integer.valueOf(5));
    selectExtractStatement.setLimitClause(-7);
    Assert.assertEquals(selectExtractStatement.getLimitClause(), Integer.valueOf(-7));
    // Tests for the offsetClause attribute
    selectExtractStatement.setOffsetClause(null);
    Assert.assertEquals(selectExtractStatement.getOffsetClause(), null);
    selectExtractStatement.setOffsetClause(0);
    Assert.assertEquals(selectExtractStatement.getOffsetClause(), Integer.valueOf(0));
    selectExtractStatement.setOffsetClause(-3);
    Assert.assertEquals(selectExtractStatement.getOffsetClause(), Integer.valueOf(-3));
    selectExtractStatement.setOffsetClause(58);
    Assert.assertEquals(selectExtractStatement.getOffsetClause(), Integer.valueOf(58));
}
Also used : SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) 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) ProjectSomeFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) Test(org.junit.Test)

Example 12 with SelectStatement

use of edu.uci.ics.textdb.textql.statements.SelectStatement in project textdb by TextDB.

the class SelectStatementTest method testSelectStatementBeansBuilder05.

/**
     * 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 testSelectStatementBeansBuilder05() {
    ProjectPredicate projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("a", "b"));
    ExtractPredicate extractPredicate = new KeywordExtractPredicate(Arrays.asList("a", "b"), "x", KeywordMatchingType.SUBSTRING_SCANBASED.toString());
    SelectStatement selectStatement = new SelectStatement("_sid4", projectPredicate, extractPredicate, "from", null, null);
    List<PredicateBase> expectedGeneratedBeans = Arrays.asList(new KeywordPredicate("x", Arrays.asList("a", "b"), null, KeywordMatchingType.SUBSTRING_SCANBASED, "_sid4_e"), 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.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) ProjectSomeFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) ProjectionPredicate(edu.uci.ics.textdb.exp.projection.ProjectionPredicate) KeywordPredicate(edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate) Test(org.junit.Test)

Example 13 with SelectStatement

use of edu.uci.ics.textdb.textql.statements.SelectStatement in project textdb by TextDB.

the class CreateViewStatementTest method testGettersAndGetters.

/**
     * Test the setter methods and the getter methods.
     * Call the setter of CreateViewStatement and test if the
     * returned value by the getter is the same.
     */
@Test
public void testGettersAndGetters() {
    Statement subStatement;
    ProjectPredicate projectPredicate;
    ExtractPredicate extractPredicate;
    CreateViewStatement createViewStatement = new CreateViewStatement(null, null);
    // Tests for the id attribute
    createViewStatement.setId(null);
    Assert.assertEquals(createViewStatement.getId(), null);
    createViewStatement.setId("statementId4");
    Assert.assertEquals(createViewStatement.getId(), "statementId4");
    createViewStatement.setId("_sid0");
    Assert.assertEquals(createViewStatement.getId(), "_sid0");
    // Tests for the subStatement attribute
    createViewStatement.setSubStatement(null);
    Assert.assertEquals(createViewStatement.getSubStatement(), null);
    projectPredicate = new ProjectAllFieldsPredicate();
    subStatement = new SelectStatement("substatementId0", projectPredicate, null, "from", null, null);
    createViewStatement = new CreateViewStatement("statementId", subStatement);
    Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
    projectPredicate = new ProjectAllFieldsPredicate();
    subStatement = new SelectStatement("substatementId1", projectPredicate, null, "table", null, null);
    createViewStatement = new CreateViewStatement("statementId", subStatement);
    Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
    projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("c", "d"));
    extractPredicate = new KeywordExtractPredicate(Arrays.asList("f0", "f1"), "xxx", KeywordMatchingType.PHRASE_INDEXBASED.toString());
    subStatement = new SelectStatement("id", projectPredicate, extractPredicate, "source", null, null);
    createViewStatement.setSubStatement(subStatement);
    Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
}
Also used : SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) CreateViewStatement(edu.uci.ics.textdb.textql.statements.CreateViewStatement) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) ExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate) Statement(edu.uci.ics.textdb.textql.statements.Statement) CreateViewStatement(edu.uci.ics.textdb.textql.statements.CreateViewStatement) SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectAllFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate) ProjectSomeFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) Test(org.junit.Test)

Example 14 with SelectStatement

use of edu.uci.ics.textdb.textql.statements.SelectStatement 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 15 with SelectStatement

use of edu.uci.ics.textdb.textql.statements.SelectStatement in project textdb by TextDB.

the class CreateViewStatementTest method testCreateViewStatementBeansBuilder01.

/**
     * Test the correctness of the generated beans by a CreateViewStatement with
     * a SelectExtractStatement as sub-statement with a
     * SelectSomeFieldsPredicate and a KeywordExtractPredicate.
     * Get a graph by calling getInternalOperatorBeans() 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 testCreateViewStatementBeansBuilder01() {
    ProjectPredicate projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("x", "y"));
    ExtractPredicate extractPredicate = new KeywordExtractPredicate(Arrays.asList("a", "b"), "zzz", KeywordMatchingType.SUBSTRING_SCANBASED.toString());
    Statement subStatement = new SelectStatement("id", projectPredicate, extractPredicate, "from", null, null);
    CreateViewStatement createViewStatement = new CreateViewStatement("idx", subStatement);
    List<PredicateBase> expectedGeneratedBeans = Collections.emptyList();
    List<String> dependencies = Arrays.asList(subStatement.getId());
    Assert.assertEquals(createViewStatement.getInputViews(), dependencies);
    StatementTestUtils.assertGeneratedBeans(createViewStatement, expectedGeneratedBeans);
}
Also used : SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) CreateViewStatement(edu.uci.ics.textdb.textql.statements.CreateViewStatement) 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) Statement(edu.uci.ics.textdb.textql.statements.Statement) CreateViewStatement(edu.uci.ics.textdb.textql.statements.CreateViewStatement) SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ProjectSomeFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate) Test(org.junit.Test)

Aggregations

SelectStatement (edu.uci.ics.textdb.textql.statements.SelectStatement)16 Test (org.junit.Test)16 ProjectPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate)13 ExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate)12 KeywordExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate)12 ProjectSomeFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate)11 ProjectAllFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate)10 PredicateBase (edu.uci.ics.textdb.exp.common.PredicateBase)8 CreateViewStatement (edu.uci.ics.textdb.textql.statements.CreateViewStatement)8 Statement (edu.uci.ics.textdb.textql.statements.Statement)8 TextQLParser (edu.uci.ics.textdb.textql.languageparser.TextQLParser)4 KeywordPredicate (edu.uci.ics.textdb.exp.keywordmatcher.KeywordPredicate)3 ProjectionPredicate (edu.uci.ics.textdb.exp.projection.ProjectionPredicate)2 ParseException (edu.uci.ics.textdb.textql.languageparser.ParseException)1 TokenMgrError (edu.uci.ics.textdb.textql.languageparser.TokenMgrError)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 PrintStream (java.io.PrintStream)1