Search in sources :

Example 11 with TextQLParser

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

the class TextQLParserTest method testIdentifierListToListString.

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

Example 12 with TextQLParser

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

the class TextQLParserTest method testNumberLiteralToDouble.

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

Example 13 with TextQLParser

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

the class TextQLParserTest method testExtractPredicate.

/**
 * Test the extractPredicate method of the parser.
 * It should parse an extract predicate and return the expected ExtractPredicate object.
 * @throws ParseException if an unexpected ParseException is thrown
 */
@Test
public void testExtractPredicate() throws ParseException {
    String keywordMatchPredicate00 = " KEYWORDMATCH(g0, \"key1\") ";
    ExtractPredicate keywordMatchParameters00 = new KeywordExtractPredicate(Arrays.asList("g0"), "key1", null);
    Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate00))).extractKeywordMatchPredicate(), keywordMatchParameters00);
    String keywordMatchPredicate01 = " KEYWORDMATCH(g1, \"key2\", conjunction) ";
    ExtractPredicate keywordMatchParameters01 = new KeywordExtractPredicate(Arrays.asList("g1"), "key2", "conjunction");
    Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate01))).extractKeywordMatchPredicate(), keywordMatchParameters01);
    String keywordMatchPredicate04 = " KEYWORDMATCH([g4], \"key0\") ";
    ExtractPredicate keywordMatchParameters04 = new KeywordExtractPredicate(Arrays.asList("g4"), "key0", null);
    Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate04))).extractKeywordMatchPredicate(), keywordMatchParameters04);
    String keywordMatchPredicate06 = " KEYWORDMATCH([g6,g7,h8,i9], \"key\") ";
    ExtractPredicate keywordMatchParameters06 = new KeywordExtractPredicate(Arrays.asList("g6", "g7", "h8", "i9"), "key", null);
    Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate06))).extractKeywordMatchPredicate(), keywordMatchParameters06);
    String keywordMatchPredicate07 = " KEYWORDMATCH([g6,g7,h8,i9], \"key\", substring) ";
    ExtractPredicate keywordMatchParameters07 = new KeywordExtractPredicate(Arrays.asList("g6", "g7", "h8", "i9"), "key", "substring");
    Assert.assertEquals((new TextQLParser(string2InputStream(keywordMatchPredicate07))).extractKeywordMatchPredicate(), keywordMatchParameters07);
}
Also used : ExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.ExtractPredicate) KeywordExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate) KeywordExtractPredicate(edu.uci.ics.texera.textql.statements.predicates.KeywordExtractPredicate) 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