Skip to content

[FEATURE] Add option to call parent of expression #1966

@voidlol

Description

@voidlol

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions