[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