All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.org.apache.calcite.sql.SqlWriterConfig Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hazelcast.org.apache.calcite.sql;

import com.hazelcast.org.apache.calcite.sql.pretty.SqlPrettyWriter;
import com.hazelcast.org.apache.calcite.util.ImmutableBeans;

/** Configuration for {@link SqlWriter} and {@link SqlPrettyWriter}. */
public interface SqlWriterConfig {
  /** Returns the dialect. */
  @ImmutableBeans.Property
  SqlDialect dialect();

  /** Sets {@link #dialect()}. */
  SqlWriterConfig withDialect(SqlDialect dialect);

  /** Returns whether to print keywords (SELECT, AS, etc.) in lower-case.
   * Default is false: keywords are printed in upper-case. */
  @ImmutableBeans.Property
  @ImmutableBeans.BooleanDefault(false)
  boolean keywordsLowerCase();

  /** Sets {@link #keywordsLowerCase}. */
  SqlWriterConfig withKeywordsLowerCase(boolean keywordsLowerCase);

  /** Returns whether to quote all identifiers, even those which would be
   * correct according to the rules of the {@link SqlDialect} if quotation
   * marks were omitted. Default is true. */
  @ImmutableBeans.Property
  @ImmutableBeans.BooleanDefault(true)
  boolean quoteAllIdentifiers();

  /** Sets {@link #quoteAllIdentifiers}. */
  SqlWriterConfig withQuoteAllIdentifiers(boolean quoteAllIdentifiers);

  /** Returns the number of spaces indentation. Default is 4. */
  @ImmutableBeans.Property
  @ImmutableBeans.IntDefault(4)
  int indentation();

  /** Sets {@link #indentation}. */
  SqlWriterConfig withIndentation(int indentation);

  /** Returns whether a clause (FROM, WHERE, GROUP BY, HAVING, WINDOW,
   * ORDER BY) starts a new line. Default is true. SELECT is always at the
   * start of a line. */
  @ImmutableBeans.Property
  @ImmutableBeans.BooleanDefault(true)
  boolean clauseStartsLine();

  /** Sets {@link #clauseStartsLine}. */
  SqlWriterConfig withClauseStartsLine(boolean clauseStartsLine);

  /** Returns whether a clause (FROM, WHERE, GROUP BY, HAVING, WINDOW,
   * ORDER BY) is followed by a new line. Default is false. */
  @ImmutableBeans.Property
  @ImmutableBeans.BooleanDefault(false)
  boolean clauseEndsLine();

  /** Sets {@link #clauseEndsLine()}. */
  SqlWriterConfig withClauseEndsLine(boolean clauseEndsLine);

  /** Returns whether each item in a SELECT list, GROUP BY list, or ORDER BY
   * list is on its own line.
   *
   * 

Default is false; * this property is superseded by {@link #selectFolding()}, * {@link #groupByFolding()}, {@link #orderByFolding()}. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(false) boolean selectListItemsOnSeparateLines(); /** Sets {@link #selectListItemsOnSeparateLines}. */ SqlWriterConfig withSelectListItemsOnSeparateLines( boolean selectListItemsOnSeparateLines); /** Returns the line-folding policy for lists in the SELECT, GROUP BY and * ORDER clauses, for items in the SET clause of UPDATE, and for items in * VALUES. * * @see #foldLength() * *

If not set, the values of * {@link #selectListItemsOnSeparateLines()}, * {@link #valuesListNewline()}, * {@link #updateSetListNewline()}, * {@link #windowDeclListNewline()} are used. */ @ImmutableBeans.Property LineFolding lineFolding(); /** Sets {@link #lineFolding()}. */ SqlWriterConfig withLineFolding(LineFolding lineFolding); /** Returns the line-folding policy for the SELECT clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding selectFolding(); /** Sets {@link #selectFolding()}. */ SqlWriterConfig withSelectFolding(LineFolding lineFolding); /** Returns the line-folding policy for the FROM clause (and JOIN). * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property @ImmutableBeans.EnumDefault("TALL") LineFolding fromFolding(); /** Sets {@link #fromFolding()}. */ SqlWriterConfig withFromFolding(LineFolding lineFolding); /** Returns the line-folding policy for the WHERE clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding whereFolding(); /** Sets {@link #whereFolding()}. */ SqlWriterConfig withWhereFolding(LineFolding lineFolding); /** Returns the line-folding policy for the GROUP BY clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding groupByFolding(); /** Sets {@link #groupByFolding()}. */ SqlWriterConfig withGroupByFolding(LineFolding lineFolding); /** Returns the line-folding policy for the HAVING clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding havingFolding(); /** Sets {@link #havingFolding()}. */ SqlWriterConfig withHavingFolding(LineFolding lineFolding); /** Returns the line-folding policy for the WINDOW clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding windowFolding(); /** Sets {@link #windowFolding()}. */ SqlWriterConfig withWindowFolding(LineFolding lineFolding); /** Returns the line-folding policy for the MATCH_RECOGNIZE clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding matchFolding(); /** Sets {@link #matchFolding()}. */ SqlWriterConfig withMatchFolding(LineFolding lineFolding); /** Returns the line-folding policy for the ORDER BY clause. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding orderByFolding(); /** Sets {@link #orderByFolding()}. */ SqlWriterConfig withOrderByFolding(LineFolding lineFolding); /** Returns the line-folding policy for the OVER clause or a window * declaration. If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding overFolding(); /** Sets {@link #overFolding()}. */ SqlWriterConfig withOverFolding(LineFolding lineFolding); /** Returns the line-folding policy for the VALUES expression. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding valuesFolding(); /** Sets {@link #valuesFolding()}. */ SqlWriterConfig withValuesFolding(LineFolding lineFolding); /** Returns the line-folding policy for the SET clause of an UPDATE statement. * If not set, the value of {@link #lineFolding()} is used. */ @ImmutableBeans.Property LineFolding updateSetFolding(); /** Sets {@link #updateSetFolding()}. */ SqlWriterConfig withUpdateSetFolding(LineFolding lineFolding); /** * Returns whether to use a fix for SELECT list indentations. * *

    *
  • If set to "false": * *
       * SELECT
       *     A as A,
       *         B as B,
       *         C as C,
       *     D
       * 
    * *
  • If set to "true" (the default): * *
       * SELECT
       *     A as A,
       *     B as B,
       *     C as C,
       *     D
       * 
    *
*/ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(true) boolean selectListExtraIndentFlag(); /** Sets {@link #selectListExtraIndentFlag}. */ SqlWriterConfig withSelectListExtraIndentFlag(boolean selectListExtraIndentFlag); /** Returns whether each declaration in a WINDOW clause should be on its own * line. * *

Default is true; * this property is superseded by {@link #windowFolding()}. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(true) boolean windowDeclListNewline(); /** Sets {@link #windowDeclListNewline}. */ SqlWriterConfig withWindowDeclListNewline(boolean windowDeclListNewline); /** Returns whether each row in a VALUES clause should be on its own * line. * *

Default is true; * this property is superseded by {@link #valuesFolding()}. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(true) boolean valuesListNewline(); /** Sets {@link #valuesListNewline}. */ SqlWriterConfig withValuesListNewline(boolean valuesListNewline); /** Returns whether each assignment in the SET clause of an UPDATE or MERGE * statement should be on its own line. * *

Default is true; * this property is superseded by {@link #updateSetFolding()}. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(true) boolean updateSetListNewline(); /** Sets {@link #updateSetListNewline}. */ SqlWriterConfig withUpdateSetListNewline(boolean updateSetListNewline); /** Returns whether a WINDOW clause should start its own line. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(false) boolean windowNewline(); /** Sets {@link #windowNewline}. */ SqlWriterConfig withWindowNewline(boolean windowNewline); /** Returns whether commas in SELECT, GROUP BY and ORDER clauses should * appear at the start of the line. Default is false. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(false) boolean leadingComma(); /** Sets {@link #leadingComma()}. */ SqlWriterConfig withLeadingComma(boolean leadingComma); /** Returns the sub-query style. * Default is {@link SqlWriter.SubQueryStyle#HYDE}. */ @ImmutableBeans.Property @ImmutableBeans.EnumDefault("HYDE") SqlWriter.SubQueryStyle subQueryStyle(); /** Sets {@link #subQueryStyle}. */ SqlWriterConfig withSubQueryStyle(SqlWriter.SubQueryStyle subQueryStyle); /** Returns whether to print a newline before each AND or OR (whichever is * higher level) in WHERE clauses. * *

NOTE: Ignored when alwaysUseParentheses is set to true. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(false) boolean whereListItemsOnSeparateLines(); /** Sets {@link #whereListItemsOnSeparateLines}. */ SqlWriterConfig withWhereListItemsOnSeparateLines( boolean whereListItemsOnSeparateLines); /** Returns whether expressions should always be included in parentheses. * Default is false. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(false) boolean alwaysUseParentheses(); /** Sets {@link #alwaysUseParentheses}. */ SqlWriterConfig withAlwaysUseParentheses(boolean alwaysUseParentheses); /** Returns the maximum line length. Default is zero, which means there is * no maximum. */ @ImmutableBeans.Property @ImmutableBeans.IntDefault(0) int lineLength(); /** Sets {@link #lineLength}. */ SqlWriterConfig withLineLength(int lineLength); /** Returns the line length at which items are chopped or folded (for clauses * that have chosen {@link LineFolding#CHOP} or {@link LineFolding#FOLD}). * Default is 80. */ @ImmutableBeans.Property @ImmutableBeans.IntDefault(80) int foldLength(); /** Sets {@link #foldLength()}. */ SqlWriterConfig withFoldLength(int lineLength); /** Returns whether the WHEN, THEN and ELSE clauses of a CASE expression * appear at the start of a new line. The default is false. */ @ImmutableBeans.Property @ImmutableBeans.BooleanDefault(false) boolean caseClausesOnNewLines(); /** Sets {@link #caseClausesOnNewLines}. */ SqlWriterConfig withCaseClausesOnNewLines(boolean caseClausesOnNewLines); /** Policy for how to do deal with long lines. * *

The following examples all have * {@link #clauseEndsLine ClauseEndsLine=true}, * {@link #indentation Indentation=4}, and * {@link #foldLength FoldLength=25} (so that the long {@code SELECT} * clause folds but the shorter {@code GROUP BY} clause does not). * *

Note that {@link #clauseEndsLine ClauseEndsLine} is observed in * STEP and TALL modes, and in CHOP mode when a line is long. * *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SQL formatted with each Folding value
FoldingExample
WIDE
   * SELECT abc, def, ghi, jkl, mno, pqr
   * FROM t
   * GROUP BY abc, def
STEP
   * SELECT
   *     abc, def, ghi, jkl, mno, pqr
   * FROM t
   * GROUP BY
   *     abc, def
FOLD
   * SELECT abc, def, ghi,
   *     jkl, mno, pqr
   * FROM t
   * GROUP BY abc, def
CHOP
   * SELECT
   *     abc,
   *     def,
   *     ghi,
   *     jkl,
   *     mno,
   *     pqr
   * FROM t
   * GROUP BY abc, def
TALL
   * SELECT
   *     abc,
   *     def,
   *     ghi,
   *     jkl,
   *     mno,
   *     pqr
   * FROM t
   * GROUP BY
   *     abc,
   *     def
*/ enum LineFolding { /** Do not wrap. Items are on the same line, regardless of length. */ WIDE, /** As {@link #WIDE} but start a new line if {@link #clauseEndsLine()}. */ STEP, /** Wrap if long. Items are on the same line, but if the line's length * exceeds {@link #foldLength()}, move items to the next line. */ FOLD, /** Chop down if long. Items are on the same line, but if the line grows * longer than {@link #foldLength()}, put all items on separate lines. */ CHOP, /** Wrap always. Items are on separate lines. */ TALL } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy