Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About optimize result when query #110

Open
hdlinh1808 opened this issue Mar 11, 2024 · 3 comments
Open

About optimize result when query #110

hdlinh1808 opened this issue Mar 11, 2024 · 3 comments

Comments

@hdlinh1808
Copy link

When I parse this query:
select vpc_id from aws_ec2_instance where not not not vpc_id IS NULL
it returns a lot of bool operator, how I can remove redudant:

{"version":160001,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget":{"val":{"ColumnRef":{"fields":[{"String":{"sval":"vpc_id"}}],"location":7}},"location":7}}],"fromClause":[{"RangeVar":{"relname":"aws_ec2_instance","inh":true,"relpersistence":"p","location":19}}],"whereClause":{"BoolExpr":{"boolop":"NOT_EXPR","args":[{"BoolExpr":{"boolop":"NOT_EXPR","args":[{"BoolExpr":{"boolop":"NOT_EXPR","args":[{"NullTest":{"arg":{"ColumnRef":{"fields":[{"String":{"sval":"vpc_id"}}],"location":54}},"nulltesttype":"IS_NULL","location":61}}],"location":50}}],"location":46}}],"location":42}},"limitOption":"LIMIT_OPTION_DEFAULT","op":"SETOP_NONE"}}}]}

Thanks

@lfittl
Copy link
Member

lfittl commented Mar 12, 2024

Hi @hdlinh1808!

In order to remove the redundant NOT you would have to modify the parse tree so that the relevant parts are no longer present (I'd suggest comparing with the same query modified to your intended result).

Note that you would have to work with the deserialized version, i.e. Go structs (not JSON), returned by the Parse (not ParseToJSON), modify it and then call Deparse:

func Deparse(tree *ParseResult) (output string, err error) {

@priyanshi-yb
Copy link

priyanshi-yb commented Oct 10, 2024

Hi @lfittl , how to deserialise a JSON string into a GO struct to traverse the Tree returned by ParsePlPgSqlToJSON() ?

@lfittl
Copy link
Member

lfittl commented Oct 15, 2024

Hi @lfittl , how to deserialise a JSON string into a GO struct to traverse the Tree returned by ParsePlPgSqlToJSON() ?

There is currently no built-in mechanism for that, you'd have to create your own structs and deserialize using Go's JSON functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants