use of edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate 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);
}
use of edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate in project textdb by TextDB.
the class TextQLParserTest method testStatement.
/**
* Test the statement method of the parser.
* It should parse a statement and return the expected Statement object.
* @throws ParseException if an unexpected ParseException is thrown
*/
@Test
public void testStatement() 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))).statement(), SelectStatementParameters00);
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))).statement(), SelectStatementParameters06);
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))).statement(), 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))).statement(), SelectStatementParameters14);
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))).statement(), SelectStatementParameters21);
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))).statement(), 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))).statement(), 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))).statement(), 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))).statement(), createViewStatementParameters03);
}
use of edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate 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));
}
use of edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate 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);
}
use of edu.uci.ics.textdb.textql.statements.predicates.ProjectPredicate 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);
}
Aggregations