You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2019/11/20 23:11:00 UTC

[jira] [Created] (CALCITE-3526) SqlPrettyWriter should have options to fold/chop long lines, print leading commas

Julian Hyde created CALCITE-3526:
------------------------------------

             Summary: SqlPrettyWriter should have options to fold/chop long lines, print leading commas
                 Key: CALCITE-3526
                 URL: https://issues.apache.org/jira/browse/CALCITE-3526
             Project: Calcite
          Issue Type: Bug
            Reporter: Julian Hyde


SqlPrettyWriter should have options to fold/chop long lines, print leading commas.

In this change, we change how {{SqlPrettyWriter}} is configured: methods such as 
{{setIndentation}} are now deprecated, there is an immutable config object {{SqlWriterConfig}}, and the {{SqlDialect}} and {{boolean alwaysUseParentheses}} constructor arguments are also properties of the config. So, rather than
{code}
new SqlPrettyWriter(d, p).setIndentation(4)
{code}
you now write
{code}
new SqlPrettyWriter(
    SqlPrettyWriter.config()
        .withDialect(d)
        .withAlwaysUseParentheses(p)
        .withIndentation(4))
{code}

This change adds options to fold lists such as the SELECT clause: WIDE always puts items on the same line, TALL always puts items on separate lines, and FOLD and CHOP adapt. If the line is too long, FOLD fits as many items on a line as it can, whereas CHOP puts items onto separate lines. STEP is like WIDE but observes the {{clauseEndsLine}} property.

You can set folding policy for each clause separately using {{withSelectFolding}}, {{withOrderByFolding}} etc., or set the default {{withFolding}}.

A new property {{clauseEndsLine}} causes first SELECT item to be on a separate line than the SELECT keyword, and similarly other clauses.

For all options, see [SqlWriterConfig|https://calcite.apache.org/apidocs/org/apache/calcite/sql/SqlWriterConfig.html].

This changes also fixes CALCITE-1585; because config is held in an immutable object rather than the SqlPrettyWriter, {{reset()}} no longer resets settings such as {{alwaysUseParentheses}}.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)