use of edu.uci.ics.textdb.textql.statements.SelectStatement in project textdb by TextDB.
the class SelectStatementTest method testSelectStatementBeansBuilder00.
/**
* Test the correctness of the generated beans by a SelectStatement without a
* ProjectPredicate nor ExtractPredicate.
* 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 testSelectStatementBeansBuilder00() {
SelectStatement selectStatement = new SelectStatement("id", null, null, "tableX", null, null);
List<PredicateBase> expectedGeneratedBeans = Collections.emptyList();
List<String> dependencies = Arrays.asList("tableX");
Assert.assertEquals(selectStatement.getInputViews(), dependencies);
StatementTestUtils.assertGeneratedBeans(selectStatement, expectedGeneratedBeans);
}
use of edu.uci.ics.textdb.textql.statements.SelectStatement in project textdb by TextDB.
the class SelectStatementTest method testConstructorAndGetters.
/**
* Test the class constructor and the getter methods.
* Call the constructor of SelectStatement and test if the
* returned value by the getter is the same.
*/
@Test
public void testConstructorAndGetters() {
ProjectPredicate projectPredicate;
ExtractPredicate extractPredicate;
SelectStatement selectExtractStatement;
// Tests for the id attribute
selectExtractStatement = new SelectStatement(null, null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getId(), null);
selectExtractStatement = new SelectStatement("idx", null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getId(), "idx");
selectExtractStatement = new SelectStatement("_sid08", null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getId(), "_sid08");
// Tests for the projectPredicate attribute
selectExtractStatement = new SelectStatement("", null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getProjectPredicate(), null);
projectPredicate = new ProjectAllFieldsPredicate();
selectExtractStatement = new SelectStatement(null, projectPredicate, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getProjectPredicate(), projectPredicate);
projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("a", "b", "c"));
selectExtractStatement = new SelectStatement(null, projectPredicate, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getProjectPredicate(), projectPredicate);
projectPredicate = new ProjectSomeFieldsPredicate(Arrays.asList("f0", "f1"));
selectExtractStatement = new SelectStatement(null, projectPredicate, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getProjectPredicate(), projectPredicate);
// Tests for the extractPredicate attribute
selectExtractStatement = new SelectStatement(null, null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getProjectPredicate(), null);
extractPredicate = new KeywordExtractPredicate(Arrays.asList("x", "y"), "keyword", KeywordMatchingType.SUBSTRING_SCANBASED.toString());
selectExtractStatement = new SelectStatement(null, null, extractPredicate, null, null, null);
Assert.assertEquals(selectExtractStatement.getExtractPredicate(), extractPredicate);
extractPredicate = new KeywordExtractPredicate(Arrays.asList("z6", "t4"), "xyz", KeywordMatchingType.PHRASE_INDEXBASED.toString());
selectExtractStatement = new SelectStatement(null, null, extractPredicate, null, null, null);
Assert.assertEquals(selectExtractStatement.getExtractPredicate(), extractPredicate);
// Tests for the fromClause attribute
selectExtractStatement = new SelectStatement(null, null, null, null, null, null);
selectExtractStatement.setFromClause(null);
selectExtractStatement = new SelectStatement(null, null, null, "tab", null, null);
selectExtractStatement.setFromClause("tab");
selectExtractStatement = new SelectStatement(null, null, null, "t1", null, null);
selectExtractStatement.setFromClause("t1");
// Tests for the limitClause attribute
selectExtractStatement = new SelectStatement(null, null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getLimitClause(), null);
selectExtractStatement = new SelectStatement(null, null, null, null, 0, null);
Assert.assertEquals(selectExtractStatement.getLimitClause(), Integer.valueOf(0));
selectExtractStatement = new SelectStatement(null, null, null, null, 8, null);
Assert.assertEquals(selectExtractStatement.getLimitClause(), Integer.valueOf(8));
selectExtractStatement = new SelectStatement(null, null, null, null, -151, null);
Assert.assertEquals(selectExtractStatement.getLimitClause(), Integer.valueOf(-151));
// Tests for the offsetClause attribute
selectExtractStatement = new SelectStatement(null, null, null, null, null, null);
Assert.assertEquals(selectExtractStatement.getOffsetClause(), null);
selectExtractStatement = new SelectStatement(null, null, null, null, null, 0);
Assert.assertEquals(selectExtractStatement.getOffsetClause(), Integer.valueOf(0));
selectExtractStatement = new SelectStatement(null, null, null, null, null, 562);
Assert.assertEquals(selectExtractStatement.getOffsetClause(), Integer.valueOf(562));
selectExtractStatement = new SelectStatement(null, null, null, null, null, -98);
Assert.assertEquals(selectExtractStatement.getOffsetClause(), Integer.valueOf(-98));
}
use of edu.uci.ics.textdb.textql.statements.SelectStatement 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);
}
use of edu.uci.ics.textdb.textql.statements.SelectStatement 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);
}
use of edu.uci.ics.textdb.textql.statements.SelectStatement 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);
}
Aggregations