google / google/googlesql

Reconstruct a subquery from AST without formatting

Open
#39 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.6k
Forks
260
PR merge metrics
No merged PRs in 30d

Description

I parse a query to an AST and would like to print out one of its child nodes to its original string. I try to use `Unparse(child_node)` but it will format a new string. Is there a way to print its original form?

Here is my basic idea:
```cc
ParseStatement(sql, options.GetParserOptions(), &parser_output)
auto child_node =parser_output->statement()->child(0)->child(0)->child(1);
std::cout << Unparse(child_node); // this method will format the string
```

For example, the original sql is `select * from x join y on x.id = y.id`. And I hope to extract its FROM clause, which should be `x join y on x.id = y.id` in its original form.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.