Menu

function with expressions cause exception

Anonymous
2012-02-25
2012-12-07
  • Anonymous

    Anonymous - 2012-02-25

    The parser will fail with:
    SELECT IF(a>12, "true", "false") FROM test_table;
    SELECT IF(a=b, "true", "false") FROM test_table;
    SELECT IF(a IN (1,3,4), "true", "false") FROM test_table;

    Though it will NOT fail with:
    SELECT IF( a, "true", "false") FROM test_table;

    The functions can include SQL expressions as well(including subselects, sql expressions like IN..).
    I tried to fix the dictionary file but couldn't do it with my limited knowledge on javacc.

    In the definition of FUNCTION, the expressionList is assigned to SimpleExpressionList().
    I tried to assign it to SQLExpressionList() but in this case it fails for any function definition.

    Can someone help me with this?   Thanks!!!

     
  • Anonymous

    Anonymous - 2012-02-27

    I have managed the solve the problem with the following change:

    _SQLExpressionList SQLExpressionList():
    {
    ExpressionList retval = new ExpressionList();
    List expressions = new ArrayList();
    Expression expr = null;
    }
    {

    expr=SQLExpression() { expressions.add(expr); }
    ( "," expr=SQLExpression() { expressions.add(expr); } )*
    {
    retval.setExpressions(expressions);
    return retval;
    }
    }

    Expression SQLExpression():
    {
    Expression result;
    }
    {
    (LOOKAHEAD(Expression()) result=Expression()
    | result=SimpleExpression())

    { return result; }
    }_

    There is a warning in the compile for Function(), but this is still useful for me. For people who are interested the warning is:

    Warning: Choice conflict in  construct at line 1319, column 11.
                 Expansion nested within construct and expansion following construct
                 have common prefixes, one of which is: "ALL"
                 Consider using a lookahead of 2 or more for nested expansion.

    Which corresponds to this line in Function() decleration:
       "(" [  (expressionList=SQLExpressionList() | "*" { retval.setAllColumns(true); }) ] ")"

     

Log in to post a comment.