Menu

Statement / Expression equality

Jens Voss
2011-06-15
2012-12-07
  • Jens Voss

    Jens Voss - 2011-06-15

    Hello,

    is there a way (other than ugly and error-prone String conversion and manipulation) to determine whether two Statments or two Expressions are "essentially the same", i.e. a method that returns true when applied to two Statements obtained from parsing the Strings

    "select foo from bar"
    

    and

    "select    foo   from   bar"
    

    ,
    but returns false|/b] when applied to the Statements obtained from

    "select foo from bar"
    

    and

    "select bar from foo"
    

    **?

    I would assume that the visitor pattern is not suitable for that kind of functionality, right?
    So how else would you do this?

    Regards,
    Jens
    **

     
  • Brian Krahmer

    Brian Krahmer - 2011-06-24

    I just ran an example where I parsed "select   foo      from      bar", then did a toString() on the resulting Statement, and it normalized it to "SELECT foo FROM bar", that is one option.  Then, if you wanted to collapse queries that have different literals, such as "select foo from bar where abcd = 'xyz'", you could walk the statement looking for StringValues, and replace them with question marks (JdbcParameters).  If you have a lot of varying IN clauses, you can do a similar technique, and replace many ? down to 1 ?.

    cheers,
    brian

     

Log in to post a comment.