dynamobi/dynamobi — Issue #682: [FRG-190] Improve SQL pretty-printer
Author: dynamobi-build
Created: 2011-12-30 03:42:57+00:00
State: open
Labels: FRG, SQL Parser

[reporter="jvs", created="Thu, 24 Aug 2006 18:14:08 -0500 (GMT-05:00)"]
Oscar, if you have any time to study and tweak this to smooth out some of the wrinkles, I can enable any improvements you make into the way it's used in LucidEra red-zone code.

Farrago class is org.eigenbase.sql.pretty.SqlPrettyWriter (it interacts with the SqlNode class hierarchy to unparse specific constructs). Unit test is org.eigenbase.sql.test.SqlPrettyWriterTest; stepping through there should give you some idea how it works. It relies on SqlPrettyWriterTest.ref.xml (in the same directory as the .java file) for input queries and expected output formatting to diff against.

It looks like there's already a flag for setCaseClausesOnNewLines; I'm not sure if it does what you want, but if it does, I can enable it. There doesn't appear to be any support for wrapping each AND clause onto a separate line yet, so that would be a possible enhancement for ON join conditions and WHERE clauses. There's also that annoying thing where it gets the indent wrong for select lists.

Rules of engagement here are that we should not change the default existing behavior, because many diff-based tests may depend on it. So any changes or enhancements need to be added via new flags whose default values yield the current behavior. And all changes need corresponding unit tests.