Search in sources :

Example 1 with Statement

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

the class StatementTestUtils method assertGeneratedBeans.

/**
     * Assert the generated beans by a statement are a valid direct acyclic graph (no cycles nor unreached nodes/links 
     * are present) and that the given list of operators are present in the right order in the path from the initial 
     * node to the final node (while ignoring the PassThroughBean and the value of the ID).
     * The following checks are performed:
     * -Check whether all the build operators have unique IDs (between them).
     * -Check whether the generated links are unique (no duplicate links).
     * -Check whether a path from the initial to the final node exists.
     * -Check whether all the operators in the path between the initial and the final node is are present in
     *     expectedOperators in the same order (ignoring the PassThroughBean)
     * -Check whether all the links connect existing operators.
     * -Check whether all the operator beans are visited once at most (no cycles).
     * -Check whether all the link beans are visited once at most (no cycles).
     * -Check whether all the operators, except for the final operator, have output arity equals to one.
     * -Check whether all the operators beans generated are reachable.
     * -Check whether all the link beans generated are reachable.
     * 
     * @param statement The statement to build the beans to be checked.
     * @param expectedOperators The list of the expected OperatorBeans to be build by the statement.
     */
public static void assertGeneratedBeans(Statement statement, List<PredicateBase> expectedOperators) {
    // Get operators and links from statement
    List<PredicateBase> operators = statement.getInternalOperatorBeans();
    List<OperatorLink> links = statement.getInternalLinkBeans();
    // Assert all statements have an unique id (check whether two operators have the same ID)
    boolean uniqueIds = operators.stream().collect(Collectors.groupingBy(op -> op.getID(), Collectors.counting())).values().stream().allMatch(count -> (count == 1));
    Assert.assertTrue(uniqueIds);
    // Iterate the graph (string of nodes) to look for the expected beans
    HashSet<PredicateBase> visitedOperators = new HashSet<>();
    HashSet<OperatorLink> visitedLinks = new HashSet<>();
    String initialNode = statement.getInputNodeID();
    String finalNode = statement.getOutputNodeID();
    Iterator<PredicateBase> expectedOperatorsIterator = expectedOperators.iterator();
    PredicateBase nextExpectedOperator = null;
    // Start from the initial node and stop when the final node is reached (or an Assert fail)
    String currentBeanId = initialNode;
    while (true) {
        // Get the next expected operator to find (if needed)
        if (nextExpectedOperator == null && expectedOperatorsIterator.hasNext()) {
            nextExpectedOperator = expectedOperatorsIterator.next();
        }
        // Get the current bean by ID
        String currentLookingBeanId = currentBeanId;
        PredicateBase currentOperatorBean = operators.stream().filter(op -> op.getID().equals(currentLookingBeanId)).findAny().orElse(null);
        Assert.assertNotNull(currentOperatorBean);
        // Add the current visited bean to the set of visited beans and assert it hasn't been visited yet (cycle check)
        Assert.assertTrue(visitedOperators.add(currentOperatorBean));
        // Compare the current bean with the next expected bean
        if (nextExpectedOperator != null && currentOperatorBean.getClass() == nextExpectedOperator.getClass()) {
            // Copy the id of the current bean to the bean we are looking for and assert they are equal
            nextExpectedOperator.setID(currentOperatorBean.getID());
            Assert.assertEquals(nextExpectedOperator, currentOperatorBean);
            nextExpectedOperator = null;
        } else if (!(currentOperatorBean instanceof PassThroughPredicate)) {
            // Found a bean that is not PassThrough and is not the expected operator!
            Assert.fail();
        }
        // Break once the final node is visited
        if (currentBeanId.equals(finalNode)) {
            break;
        }
        // Get outgoing links for the current bean
        List<OperatorLink> currentOperatorBeanOutgoingLinks = links.stream().filter(link -> link.getOrigin().equals(currentOperatorBean.getID())).collect(Collectors.toList());
        // Assert there is only one outgoing link
        Assert.assertEquals(currentOperatorBeanOutgoingLinks.size(), 1);
        OperatorLink currentOperatorBeanOutgoingLink = currentOperatorBeanOutgoingLinks.get(0);
        // Add the outgoing link to the set of visited links and assert it hasn't been visited yet (cycle and duplicate check)
        Assert.assertTrue(visitedLinks.add(currentOperatorBeanOutgoingLink));
        // Set the current bean id to the next bean
        currentBeanId = currentOperatorBeanOutgoingLink.getDestination();
    }
    // Assert there are no more expected operators to look for
    Assert.assertFalse(expectedOperatorsIterator.hasNext());
    // Assert all the operators generated by the statement are visited (no unreachable operators)
    Assert.assertTrue(visitedOperators.containsAll(operators));
    // Assert all the links generated by the statement are visited (no unreachable links)
    Assert.assertTrue(visitedLinks.containsAll(links));
}
Also used : HashSet(java.util.HashSet) List(java.util.List) OperatorLink(edu.uci.ics.textdb.exp.plangen.OperatorLink) Iterator(java.util.Iterator) Statement(edu.uci.ics.textdb.textql.statements.Statement) Assert(org.junit.Assert) PassThroughPredicate(edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate) Collectors(java.util.stream.Collectors) PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) OperatorLink(edu.uci.ics.textdb.exp.plangen.OperatorLink) PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) PassThroughPredicate(edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate) HashSet(java.util.HashSet)

Example 2 with Statement

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

the class TextQLParserTest method testStatementsMain.

/**
     * Test the statementsMain method of the parser.
     * It should parse a list of statements and return the expected list
     * of Statement object and provide the Statements to the consumer.
     * @throws ParseException if an unexpected ParseException is thrown
     */
@Test
public void testStatementsMain() throws ParseException {
    //Declaration of multiple statements for testing
    String SelectStatement00 = "SELECT * FROM a;";
    String SelectStatement13 = "SELECT h, i, j, KEYWORDMATCH([h6,h7,k8,k9], \"key5\") FROM q LIMIT 5 OFFSET 6;";
    String SelectStatement14 = "SELECT KEYWORDMATCH(i6, \"key5\") FROM q;";
    String createViewStatement00 = " CREATE VIEW v0 AS SELECT * FROM a; ";
    String createViewStatement01 = " CREATE VIEW v1 AS SELECT f8, fa, fc, df, ff FROM j LIMIT 1 OFFSET 8; ";
    String createViewStatement02 = " CREATE VIEW v2 AS SELECT e, KEYWORDMATCH([g4,g5], \"key0\") FROM o ;";
    String createViewStatement03 = " CREATE VIEW v2 AS SELECT KEYWORDMATCH([g4,g5], \"key0\", substring) FROM o ;";
    //Example of statement objects used for testing
    ProjectPredicate SelectStatementSelect00 = new ProjectAllFieldsPredicate();
    //Statement SelectStatementParameters00 = new SelectStatement("_sid0", , null, "a", null, null);
    ProjectPredicate SelectStatementSelect13 = new ProjectSomeFieldsPredicate(Arrays.asList("h", "i", "j"));
    ExtractPredicate SelectStatementExtract13 = new KeywordExtractPredicate(Arrays.asList("h6", "h7", "k8", "k9"), "key5", null);
    //Statement SelectStatementParameters13 = new SelectStatement("_sid0", , SelectStatementExtract13, "q", 5, 6);
    ExtractPredicate SelectStatementExtract14 = new KeywordExtractPredicate(Arrays.asList("i6"), "key5", null);
    //Statement SelectStatementParameters14 = new SelectStatement("_sid0", null, SelectStatementExtract14, "q", null, null);
    ProjectPredicate cfreateViewStatementSelect00 = new ProjectAllFieldsPredicate();
    //Statement createViewStatementSelect00 = new SelectStatement("_sid0", , null, "a", null, null);
    //Statement createViewStatementParameters00 = new CreateViewStatement("v0", createViewStatementSelect00);
    ProjectPredicate createViewStatementSelect01 = new ProjectSomeFieldsPredicate(Arrays.asList("f8", "fa", "fc", "df", "ff"));
    //Statement createViewStatementSelect01 = new SelectStatement("_sid0", , null, "j", 1, 8);
    //Statement createViewStatementParameters01 = new CreateViewStatement("v1", createViewStatementSelect01);
    ProjectPredicate createViewStatementSelect02 = new ProjectSomeFieldsPredicate(Arrays.asList("e"));
    ExtractPredicate createViewStatementExtract02 = new KeywordExtractPredicate(Arrays.asList("g4", "g5"), "key0", null);
    //Statement createViewStatementSelect02 = new SelectStatement("_sid0", , createViewStatementExtract02, "o", null, null);
    //Statement createViewStatementParameters02 = new CreateViewStatement("v2", createViewStatementSelect02);
    ExtractPredicate createViewStatementExtract03 = new KeywordExtractPredicate(Arrays.asList("g4", "g5"), "key0", "substring");
    //Statement createViewStatementSelect03 = new SelectStatement("_sid0", null, createViewStatementExtract03, "o", null, null);
    //Statement createViewStatementParameters03 = new CreateViewStatement("v2", createViewStatementSelect03);
    //Test combinations of statements
    String statements00 = SelectStatement00;
    Statement statements00Select = new SelectStatement("_sid0", SelectStatementSelect00, null, "a", null, null);
    List<Statement> statements00Result = Arrays.asList(statements00Select);
    Assert.assertEquals((new TextQLParser(string2InputStream(statements00))).mainStatementList(null), statements00Result);
    String statements01 = createViewStatement02;
    Statement statements01Select = new SelectStatement("_sid0", createViewStatementSelect02, createViewStatementExtract02, "o", null, null);
    Statement statements01CreateView = new CreateViewStatement("v2", statements01Select);
    List<Statement> statements01Result = Arrays.asList(statements01CreateView);
    Assert.assertEquals((new TextQLParser(string2InputStream(statements01))).mainStatementList(null), statements01Result);
    String statements02 = createViewStatement02 + SelectStatement00;
    Statement statements02Select00 = new SelectStatement("_sid0", createViewStatementSelect02, createViewStatementExtract02, "o", null, null);
    Statement statements02CreateView00 = new CreateViewStatement("v2", statements02Select00);
    Statement statements02Select01 = new SelectStatement("_sid1", SelectStatementSelect00, null, "a", null, null);
    List<Statement> statementsResult02 = Arrays.asList(statements02CreateView00, statements02Select01);
    List<Statement> statementsConsumed02 = new ArrayList<>();
    Assert.assertEquals((new TextQLParser(string2InputStream(statements02))).mainStatementList(null), statementsResult02);
    Assert.assertEquals((new TextQLParser(string2InputStream(statements02))).mainStatementList(s -> statementsConsumed02.add(s)), statementsResult02);
    Assert.assertEquals(statementsConsumed02, statementsResult02);
    String statements03 = SelectStatement00 + createViewStatement00 + createViewStatement03;
    Statement statements03Select00 = new SelectStatement("_sid0", SelectStatementSelect00, null, "a", null, null);
    Statement statements03Select01 = new SelectStatement("_sid1", cfreateViewStatementSelect00, null, "a", null, null);
    Statement statements03CreateView01 = new CreateViewStatement("v0", statements03Select01);
    Statement statements03Select02 = new SelectStatement("_sid2", null, createViewStatementExtract03, "o", null, null);
    Statement statements03CreateView02 = new CreateViewStatement("v2", statements03Select02);
    List<Statement> statements03Result = Arrays.asList(statements03Select00, statements03CreateView01, statements03CreateView02);
    List<Statement> statements03Consumed = new ArrayList<>();
    Assert.assertEquals((new TextQLParser(string2InputStream(statements03))).mainStatementList(null), statements03Result);
    Assert.assertEquals((new TextQLParser(string2InputStream(statements03))).mainStatementList(s -> statements03Consumed.add(s)), statements03Result);
    Assert.assertEquals(statements03Consumed, statements03Result);
    String statements04 = createViewStatement02 + SelectStatement14 + SelectStatement13;
    Statement statements04Select00 = new SelectStatement("_sid0", createViewStatementSelect02, createViewStatementExtract02, "o", null, null);
    Statement statements04CreateView00 = new CreateViewStatement("v2", statements04Select00);
    Statement statements04Select01 = new SelectStatement("_sid1", null, SelectStatementExtract14, "q", null, null);
    Statement statements04Select02 = new SelectStatement("_sid2", SelectStatementSelect13, SelectStatementExtract13, "q", 5, 6);
    List<Statement> statements04Result = Arrays.asList(statements04CreateView00, statements04Select01, statements04Select02);
    List<Statement> statements04Consumed = new ArrayList<>();
    Assert.assertEquals((new TextQLParser(string2InputStream(statements04))).mainStatementList(null), statements04Result);
    Assert.assertEquals((new TextQLParser(string2InputStream(statements04))).mainStatementList(s -> statements04Consumed.add(s)), statements04Result);
    Assert.assertEquals(statements04Consumed, statements04Result);
    String statements05 = createViewStatement01 + SelectStatement13 + createViewStatement03;
    Statement statements05Select00 = new SelectStatement("_sid0", createViewStatementSelect01, null, "j", 1, 8);
    Statement statements05CreateView00 = new CreateViewStatement("v1", statements05Select00);
    Statement statements05Select01 = new SelectStatement("_sid1", SelectStatementSelect13, SelectStatementExtract13, "q", 5, 6);
    Statement statements05Select02 = new SelectStatement("_sid2", null, createViewStatementExtract03, "o", null, null);
    Statement statements05CreateView02 = new CreateViewStatement("v2", statements05Select02);
    List<Statement> statements05Result = Arrays.asList(statements05CreateView00, statements05Select01, statements05CreateView02);
    List<Statement> statements05Consumed = new ArrayList<>();
    Assert.assertEquals((new TextQLParser(string2InputStream(statements05))).mainStatementList(null), statements05Result);
    Assert.assertEquals((new TextQLParser(string2InputStream(statements05))).mainStatementList(s -> statements05Consumed.add(s)), statements05Result);
    Assert.assertEquals(statements05Consumed, statements05Result);
}
Also used : PrintStream(java.io.PrintStream) ProjectAllFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate) TokenMgrError(edu.uci.ics.textdb.textql.languageparser.TokenMgrError) Arrays(java.util.Arrays) 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) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Test(org.junit.Test) PipedOutputStream(java.io.PipedOutputStream) CreateViewStatement(edu.uci.ics.textdb.textql.statements.CreateViewStatement) SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) ArrayList(java.util.ArrayList) List(java.util.List) PipedInputStream(java.io.PipedInputStream) TextQLParser(edu.uci.ics.textdb.textql.languageparser.TextQLParser) Assert(junit.framework.Assert) ParseException(edu.uci.ics.textdb.textql.languageparser.ParseException) InputStream(java.io.InputStream) ProjectSomeFieldsPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate) ProjectPredicate(edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate) CreateViewStatement(edu.uci.ics.textdb.textql.statements.CreateViewStatement) 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) ArrayList(java.util.ArrayList) SelectStatement(edu.uci.ics.textdb.textql.statements.SelectStatement) 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) TextQLParser(edu.uci.ics.textdb.textql.languageparser.TextQLParser) Test(org.junit.Test)

Example 3 with Statement

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

the class CreateViewStatementTest method testConstructorAndGetters.

/**
     * Test the class constructor and the getter methods.
     * Call the constructor of CreateViewStatement and test if
     * the returned value by the getter is the same.
     */
@Test
public void testConstructorAndGetters() {
    Statement subStatement;
    ProjectPredicate projectPredicate;
    ExtractPredicate extractPredicate;
    CreateViewStatement createViewStatement;
    // Tests for the id attribute
    createViewStatement = new CreateViewStatement(null, null);
    Assert.assertEquals(createViewStatement.getId(), null);
    createViewStatement = new CreateViewStatement("statementId", null);
    Assert.assertEquals(createViewStatement.getId(), "statementId");
    createViewStatement = new CreateViewStatement("id6", null);
    Assert.assertEquals(createViewStatement.getId(), "id6");
    createViewStatement = new CreateViewStatement("_sid12", null);
    Assert.assertEquals(createViewStatement.getId(), "_sid12");
    // Tests for the subStatement attribute
    createViewStatement = new CreateViewStatement("statementId", null);
    Assert.assertEquals(createViewStatement.getSubStatement(), null);
    subStatement = new SelectStatement("substatementId0", null, null, "source", null, null);
    createViewStatement = new CreateViewStatement("statementId", subStatement);
    Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
    subStatement = new SelectStatement("substatementId1", null, null, "table", null, null);
    createViewStatement = new CreateViewStatement("statementId", subStatement);
    Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
    projectPredicate = new ProjectAllFieldsPredicate();
    subStatement = new SelectStatement("substatementId2", projectPredicate, null, "from", null, null);
    createViewStatement = new CreateViewStatement("statementId", subStatement);
    Assert.assertEquals(createViewStatement.getSubStatement(), subStatement);
    projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("at1", "at0"));
    extractPredicate = new KeywordExtractPredicate(Arrays.asList("a", "b"), "keyword", KeywordMatchingType.CONJUNCTION_INDEXBASED.toString());
    subStatement = new SelectStatement("substatementIdX", projectPredicate, extractPredicate, "t", null, null);
    createViewStatement = new CreateViewStatement("statementId", 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 4 with Statement

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

the class TextQLParserTest method testSelectStatement.

/**
     * Test the selectStatement method of the parser.
     * It should parse a select statements and return the expected SelectStatement object.
     * @throws ParseException if an unexpected ParseException is thrown
     */
@Test
public void testSelectStatement() throws ParseException {
    String SelectStatement00 = "SELECT * FROM a";
    ProjectPredicate SelectStatementSelect00 = new ProjectAllFieldsPredicate();
    Statement SelectStatementParameters00 = new SelectStatement("_sid0", SelectStatementSelect00, null, "a", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement00))).selectStatement(), SelectStatementParameters00);
    String SelectStatement01 = "SELECT * FROM b LIMIT 5";
    ProjectPredicate SelectStatementSelect01 = new ProjectAllFieldsPredicate();
    Statement SelectStatementParameters01 = new SelectStatement("_sid0", SelectStatementSelect01, null, "b", 5, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement01))).selectStatement(), SelectStatementParameters01);
    String SelectStatement02 = "SELECT * FROM c LIMIT 1 OFFSET 8";
    ProjectPredicate SelectStatementSelect02 = new ProjectAllFieldsPredicate();
    Statement SelectStatementParameters02 = new SelectStatement("_sid0", SelectStatementSelect02, null, "c", 1, 8);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement02))).selectStatement(), SelectStatementParameters02);
    String SelectStatement03 = "SELECT * FROM d OFFSET 6";
    ProjectPredicate SelectStatementSelect03 = new ProjectAllFieldsPredicate();
    Statement SelectStatementParameters03 = new SelectStatement("_sid0", SelectStatementSelect03, null, "d", null, 6);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement03))).selectStatement(), SelectStatementParameters03);
    String SelectStatement04 = "SELECT f1 FROM e";
    ProjectPredicate SelectStatementSelect04 = new ProjectSomeFieldsPredicate(Arrays.asList("f1"));
    Statement SelectStatementParameters04 = new SelectStatement("_sid0", SelectStatementSelect04, null, "e", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement04))).selectStatement(), SelectStatementParameters04);
    String SelectStatement05 = "SELECT f1, f5 FROM i";
    ProjectPredicate SelectStatementSelect05 = new ProjectSomeFieldsPredicate(Arrays.asList("f1", "f5"));
    Statement SelectStatementParameters05 = new SelectStatement("_sid0", SelectStatementSelect05, null, "i", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement05))).selectStatement(), SelectStatementParameters05);
    String SelectStatement06 = "SELECT f8, fa, fc, df, ff FROM j";
    ProjectPredicate SelectStatementSelect06 = new ProjectSomeFieldsPredicate(Arrays.asList("f8", "fa", "fc", "df", "ff"));
    Statement SelectStatementParameters06 = new SelectStatement("_sid0", SelectStatementSelect06, null, "j", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement06))).selectStatement(), SelectStatementParameters06);
    String SelectStatement07 = "SELECT a, KEYWORDMATCH(g0, \"key1\") FROM k";
    ProjectPredicate SelectStatementSelect07 = new ProjectSomeFieldsPredicate(Arrays.asList("a"));
    ExtractPredicate SelectStatementExtract07 = new KeywordExtractPredicate(Arrays.asList("g0"), "key1", null);
    Statement SelectStatementParameters07 = new SelectStatement("_sid0", SelectStatementSelect07, SelectStatementExtract07, "k", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement07))).selectStatement(), SelectStatementParameters07);
    String SelectStatement08 = "SELECT b, KEYWORDMATCH(g1, \"key2\", conjunction) FROM l";
    ProjectPredicate SelectStatementSelect08 = new ProjectSomeFieldsPredicate(Arrays.asList("b"));
    ExtractPredicate SelectStatementExtract08 = new KeywordExtractPredicate(Arrays.asList("g1"), "key2", "conjunction");
    Statement SelectStatementParameters08 = new SelectStatement("_sid0", SelectStatementSelect08, SelectStatementExtract08, "l", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement08))).selectStatement(), SelectStatementParameters08);
    String SelectStatement10 = "SELECT v, KEYWORDMATCH(u, \"keyZ\") FROM t";
    ProjectPredicate SelectStatementSelect10 = new ProjectSomeFieldsPredicate(Arrays.asList("v"));
    ExtractPredicate SelectStatementExtract10 = new KeywordExtractPredicate(Arrays.asList("u"), "keyZ", null);
    Statement SelectStatementParameters10 = new SelectStatement("_sid0", SelectStatementSelect10, SelectStatementExtract10, "t", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement10))).selectStatement(), SelectStatementParameters10);
    String SelectStatement11 = "SELECT e, KEYWORDMATCH([g4], \"key0\") FROM o";
    ProjectPredicate SelectStatementSelect11 = new ProjectSomeFieldsPredicate(Arrays.asList("e"));
    ExtractPredicate SelectStatementExtract11 = new KeywordExtractPredicate(Arrays.asList("g4"), "key0", null);
    Statement SelectStatementParameters11 = new SelectStatement("_sid0", SelectStatementSelect11, SelectStatementExtract11, "o", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement11))).selectStatement(), SelectStatementParameters11);
    String SelectStatement12 = "SELECT f, KEYWORDMATCH([g6,g7,h8,i9], \"key\") FROM p";
    ProjectPredicate SelectStatementSelect12 = new ProjectSomeFieldsPredicate(Arrays.asList("f"));
    ExtractPredicate SelectStatementExtract12 = new KeywordExtractPredicate(Arrays.asList("g6", "g7", "h8", "i9"), "key", null);
    Statement SelectStatementParameters12 = new SelectStatement("_sid0", SelectStatementSelect12, SelectStatementExtract12, "p", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement12))).selectStatement(), SelectStatementParameters12);
    String SelectStatement13 = "SELECT h, i, j, KEYWORDMATCH([h6,h7,k8,k9], \"key5\") FROM q";
    ProjectPredicate SelectStatementSelect13 = new ProjectSomeFieldsPredicate(Arrays.asList("h", "i", "j"));
    ExtractPredicate SelectStatementExtract13 = new KeywordExtractPredicate(Arrays.asList("h6", "h7", "k8", "k9"), "key5", null);
    Statement SelectStatementParameters13 = new SelectStatement("_sid0", SelectStatementSelect13, SelectStatementExtract13, "q", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement13))).selectStatement(), SelectStatementParameters13);
    String SelectStatement14 = "SELECT KEYWORDMATCH([i6,j7,l8,m9], \"key5\") FROM q";
    ExtractPredicate SelectStatementExtract14 = new KeywordExtractPredicate(Arrays.asList("i6", "j7", "l8", "m9"), "key5", null);
    Statement SelectStatementParameters14 = new SelectStatement("_sid0", null, SelectStatementExtract14, "q", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement14))).selectStatement(), SelectStatementParameters14);
    String SelectStatement15 = "SELECT KEYWORDMATCH(g0, \"key1\") FROM k";
    ExtractPredicate SelectStatementExtract15 = new KeywordExtractPredicate(Arrays.asList("g0"), "key1", null);
    Statement SelectStatementParameters15 = new SelectStatement("_sid0", null, SelectStatementExtract15, "k", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement15))).selectStatement(), SelectStatementParameters15);
    String SelectStatement16 = "SELECT KEYWORDMATCH(g1, \"key2\", phrase) FROM l";
    ExtractPredicate SelectStatementExtract16 = new KeywordExtractPredicate(Arrays.asList("g1"), "key2", "phrase");
    Statement SelectStatementParameters16 = new SelectStatement("_sid0", null, SelectStatementExtract16, "l", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement16))).selectStatement(), SelectStatementParameters16);
    String SelectStatement19 = "SELECT KEYWORDMATCH([g4], \"key0\") FROM o";
    ExtractPredicate SelectStatementExtract19 = new KeywordExtractPredicate(Arrays.asList("g4"), "key0", null);
    Statement SelectStatementParameters19 = new SelectStatement("_sid0", null, SelectStatementExtract19, "o", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement19))).selectStatement(), SelectStatementParameters19);
    String SelectStatement20 = "SELECT KEYWORDMATCH([g6,g7,h8,i9], \"key\") FROM p";
    ExtractPredicate SelectStatementExtract20 = new KeywordExtractPredicate(Arrays.asList("g6", "g7", "h8", "i9"), "key", null);
    Statement SelectStatementParameters20 = new SelectStatement("_sid0", null, SelectStatementExtract20, "p", null, null);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement20))).selectStatement(), SelectStatementParameters20);
    String SelectStatement21 = "SELECT KEYWORDMATCH([h3,i2,j1,k0], \"key\\\"/\") FROM m LIMIT 4 OFFSET 25 ";
    ExtractPredicate SelectStatementExtract21 = new KeywordExtractPredicate(Arrays.asList("h3", "i2", "j1", "k0"), "key\"/", null);
    Statement SelectStatementParameters21 = new SelectStatement("_sid0", null, SelectStatementExtract21, "m", 4, 25);
    Assert.assertEquals((new TextQLParser(string2InputStream(SelectStatement21))).selectStatement(), SelectStatementParameters21);
    String SelectStatement22 = "SELECT FROM a";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement22))).selectStatement(), ParseException.class);
    String SelectStatement23 = "SELECT FROM a OFFSET 5 LIMIT 6";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement23))).selectStatement(), ParseException.class);
    String SelectStatement24 = "SELECT 25 FROM a";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement24))).selectStatement(), ParseException.class);
    String SelectStatement25 = "SELECT [a,b] FROM a";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement25))).selectStatement(), ParseException.class);
    String SelectStatement26 = "SELECT *, a FROM a";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement26))).selectStatement(), ParseException.class);
    String SelectStatement27 = "SELECT * FROM [a,b]";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement27))).selectStatement(), ParseException.class);
    String SelectStatement28 = "SELECT KEYWORDMATCH(g0, \"key1\"), a FROM a";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement28))).selectStatement(), ParseException.class);
    String SelectStatement29 = "SELECT KEYWORDMATCH(g0, \"key1\") SELECT a FROM k";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement29))).selectStatement(), ParseException.class);
    String SelectStatement30 = "SELECT a";
    assertException(() -> (new TextQLParser(string2InputStream(SelectStatement30))).selectStatement(), ParseException.class);
}
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) 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) TextQLParser(edu.uci.ics.textdb.textql.languageparser.TextQLParser) Test(org.junit.Test)

Example 5 with Statement

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

the class TextQLParserTest method testCreateViewStatement.

/**
     * Test the createViewStatement method of the parser.
     * It should parse a create view statement and return the expected CreateViewStatement object.
     * @throws ParseException if an unexpected ParseException is thrown
     */
@Test
public void testCreateViewStatement() throws ParseException {
    String createViewStatement00 = " CREATE VIEW v0 AS SELECT * FROM a ";
    ProjectPredicate createViewStatementSelectP00 = new ProjectAllFieldsPredicate();
    Statement createViewStatementSelect00 = new SelectStatement("_sid0", createViewStatementSelectP00, null, "a", null, null);
    Statement createViewStatementParameters00 = new CreateViewStatement("v0", createViewStatementSelect00);
    Assert.assertEquals((new TextQLParser(string2InputStream(createViewStatement00))).createViewStatement(), createViewStatementParameters00);
    String createViewStatement01 = " CREATE VIEW v1 AS SELECT f8, fa, fc, df, ff FROM j LIMIT 1 OFFSET 8 ";
    ProjectPredicate createViewStatementSelectP01 = new ProjectSomeFieldsPredicate(Arrays.asList("f8", "fa", "fc", "df", "ff"));
    Statement createViewStatementSelect01 = new SelectStatement("_sid0", createViewStatementSelectP01, null, "j", 1, 8);
    Statement createViewStatementParameters01 = new CreateViewStatement("v1", createViewStatementSelect01);
    Assert.assertEquals((new TextQLParser(string2InputStream(createViewStatement01))).createViewStatement(), createViewStatementParameters01);
    String createViewStatement02 = " CREATE VIEW v2 AS SELECT e, KEYWORDMATCH([g4,g5], \"key0\") FROM o ";
    ProjectPredicate createViewStatementSelectP02 = new ProjectSomeFieldsPredicate(Arrays.asList("e"));
    ExtractPredicate createViewStatementExtract02 = new KeywordExtractPredicate(Arrays.asList("g4", "g5"), "key0", null);
    Statement createViewStatementSelect02 = new SelectStatement("_sid0", createViewStatementSelectP02, createViewStatementExtract02, "o", null, null);
    Statement createViewStatementParameters02 = new CreateViewStatement("v2", createViewStatementSelect02);
    Assert.assertEquals((new TextQLParser(string2InputStream(createViewStatement02))).createViewStatement(), createViewStatementParameters02);
    String createViewStatement03 = " CREATE VIEW v2 AS SELECT KEYWORDMATCH([g4,g5], \"key0\", substring) FROM o ";
    ExtractPredicate createViewStatementExtract03 = new KeywordExtractPredicate(Arrays.asList("g4", "g5"), "key0", "substring");
    Statement createViewStatementSelect03 = new SelectStatement("_sid0", null, createViewStatementExtract03, "o", null, null);
    Statement createViewStatementParameters03 = new CreateViewStatement("v2", createViewStatementSelect03);
    Assert.assertEquals((new TextQLParser(string2InputStream(createViewStatement03))).createViewStatement(), createViewStatementParameters03);
    String createViewStatement04 = " CREATE VIEW v3 AS CREATE VIEW v4 AS SELECT * FROM a ";
    assertException(() -> (new TextQLParser(string2InputStream(createViewStatement04))).createViewStatement(), ParseException.class);
    String createViewStatement05 = " CREATE VIEW v0 AS ";
    assertException(() -> (new TextQLParser(string2InputStream(createViewStatement05))).createViewStatement(), ParseException.class);
    String createViewStatement06 = " CREATE VIEW v0 ";
    assertException(() -> (new TextQLParser(string2InputStream(createViewStatement06))).createViewStatement(), ParseException.class);
    String createViewStatement08 = " CREATE v0 AS SELECT * FROM a ";
    assertException(() -> (new TextQLParser(string2InputStream(createViewStatement08))).createViewStatement(), ParseException.class);
    String createViewStatement09 = " VIEW v0 AS SELECT * FROM a ";
    assertException(() -> (new TextQLParser(string2InputStream(createViewStatement09))).createViewStatement(), ParseException.class);
}
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) TextQLParser(edu.uci.ics.textdb.textql.languageparser.TextQLParser) Test(org.junit.Test)

Aggregations

Statement (edu.uci.ics.textdb.textql.statements.Statement)9 CreateViewStatement (edu.uci.ics.textdb.textql.statements.CreateViewStatement)8 SelectStatement (edu.uci.ics.textdb.textql.statements.SelectStatement)8 Test (org.junit.Test)8 ExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.ExtractPredicate)7 KeywordExtractPredicate (edu.uci.ics.textdb.textql.statements.predicates.KeywordExtractPredicate)7 ProjectPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate)7 ProjectSomeFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectSomeFieldsPredicate)7 ProjectAllFieldsPredicate (edu.uci.ics.textdb.textql.statements.predicates.ProjectAllFieldsPredicate)6 TextQLParser (edu.uci.ics.textdb.textql.languageparser.TextQLParser)4 PredicateBase (edu.uci.ics.textdb.exp.common.PredicateBase)3 List (java.util.List)2 OperatorLink (edu.uci.ics.textdb.exp.plangen.OperatorLink)1 ParseException (edu.uci.ics.textdb.textql.languageparser.ParseException)1 TokenMgrError (edu.uci.ics.textdb.textql.languageparser.TokenMgrError)1 PassThroughPredicate (edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1