This is an automated email from the ASF dual-hosted git repository.
mattcasters pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 1e20e3d60d Add more Calcite SQL format options #8337 (#8338)
1e20e3d60d is described below
commit 1e20e3d60d0812203323f97de9c8baeb577e0dae
Author: Nicolas Adment <[email protected]>
AuthorDate: Sat Sep 12 13:30:30 2026 +0200
Add more Calcite SQL format options #8337 (#8338)
* Add more Calcite SQL format options #8337
* Fix widget ID prefix, test assertion message, and tooltip grammar
---------
Co-authored-by: mattcasters <[email protected]>
---
.../ROOT/pages/technology/calcite/index.adoc | 2 +
.../apache/hop/calcite/CalciteSqlFormatter.java | 10 +--
.../hop/calcite/config/CalciteSqlFormatConfig.java | 60 ++++++++++++++----
.../config/CalciteSqlFormatConfigPlugin.java | 74 +++++++++++++++++++++-
.../config/messages/messages_en_US.properties | 14 +++-
.../config/CalciteSqlFormatConfigPluginTest.java | 2 +-
.../calcite/config/CalciteSqlFormatConfigTest.java | 39 ++++++++----
7 files changed, 166 insertions(+), 35 deletions(-)
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/technology/calcite/index.adoc
b/docs/hop-user-manual/modules/ROOT/pages/technology/calcite/index.adoc
index 9dad720457..0e606db2a8 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/technology/calcite/index.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/technology/calcite/index.adoc
@@ -38,6 +38,8 @@ In a Database SQL editor the formatter picks a Calcite
dialect from the tab's re
Quoted identifiers are accepted in PostgreSQL/ANSI double quotes
(`"public".table`), MySQL backticks, and SQL Server brackets.
Hop variable expressions such as `'${TABLE_NAME}'` are preserved.
+IMPORTANT: Comments are removed during formatting, unless you select all text
except for the comments.
+
== Options
Open the xref:hop-gui/perspective-configuration.adoc[Configuration
perspective], then **Plugins → Apache Calcite SQL formatter**.
diff --git
a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/CalciteSqlFormatter.java
b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/CalciteSqlFormatter.java
index 9caa5c0686..8cf6720676 100644
---
a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/CalciteSqlFormatter.java
+++
b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/CalciteSqlFormatter.java
@@ -27,6 +27,7 @@ import org.apache.calcite.avatica.util.Quoting;
import org.apache.calcite.config.Lex;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlWriterConfig;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
@@ -159,7 +160,8 @@ public final class CalciteSqlFormatter {
}
return buffer.toString();
}
- SqlNode toFormat = node instanceof SqlNodeList list && list.size() == 1 ?
list.get(0) : node;
+ SqlNode toFormat =
+ node instanceof SqlNodeList list && list.size() == 1 ? list.getFirst()
: node;
String formatted = pretty(toFormat, style, formatConfig).trim();
if (originalSql.trim().endsWith(";")) {
formatted = formatted + ';';
@@ -169,9 +171,9 @@ public final class CalciteSqlFormatter {
private static String pretty(
SqlNode node, CalciteSqlStyle style, CalciteSqlFormatConfig
formatConfig) {
- SqlPrettyWriter writer =
- new
SqlPrettyWriter(SqlPrettyWriter.config().withDialect(style.dialect()));
- writer.setFormatOptions(formatConfig.toSqlFormatOptions());
+
+ SqlWriterConfig config =
SqlPrettyWriter.config().withDialect(style.dialect());
+ SqlPrettyWriter writer = new
SqlPrettyWriter(formatConfig.applySqlFormat(config));
return writer.format(node);
}
diff --git
a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfig.java
b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfig.java
index 8bf2a79fa4..c875c01539 100644
---
a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfig.java
+++
b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfig.java
@@ -20,6 +20,8 @@ package org.apache.hop.calcite.config;
import java.util.function.Consumer;
import lombok.Getter;
import lombok.Setter;
+import org.apache.calcite.sql.SqlWriterConfig;
+import org.apache.calcite.sql.SqlWriterConfig.LineFolding;
import org.apache.calcite.sql.pretty.SqlFormatOptions;
import org.apache.hop.core.Const;
@@ -38,12 +40,23 @@ public class CalciteSqlFormatConfig {
private boolean alwaysUseParentheses;
private boolean caseClausesOnNewLines = true;
private boolean clauseStartsLine = true;
+ private boolean clauseEndsLine = false;
private boolean keywordsLowercase;
private boolean quoteAllIdentifiers;
private boolean selectListItemsOnSeparateLines = true;
+ private boolean fromListItemsOnSeparateLines = true;
private boolean whereListItemsOnSeparateLines = true;
private boolean windowDeclarationStartsLine = true;
private boolean windowListItemsOnSeparateLines = true;
+ private boolean groupByListItemsOnSeparateLines = true;
+ private boolean orderByListItemsOnSeparateLines = true;
+
+ /**
+ * Returns whether commas in SELECT, GROUP BY and ORDER clauses should
appear at the start of the
+ * line. Default is false.
+ */
+ private boolean leadingComma = false;
+
private int indentation = 2;
private int lineLength;
@@ -53,14 +66,19 @@ public class CalciteSqlFormatConfig {
this.alwaysUseParentheses = other.alwaysUseParentheses;
this.caseClausesOnNewLines = other.caseClausesOnNewLines;
this.clauseStartsLine = other.clauseStartsLine;
+ this.clauseEndsLine = other.clauseEndsLine;
this.keywordsLowercase = other.keywordsLowercase;
this.quoteAllIdentifiers = other.quoteAllIdentifiers;
this.selectListItemsOnSeparateLines = other.selectListItemsOnSeparateLines;
+ this.fromListItemsOnSeparateLines = other.fromListItemsOnSeparateLines;
this.whereListItemsOnSeparateLines = other.whereListItemsOnSeparateLines;
+ this.groupByListItemsOnSeparateLines =
other.groupByListItemsOnSeparateLines;
+ this.orderByListItemsOnSeparateLines =
other.orderByListItemsOnSeparateLines;
this.windowDeclarationStartsLine = other.windowDeclarationStartsLine;
this.windowListItemsOnSeparateLines = other.windowListItemsOnSeparateLines;
this.indentation = other.indentation;
this.lineLength = other.lineLength;
+ this.leadingComma = other.leadingComma;
}
/**
@@ -75,14 +93,25 @@ public class CalciteSqlFormatConfig {
changed |= applyBoolean(plugin.getAlwaysUseParentheses(), v ->
alwaysUseParentheses = v);
changed |= applyBoolean(plugin.getCaseClausesOnNewLines(), v ->
caseClausesOnNewLines = v);
changed |= applyBoolean(plugin.getClauseStartsLine(), v ->
clauseStartsLine = v);
+ changed |= applyBoolean(plugin.getClauseEndsLine(), v -> clauseEndsLine =
v);
+ changed |= applyBoolean(plugin.getLeadingComma(), v -> leadingComma = v);
changed |= applyBoolean(plugin.getKeywordsLowercase(), v ->
keywordsLowercase = v);
changed |= applyBoolean(plugin.getQuoteAllIdentifiers(), v ->
quoteAllIdentifiers = v);
changed |=
applyBoolean(
plugin.getSelectListItemsOnSeparateLines(), v ->
selectListItemsOnSeparateLines = v);
+ changed |=
+ applyBoolean(
+ plugin.getFromListItemsOnSeparateLines(), v ->
fromListItemsOnSeparateLines = v);
changed |=
applyBoolean(
plugin.getWhereListItemsOnSeparateLines(), v ->
whereListItemsOnSeparateLines = v);
+ changed |=
+ applyBoolean(
+ plugin.getGroupByListItemsOnSeparateLines(), v ->
groupByListItemsOnSeparateLines = v);
+ changed |=
+ applyBoolean(
+ plugin.getOrderByListItemsOnSeparateLines(), v ->
orderByListItemsOnSeparateLines = v);
changed |=
applyBoolean(plugin.getWindowDeclarationStartsLine(), v ->
windowDeclarationStartsLine = v);
changed |=
@@ -105,19 +134,24 @@ public class CalciteSqlFormatConfig {
return changed;
}
- public SqlFormatOptions toSqlFormatOptions() {
- return new SqlFormatOptions(
- alwaysUseParentheses,
- caseClausesOnNewLines,
- clauseStartsLine,
- keywordsLowercase,
- quoteAllIdentifiers,
- selectListItemsOnSeparateLines,
- whereListItemsOnSeparateLines,
- windowDeclarationStartsLine,
- windowListItemsOnSeparateLines,
- indentation,
- lineLength);
+ public SqlWriterConfig applySqlFormat(SqlWriterConfig config) {
+ return config
+ .withClauseStartsLine(clauseStartsLine)
+ .withClauseEndsLine(clauseEndsLine)
+ .withAlwaysUseParentheses(alwaysUseParentheses)
+ .withCaseClausesOnNewLines(caseClausesOnNewLines)
+ .withKeywordsLowerCase(keywordsLowercase)
+ .withQuoteAllIdentifiers(quoteAllIdentifiers)
+ .withLeadingComma(leadingComma)
+ .withIndentation(indentation)
+ .withLineLength(lineLength)
+ .withSelectFolding(selectListItemsOnSeparateLines ? LineFolding.TALL :
LineFolding.FOLD)
+ .withWindowFolding(windowListItemsOnSeparateLines ? LineFolding.TALL :
LineFolding.FOLD)
+ .withOverFolding(windowDeclarationStartsLine ? LineFolding.TALL :
LineFolding.FOLD)
+ .withFromFolding(fromListItemsOnSeparateLines ? LineFolding.TALL :
LineFolding.FOLD)
+ .withWhereFolding(whereListItemsOnSeparateLines ? LineFolding.TALL :
LineFolding.FOLD)
+ .withGroupByFolding(groupByListItemsOnSeparateLines ? LineFolding.TALL
: LineFolding.FOLD)
+ .withOrderByFolding(orderByListItemsOnSeparateLines ? LineFolding.TALL
: LineFolding.FOLD);
}
/**
diff --git
a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java
b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java
index e18450bcee..e4e4a7825c 100644
---
a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java
+++
b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java
@@ -107,6 +107,19 @@ public class CalciteSqlFormatConfigPlugin
negatable = true)
private Boolean clauseStartsLine;
+ @GuiWidgetElement(
+ id = "0121-sql-format-clause-ends-line",
+ order = "0121",
+ parentId = PARENT,
+ type = GuiElementType.CHECKBOX,
+ variables = false,
+ label = "i18n::CalciteSqlFormatConfigPlugin.ClauseEndsLine.Label",
+ toolTip = "i18n::CalciteSqlFormatConfigPlugin.ClauseEndsLine.Tooltip",
+ group = GROUP_LAYOUT,
+ groupOrder = "10",
+ groupType = GuiWidgetGroupType.TABS)
+ private Boolean clauseEndsLine;
+
@GuiWidgetElement(
id = "0130-sql-format-always-use-parentheses",
order = "0130",
@@ -124,6 +137,19 @@ public class CalciteSqlFormatConfigPlugin
negatable = true)
private Boolean alwaysUseParentheses;
+ @GuiWidgetElement(
+ id = "0135-sql-format-leading-comma",
+ order = "0135",
+ parentId = PARENT,
+ type = GuiElementType.CHECKBOX,
+ variables = false,
+ label = "i18n::CalciteSqlFormatConfigPlugin.LeadingComma.Label",
+ toolTip = "i18n::CalciteSqlFormatConfigPlugin.LeadingComma.Tooltip",
+ group = GROUP_LAYOUT,
+ groupOrder = "10",
+ groupType = GuiWidgetGroupType.TABS)
+ private Boolean leadingComma;
+
@GuiWidgetElement(
id = "0140-sql-format-select-list-items-on-separate-lines",
order = "0140",
@@ -142,8 +168,21 @@ public class CalciteSqlFormatConfigPlugin
private Boolean selectListItemsOnSeparateLines;
@GuiWidgetElement(
- id = "0150-sql-format-where-list-items-on-separate-lines",
- order = "0150",
+ id = "0141-sql-format-from-list-items-on-separate-lines",
+ order = "0141",
+ parentId = PARENT,
+ type = GuiElementType.CHECKBOX,
+ variables = false,
+ label =
"i18n::CalciteSqlFormatConfigPlugin.FromListItemsOnSeparateLines.Label",
+ toolTip =
"i18n::CalciteSqlFormatConfigPlugin.FromListItemsOnSeparateLines.Tooltip",
+ group = GROUP_LAYOUT,
+ groupOrder = "10",
+ groupType = GuiWidgetGroupType.TABS)
+ private Boolean fromListItemsOnSeparateLines;
+
+ @GuiWidgetElement(
+ id = "0142-sql-format-where-list-items-on-separate-lines",
+ order = "0142",
parentId = PARENT,
type = GuiElementType.CHECKBOX,
variables = false,
@@ -158,6 +197,32 @@ public class CalciteSqlFormatConfigPlugin
negatable = true)
private Boolean whereListItemsOnSeparateLines;
+ @GuiWidgetElement(
+ id = "0143-sql-format-group-by-list-items-on-separate-lines",
+ order = "0143",
+ parentId = PARENT,
+ type = GuiElementType.CHECKBOX,
+ variables = false,
+ label =
"i18n::CalciteSqlFormatConfigPlugin.GroupByListItemsOnSeparateLines.Label",
+ toolTip =
"i18n::CalciteSqlFormatConfigPlugin.GroupByListItemsOnSeparateLines.Tooltip",
+ group = GROUP_LAYOUT,
+ groupOrder = "10",
+ groupType = GuiWidgetGroupType.TABS)
+ private Boolean groupByListItemsOnSeparateLines;
+
+ @GuiWidgetElement(
+ id = "0144-sql-format-order-by-list-items-on-separate-lines",
+ order = "0144",
+ parentId = PARENT,
+ type = GuiElementType.CHECKBOX,
+ variables = false,
+ label =
"i18n::CalciteSqlFormatConfigPlugin.OrderByListItemsOnSeparateLines.Label",
+ toolTip =
"i18n::CalciteSqlFormatConfigPlugin.OrderByListItemsOnSeparateLines.Tooltip",
+ group = GROUP_LAYOUT,
+ groupOrder = "10",
+ groupType = GuiWidgetGroupType.TABS)
+ private Boolean orderByListItemsOnSeparateLines;
+
@GuiWidgetElement(
id = "0160-sql-format-case-clauses-on-new-lines",
order = "0160",
@@ -253,12 +318,17 @@ public class CalciteSqlFormatConfigPlugin
this.indentation = Integer.toString(config.getIndentation());
this.lineLength = Integer.toString(config.getLineLength());
this.clauseStartsLine = config.isClauseStartsLine();
+ this.clauseEndsLine = config.isClauseEndsLine();
this.alwaysUseParentheses = config.isAlwaysUseParentheses();
this.selectListItemsOnSeparateLines =
config.isSelectListItemsOnSeparateLines();
+ this.fromListItemsOnSeparateLines =
config.isFromListItemsOnSeparateLines();
this.whereListItemsOnSeparateLines =
config.isWhereListItemsOnSeparateLines();
+ this.groupByListItemsOnSeparateLines =
config.isGroupByListItemsOnSeparateLines();
+ this.orderByListItemsOnSeparateLines =
config.isOrderByListItemsOnSeparateLines();
this.caseClausesOnNewLines = config.isCaseClausesOnNewLines();
this.windowDeclarationStartsLine = config.isWindowDeclarationStartsLine();
this.windowListItemsOnSeparateLines =
config.isWindowListItemsOnSeparateLines();
+ this.leadingComma = config.isLeadingComma();
this.keywordsLowercase = config.isKeywordsLowercase();
this.quoteAllIdentifiers = config.isQuoteAllIdentifiers();
}
diff --git
a/plugins/tech/calcite/src/main/resources/org/apache/hop/calcite/config/messages/messages_en_US.properties
b/plugins/tech/calcite/src/main/resources/org/apache/hop/calcite/config/messages/messages_en_US.properties
index b633c58da9..de2172f709 100644
---
a/plugins/tech/calcite/src/main/resources/org/apache/hop/calcite/config/messages/messages_en_US.properties
+++
b/plugins/tech/calcite/src/main/resources/org/apache/hop/calcite/config/messages/messages_en_US.properties
@@ -19,21 +19,31 @@ CalciteSqlFormatConfigPlugin.Group.Layout=Layout
CalciteSqlFormatConfigPlugin.Group.Keywords=Keywords and identifiers
CalciteSqlFormatConfigPlugin.Indentation.Label=Indentation (spaces)
CalciteSqlFormatConfigPlugin.Indentation.Tooltip=Number of spaces to indent
nested SQL. Calcite default is 4; Hop default is 2.
+CalciteSqlFormatConfigPlugin.LeadingComma.Label=Leading comma
+CalciteSqlFormatConfigPlugin.LeadingComma.Tooltip=Commas in SELECT, GROUP BY
and ORDER clauses should appear at the start of the line.
CalciteSqlFormatConfigPlugin.LineLength.Label=Line length
CalciteSqlFormatConfigPlugin.LineLength.Tooltip=Preferred maximum line length.
0 means no maximum.
CalciteSqlFormatConfigPlugin.ClauseStartsLine.Label=Clause starts a new line
CalciteSqlFormatConfigPlugin.ClauseStartsLine.Tooltip=Start FROM, WHERE, GROUP
BY, HAVING, WINDOW and ORDER BY on a new line.
+CalciteSqlFormatConfigPlugin.ClauseEndsLine.Label=Clause is followed by a new
line
+CalciteSqlFormatConfigPlugin.ClauseEndsLine.Tooltip=Clause (FROM, WHERE, GROUP
BY, HAVING, WINDOW, ORDER BY) is followed by a new line
CalciteSqlFormatConfigPlugin.AlwaysUseParentheses.Label=Always use parentheses
CalciteSqlFormatConfigPlugin.AlwaysUseParentheses.Tooltip=Wrap every
expression in parentheses even when operator precedence does not require it.
-CalciteSqlFormatConfigPlugin.SelectListItemsOnSeparateLines.Label=SELECT list
items on separate lines
+CalciteSqlFormatConfigPlugin.SelectListItemsOnSeparateLines.Label=SELECT items
on separate lines
CalciteSqlFormatConfigPlugin.SelectListItemsOnSeparateLines.Tooltip=Put each
item in the SELECT list on its own line.
+CalciteSqlFormatConfigPlugin.FromListItemsOnSeparateLines.Label=FROM items on
separate lines
+CalciteSqlFormatConfigPlugin.FromListItemsOnSeparateLines.Tooltip=Put each
item in the FROM list on its own line.
CalciteSqlFormatConfigPlugin.WhereListItemsOnSeparateLines.Label=WHERE items
on separate lines
CalciteSqlFormatConfigPlugin.WhereListItemsOnSeparateLines.Tooltip=Put each
item in the WHERE list on its own line.
+CalciteSqlFormatConfigPlugin.OrderByListItemsOnSeparateLines.Label=ORDER BY
items on separate lines
+CalciteSqlFormatConfigPlugin.OrderByListItemsOnSeparateLines.Tooltip=Put each
item in an ORDER BY list on its own line.
+CalciteSqlFormatConfigPlugin.GroupByListItemsOnSeparateLines.Label=GROUP BY
items on separate lines
+CalciteSqlFormatConfigPlugin.GroupByListItemsOnSeparateLines.Tooltip=Put each
item in a GROUP BY list on its own line.
CalciteSqlFormatConfigPlugin.CaseClausesOnNewLines.Label=CASE clauses on new
lines
CalciteSqlFormatConfigPlugin.CaseClausesOnNewLines.Tooltip=Put WHEN, THEN and
ELSE of a CASE expression at the start of a new line.
CalciteSqlFormatConfigPlugin.WindowDeclarationStartsLine.Label=WINDOW
declaration starts a new line
CalciteSqlFormatConfigPlugin.WindowDeclarationStartsLine.Tooltip=Start a
WINDOW declaration on a new line.
-CalciteSqlFormatConfigPlugin.WindowListItemsOnSeparateLines.Label=WINDOW list
items on separate lines
+CalciteSqlFormatConfigPlugin.WindowListItemsOnSeparateLines.Label=WINDOW items
on separate lines
CalciteSqlFormatConfigPlugin.WindowListItemsOnSeparateLines.Tooltip=Put each
item in a WINDOW list on its own line.
CalciteSqlFormatConfigPlugin.KeywordsLowercase.Label=Keywords in lower case
CalciteSqlFormatConfigPlugin.KeywordsLowercase.Tooltip=Print SQL keywords such
as SELECT and FROM in lower case.
diff --git
a/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPluginTest.java
b/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPluginTest.java
index d9b7693785..d61cdfde04 100644
---
a/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPluginTest.java
+++
b/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPluginTest.java
@@ -59,6 +59,6 @@ class CalciteSqlFormatConfigPluginTest {
assertTrue(
element.type() == GuiElementType.CHECKBOX || element.type() ==
GuiElementType.TEXT);
}
- assertEquals(11, widgets, "SqlFormatOptions has 11 fields");
+ assertEquals(16, widgets, "SqlFormatOptions has 16 fields");
}
}
diff --git
a/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigTest.java
b/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigTest.java
index 6ad1d19eb1..f1682ae9e3 100644
---
a/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigTest.java
+++
b/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigTest.java
@@ -21,7 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.apache.calcite.sql.pretty.SqlFormatOptions;
+import org.apache.calcite.sql.SqlWriterConfig;
+import org.apache.calcite.sql.SqlWriterConfig.LineFolding;
+import org.apache.calcite.sql.pretty.SqlPrettyWriter;
import org.apache.hop.calcite.CalciteSqlFormatter;
import org.junit.jupiter.api.Test;
@@ -33,27 +35,38 @@ class CalciteSqlFormatConfigTest {
config.setAlwaysUseParentheses(true);
config.setCaseClausesOnNewLines(false);
config.setClauseStartsLine(false);
+ config.setLeadingComma(true);
config.setKeywordsLowercase(true);
config.setQuoteAllIdentifiers(true);
config.setSelectListItemsOnSeparateLines(false);
+ config.setFromListItemsOnSeparateLines(false);
config.setWhereListItemsOnSeparateLines(false);
+ config.setGroupByListItemsOnSeparateLines(false);
+ config.setOrderByListItemsOnSeparateLines(false);
config.setWindowDeclarationStartsLine(false);
config.setWindowListItemsOnSeparateLines(false);
config.setIndentation(8);
config.setLineLength(80);
- SqlFormatOptions options = config.toSqlFormatOptions();
- assertTrue(options.isAlwaysUseParentheses());
- assertFalse(options.isCaseClausesOnNewLines());
- assertFalse(options.isClauseStartsLine());
- assertTrue(options.isKeywordsLowercase());
- assertTrue(options.isQuoteAllIdentifiers());
- assertFalse(options.isSelectListItemsOnSeparateLines());
- assertFalse(options.isWhereListItemsOnSeparateLines());
- assertFalse(options.isWindowDeclarationStartsLine());
- assertFalse(options.isWindowListItemsOnSeparateLines());
- assertEquals(8, options.getIndentation());
- assertEquals(80, options.getLineLength());
+ SqlWriterConfig writerConfig =
config.applySqlFormat(SqlPrettyWriter.config());
+
+ assertTrue(writerConfig.alwaysUseParentheses());
+ assertFalse(writerConfig.caseClausesOnNewLines());
+ assertFalse(writerConfig.clauseStartsLine());
+ assertFalse(writerConfig.clauseEndsLine());
+ assertTrue(writerConfig.leadingComma());
+ assertTrue(writerConfig.keywordsLowerCase());
+ assertTrue(writerConfig.quoteAllIdentifiers());
+ assertEquals(LineFolding.FOLD, writerConfig.selectFolding());
+ assertEquals(LineFolding.FOLD, writerConfig.fromFolding());
+ assertEquals(LineFolding.FOLD, writerConfig.whereFolding());
+ assertEquals(LineFolding.FOLD, writerConfig.groupByFolding());
+ assertEquals(LineFolding.FOLD, writerConfig.orderByFolding());
+ assertEquals(LineFolding.FOLD, writerConfig.windowFolding());
+ assertEquals(LineFolding.FOLD, writerConfig.overFolding());
+
+ assertEquals(8, writerConfig.indentation());
+ assertEquals(80, writerConfig.lineLength());
}
@Test