Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add FORMAT statement #6725
Add FORMAT statement syntax. Format returns formatted statement. It is useful utility to canonicalize bunch of queries to same format. I used that for to format TPC-DS queries in #6636.
See some result examples:
changed the title from
Leverage indentation in ExpressionFormatter
Add FORMAT statement
Nov 30, 2016
I need to think about this more, but my initial thought is that this shouldn't be a SQL language feature. There are lots of tools that can format SQL queries. Ours isn't particularly good, nor is it configurable. Once you go down this route, people will continually ask for customization. Also, the output format isn't specified and can change from release to release.
I'd rather have this be a separate command line tool, or added to the CLI (either as a command line option or a special command like "help" or "exit").
For example on possible customizations, see what IntelliJ supports:
@electrum Before doing thisI used some web formatters and they were poor. I remember some changed the semantic of couple TPC-DS queries. The only advantage I see of having this tool integrated with presto is that it completely understands presto SQL syntax which may not be true for externals formatter. Note lambda extension for example I have no idea how such external formatter can behave.
I can re-implement this as special CLI command or another CLI tool. I can even make it a 3rd party command line application. Your call.
Ok, I extracted #7329 from this PR. Also I created an external tool which I use from time to time here - https://github.com/prestodb-rocks/presto-query-formatter
Said above. I am closing this pull request.