Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3526

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.22.0
    • Component/s: None
    • Labels:
      None

      Description

      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

      new SqlPrettyWriter(d, p).setIndentation(4)
      

      you now write

      new SqlPrettyWriter(
          SqlPrettyWriter.config()
              .withDialect(d)
              .withAlwaysUseParentheses(p)
              .withIndentation(4))
      

      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.

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              julianhyde Julian Hyde
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: