Search in sources :

Example 6 with Statement

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

the class CreateViewStatementTest method testCreateViewStatementBeansBuilder00.

/**
 * Test the correctness of the generated beans by a CreateViewStatement with
 * a SelectExtractStatement as sub-statement without a SelectPredicate nor
 * ExtractPredicate.
 * 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 testCreateViewStatementBeansBuilder00() {
    Statement subStatement = new SelectStatement("id2", null, null, "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.texera.textql.statements.SelectStatement) CreateViewStatement(edu.uci.ics.texera.textql.statements.CreateViewStatement) PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) CreateViewStatement(edu.uci.ics.texera.textql.statements.CreateViewStatement) SelectStatement(edu.uci.ics.texera.textql.statements.SelectStatement) Statement(edu.uci.ics.texera.textql.statements.Statement) Test(org.junit.Test)

Example 7 with Statement

use of edu.uci.ics.texera.textql.statements.Statement 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.texera.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectPredicate) CreateViewStatement(edu.uci.ics.texera.textql.statements.CreateViewStatement) ExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.ExtractPredicate) KeywordExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate) CreateViewStatement(edu.uci.ics.texera.textql.statements.CreateViewStatement) SelectStatement(edu.uci.ics.texera.textql.statements.SelectStatement) Statement(edu.uci.ics.texera.textql.statements.Statement) ProjectAllFieldsPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectAllFieldsPredicate) ProjectSomeFieldsPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectSomeFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate) Test(org.junit.Test)

Example 8 with Statement

use of edu.uci.ics.texera.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) PassThroughPredicate(edu.uci.ics.texera.textql.planbuilder.beans.PassThroughPredicate) Iterator(java.util.Iterator) Statement(edu.uci.ics.texera.textql.statements.Statement) PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) OperatorLink(edu.uci.ics.texera.dataflow.plangen.OperatorLink) OperatorLink(edu.uci.ics.texera.dataflow.plangen.OperatorLink) PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) PassThroughPredicate(edu.uci.ics.texera.textql.planbuilder.beans.PassThroughPredicate) HashSet(java.util.HashSet)

Example 9 with Statement

use of edu.uci.ics.texera.textql.statements.Statement 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.texera.textql.statements.SelectStatement) ProjectPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectPredicate) CreateViewStatement(edu.uci.ics.texera.textql.statements.CreateViewStatement) PredicateBase(edu.uci.ics.texera.dataflow.common.PredicateBase) ExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.ExtractPredicate) KeywordExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate) CreateViewStatement(edu.uci.ics.texera.textql.statements.CreateViewStatement) SelectStatement(edu.uci.ics.texera.textql.statements.SelectStatement) Statement(edu.uci.ics.texera.textql.statements.Statement) ProjectSomeFieldsPredicate(edu.uci.ics.texera.textql.statements.predicates.ProjectSomeFieldsPredicate) KeywordExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate) Test(org.junit.Test)

Aggregations

Statement (edu.uci.ics.texera.textql.statements.Statement)9 CreateViewStatement (edu.uci.ics.texera.textql.statements.CreateViewStatement)8 SelectStatement (edu.uci.ics.texera.textql.statements.SelectStatement)8 Test (org.junit.Test)8 ExtractPredicate (edu.uci.ics.texera.textql.statements.predicates.ExtractPredicate)7 KeywordExtractPredicate (edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate)7 ProjectPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectPredicate)7 ProjectSomeFieldsPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectSomeFieldsPredicate)7 ProjectAllFieldsPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectAllFieldsPredicate)6 TextQLParser (edu.uci.ics.texera.textql.languageparser.TextQLParser)4 PredicateBase (edu.uci.ics.texera.dataflow.common.PredicateBase)3 List (java.util.List)2 OperatorLink (edu.uci.ics.texera.dataflow.plangen.OperatorLink)1 ParseException (edu.uci.ics.texera.textql.languageparser.ParseException)1 TokenMgrError (edu.uci.ics.texera.textql.languageparser.TokenMgrError)1 PassThroughPredicate (edu.uci.ics.texera.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