-
Notifications
You must be signed in to change notification settings - Fork 203
Deparser: Add optional formatting/pretty printing #293
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
Conversation
deff0ac to
eac8109
Compare
msakrejda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not look at the code, but I reviewed the examples, and they all look pretty good. I agree with the TODOs, but I think OVER() is the only one I'd really miss.
| @@ -0,0 +1,6 @@ | |||
| --- TODO: Should we split the IN list items here? | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
SELECT a
FROM b
WHERE
c IN (1, 2, 3)
AND d IN (
'something longer', 'something longer 2', 'something longer 3',
'something longer 4', 'something longer 5', ''
)? Yeah, that might be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I will however defer this for now, it seems, based on doing some more investigation just now.
Figuring out how to make this work is non-trivial, and I'd like to get a first version of this code committed soon (and I don't think fixing this will break the API).
| @@ -0,0 +1,15 @@ | |||
| --- TODO: The parenthesis around the first UNION are likely unnecessary | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may or may not address this before merging, but for now I've put this on the "could do in a follow-up" list.
| @@ -0,0 +1,3 @@ | |||
| --- TODO: Limit how many items we put on one line | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this is the same issue as the IN list case, so I'll fix those at the same time in a follow-up.
|
|
||
| // Pretty print options | ||
| bool pretty_print; | ||
| int indent_size; // Indentation size (Default 4 spaces) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think 2 spaces would generally work better for this kind of formatting, but since it's configurable, it's not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do find the 4 spaces helpful for tests since it makes the indentation levels clearly visible, but otherwise agree that in practical use 2 spaces is likely more convenient (and that's how we can use this in the app).
Thank you for the review! |
b70ff3b to
d427bc1
Compare
msepga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about one condition (left a comment), but otherwise LGTM 👍
This allows more flexibility in subsequent commits to not directly emit each string into the final result. Whilst this is a large change it does not have any logic changes.
This matches other XML functions as well as the Postgres documentation, since these are closer to function argument names than regular keywords.
Prefer (..)::type syntax, unless we are already in a function call.
Introduces a new optional pretty print mode that emits a human readable output. A detailed explanation of the mechanism can be found at the start of the deparser file. New test cases are added from depesz' pg-sql-prettyprinter project, though stylistic choices differ, and the output logic was developed independently.
222b563 to
8e78c33
Compare
TODO
db/structure.sql)Defer until later
deparseExprList(e.g. see21-in.psqland03-many-columns.psqlexamples)EXPLAIN(e.g. see12-explains.d/01-base.psqlexample)35-setops.psqlexample)