Search in sources :

Example 1 with TextQLParser

use of edu.uci.ics.texera.textql.languageparser.TextQLParser 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.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) TextQLParser(edu.uci.ics.texera.textql.languageparser.TextQLParser) Test(org.junit.Test)

Example 2 with TextQLParser

use of edu.uci.ics.texera.textql.languageparser.TextQLParser in project textdb by TextDB.

the class TextQLParserTest method testIdentifierLiteralToString.

/**
 * Test the identifierLiteralToString method of the parser.
 * It should parse a IDENTIFIER_LITERAL from the input and return it as a string.
 * @throws ParseException if an unexpected ParseException is thrown
 */
@Test
public void testIdentifierLiteralToString() throws ParseException {
    Assert.assertEquals((new TextQLParser(string2InputStream(" i "))).identifierLiteralToString(), "i");
    Assert.assertEquals((new TextQLParser(string2InputStream(" id "))).identifierLiteralToString(), "id");
    Assert.assertEquals((new TextQLParser(string2InputStream(" id de "))).identifierLiteralToString(), "id");
    Assert.assertEquals((new TextQLParser(string2InputStream(" id0 "))).identifierLiteralToString(), "id0");
    Assert.assertEquals((new TextQLParser(string2InputStream(" i6i8s7s "))).identifierLiteralToString(), "i6i8s7s");
    Assert.assertEquals((new TextQLParser(string2InputStream(" j7i\\8s7s "))).identifierLiteralToString(), "j7i");
    Assert.assertEquals((new TextQLParser(string2InputStream(" k8i\"8s7s "))).identifierLiteralToString(), "k8i");
    Assert.assertEquals((new TextQLParser(string2InputStream(" aFROM "))).identifierLiteralToString(), "aFROM");
    Assert.assertEquals((new TextQLParser(string2InputStream(" A "))).identifierLiteralToString(), "A");
    Assert.assertEquals((new TextQLParser(string2InputStream(" FROMa "))).identifierLiteralToString(), "FROMa");
    Assert.assertEquals((new TextQLParser(string2InputStream(" Ed0 "))).identifierLiteralToString(), "Ed0");
    assertException(() -> (new TextQLParser(string2InputStream(" 2df "))).identifierLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" _a "))).identifierLiteralToString(), TokenMgrError.class);
}
Also used : TextQLParser(edu.uci.ics.texera.textql.languageparser.TextQLParser) Test(org.junit.Test)

Example 3 with TextQLParser

use of edu.uci.ics.texera.textql.languageparser.TextQLParser in project textdb by TextDB.

the class TextQLParserTest method testNumberLiteralToString.

/**
 * Test the numberLiteralToString method of the parser.
 * It should parse a NUMBER_LITERAL from the input and return it as a string.
 * @throws ParseException if an unexpected ParseException is thrown
 */
@Test
public void testNumberLiteralToString() throws ParseException {
    Assert.assertEquals((new TextQLParser(string2InputStream(" 0 "))).numberLiteralToString(), "0");
    Assert.assertEquals((new TextQLParser(string2InputStream(" 12 "))).numberLiteralToString(), "12");
    Assert.assertEquals((new TextQLParser(string2InputStream(" 34566 "))).numberLiteralToString(), "34566");
    Assert.assertEquals((new TextQLParser(string2InputStream(" 78.90 "))).numberLiteralToString(), "78.90");
    Assert.assertEquals((new TextQLParser(string2InputStream(" 123. "))).numberLiteralToString(), "123.");
    Assert.assertEquals((new TextQLParser(string2InputStream(" .456 "))).numberLiteralToString(), ".456");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -0 "))).numberLiteralToString(), "-0");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -12 "))).numberLiteralToString(), "-12");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -34566 "))).numberLiteralToString(), "-34566");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -78.90 "))).numberLiteralToString(), "-78.90");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -123. "))).numberLiteralToString(), "-123.");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -.456 "))).numberLiteralToString(), "-.456");
    Assert.assertEquals((new TextQLParser(string2InputStream(" -.789.001 "))).numberLiteralToString(), "-.789");
    assertException(() -> (new TextQLParser(string2InputStream(" -e "))).numberLiteralToString(), TokenMgrError.class);
    assertException(() -> (new TextQLParser(string2InputStream(" -e 21"))).numberLiteralToString(), TokenMgrError.class);
    assertException(() -> (new TextQLParser(string2InputStream(" +4 "))).numberLiteralToString(), TokenMgrError.class);
    assertException(() -> (new TextQLParser(string2InputStream(" a "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" a 22 "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" a45 "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" A45 "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" FROM45 "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" \"4\" "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" /4/ "))).numberLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" /4 "))).numberLiteralToString(), TokenMgrError.class);
}
Also used : TextQLParser(edu.uci.ics.texera.textql.languageparser.TextQLParser) Test(org.junit.Test)

Example 4 with TextQLParser

use of edu.uci.ics.texera.textql.languageparser.TextQLParser 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);
}
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) TextQLParser(edu.uci.ics.texera.textql.languageparser.TextQLParser) Test(org.junit.Test)

Example 5 with TextQLParser

use of edu.uci.ics.texera.textql.languageparser.TextQLParser in project textdb by TextDB.

the class TextQLParserTest method testRegexLiteralToString.

/**
 * Test the regexLiteralToString method of the parser.
 * It should parse a REGEX_LITERAL from the input and return it as a string.
 * @throws ParseException if an unexpected ParseException is thrown
 */
@Test
public void testRegexLiteralToString() throws ParseException {
    Assert.assertEquals((new TextQLParser(string2InputStream(" // "))).regexLiteralToString(), "");
    Assert.assertEquals((new TextQLParser(string2InputStream(" /abc/ "))).regexLiteralToString(), "abc");
    Assert.assertEquals((new TextQLParser(string2InputStream(" /d\\/e/ "))).regexLiteralToString(), "d/e");
    Assert.assertEquals((new TextQLParser(string2InputStream(" /d\\/e\\/f/ "))).regexLiteralToString(), "d/e/f");
    Assert.assertEquals((new TextQLParser(string2InputStream(" /FROM/ "))).regexLiteralToString(), "FROM");
    Assert.assertEquals((new TextQLParser(string2InputStream(" /\"/ "))).regexLiteralToString(), "\"");
    Assert.assertEquals((new TextQLParser(string2InputStream(" /\\/ "))).regexLiteralToString(), "\\");
    assertException(() -> (new TextQLParser(string2InputStream(" /21 "))).regexLiteralToString(), TokenMgrError.class);
    assertException(() -> (new TextQLParser(string2InputStream(" 2/1/ "))).regexLiteralToString(), ParseException.class);
    assertException(() -> (new TextQLParser(string2InputStream(" \"4/ "))).regexLiteralToString(), TokenMgrError.class);
    assertException(() -> (new TextQLParser(string2InputStream(" FROM// "))).regexLiteralToString(), ParseException.class);
}
Also used : TextQLParser(edu.uci.ics.texera.textql.languageparser.TextQLParser) Test(org.junit.Test)

Aggregations

TextQLParser (edu.uci.ics.texera.textql.languageparser.TextQLParser)13 Test (org.junit.Test)13 ExtractPredicate (edu.uci.ics.texera.textql.statements.predicates.ExtractPredicate)6 KeywordExtractPredicate (edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate)6 CreateViewStatement (edu.uci.ics.texera.textql.statements.CreateViewStatement)4 SelectStatement (edu.uci.ics.texera.textql.statements.SelectStatement)4 Statement (edu.uci.ics.texera.textql.statements.Statement)4 ProjectAllFieldsPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectAllFieldsPredicate)4 ProjectPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectPredicate)4 ProjectSomeFieldsPredicate (edu.uci.ics.texera.textql.statements.predicates.ProjectSomeFieldsPredicate)4 ParseException (edu.uci.ics.texera.textql.languageparser.ParseException)1 TokenMgrError (edu.uci.ics.texera.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 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1