JSQLParser / JSqlParser

JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern

Home Page:https://github.com/JSQLParser/JSqlParser/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] Add option to call parent of expression

voidlol opened this issue · comments

I'm using JsqlParser to parse SQL script, which is always select statement and is written in Spark SQL syntax.

My goal is to travel through all functions and replace them with correct analog to target database (for example postgres).

Using visitor is great feature. but I can only change existing Function object, change function name, change parameters and so on.
But in some cases I need to replace this Function with other Expression, for example with Subtraction.

Look at this example:
SELECT to_unix_timestamp("col1") from mytable; -> this is valid spark sql
SELECT ("col1" - to_date('1970-01-01', 'yyyy-mm-dd')) * 86400 -> this is valid oracle sql

Here i need to change to_unix_timestamp function with Multiplication.

I wish there was an option to get parentExpression on my Function in a visitor and call something like replaceWith(multiplication)

Greetings.
All of that is very possible. What challenges exactly are you facing please?

Maybe this explanations will help: https://manticore-projects.com/JSQLParser/usage.html#build-a-sql-statement