SqlShuttle helped to visit field names as well as change it according to target dialect.
On Thu, Jan 18, 2018 at 4:01 PM, Nirav Patel <[email protected]> wrote: > Sorry my original expression had an extra ")" in the end. Thanks for > verifying. > > Followup question: > > How do I extract Field(Column) names from all such expressions? I tried > implementing SqlVisitor. I can see SqlCall has fields operators and operand > but when I fetch them I get List[SqlNode] can they be converted directly to > String? or any getNames() method? Or do I need to do recursive traversal > and each time I get sqlNode I provide new visitor until I hit > SqlIdentifier? Can you provide some suggestion to effectively get all > column names from expression. > > Thanks, > Nirav > > On Thu, Jan 18, 2018 at 3:01 PM, Julian Hyde <[email protected]> wrote: > >> It works for me. >> >> public static void main(String[] args) throws SqlParseException { >> try { >> SqlParser parser = SqlParser.create("SUM(t1.amount)/COUNT(t1)"); >> SqlNode sqlNode = parser.parseExpression(); >> } catch (Throwable e) { >> e.printStackTrace(); >> } >> } >> >> >> > On Jan 18, 2018, at 1:44 PM, Nirav Patel <[email protected]> wrote: >> > >> > Is it possible to just parse sql function expression which is not a >> > complete sql syntax. >> > e.g. I want to parse expression `SUM(t1.amount)/COUNT(t1)` instead of >> whole >> > sql like "select t1.name, SUM(t1.amount)/COUNT(t1) from mytable t1 >> group by >> > t1.name". I tried >> > >> > val parser = SqlParser.create("SUM(t1.amount)/COUNT(t1)") >> > val sqlNode = parser.parseExpression() >> > >> > but it fails with parse exception. >> > >> > Thanks >> > >> > -- >> > >> > >> > [image: What's New with Xactly] <http://www.xactlycorp.com/email-click/ >> > >> > >> > <https://www.instagram.com/xactlycorp/> >> > <https://www.linkedin.com/company/xactly-corporation> >> > <https://twitter.com/Xactly> <https://www.facebook.com/XactlyCorp> >> > <http://www.youtube.com/xactlycorporation> >> >> > -- [image: What's New with Xactly] <http://www.xactlycorp.com/email-click/> <https://www.instagram.com/xactlycorp/> <https://www.linkedin.com/company/xactly-corporation> <https://twitter.com/Xactly> <https://www.facebook.com/XactlyCorp> <http://www.youtube.com/xactlycorporation>
