示例#1
0
  /** Test basic || expression */
  @Test
  public void orExpression() throws RecognitionException {

    String queryString = "select * where a = 1 or b > 2";

    ANTLRStringStream in = new ANTLRStringStream(queryString);
    QueryFilterLexer lexer = new QueryFilterLexer(in);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    QueryFilterParser parser = new QueryFilterParser(tokens);

    Query query = parser.ql().query;

    Operand root = query.getRootOperand();

    OrOperand and = (OrOperand) root;

    Equal equal = (Equal) and.getLeft();

    assertEquals("a", equal.getProperty().getValue());

    assertEquals(1, ((LongLiteral) equal.getLiteral()).getValue().intValue());

    GreaterThan greater = (GreaterThan) and.getRight();

    assertEquals("b", greater.getProperty().getValue());
    assertEquals(2, ((LongLiteral) greater.getLiteral()).getValue().intValue());
  }
示例#2
0
  /** Simple test that constructs and AST from the ANTLR generated files */
  @Test
  public void greaterThan() throws RecognitionException {

    String queryString = "select * where a > 5";

    ANTLRStringStream in = new ANTLRStringStream(queryString);
    QueryFilterLexer lexer = new QueryFilterLexer(in);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    QueryFilterParser parser = new QueryFilterParser(tokens);

    Query query = parser.ql().query;

    Operand root = query.getRootOperand();

    GreaterThan equal = (GreaterThan) root;

    assertEquals("a", equal.getProperty().getValue());

    assertEquals(5, ((LongLiteral) equal.getLiteral()).getValue().intValue());

    queryString = "select * where a gt 5";

    in = new ANTLRStringStream(queryString);
    lexer = new QueryFilterLexer(in);
    tokens = new TokenRewriteStream(lexer);
    parser = new QueryFilterParser(tokens);

    query = parser.ql().query;

    root = query.getRootOperand();

    equal = (GreaterThan) root;

    assertEquals("a", equal.getProperty().getValue());

    assertEquals(5, ((LongLiteral) equal.getLiteral()).getValue().intValue());
  }