use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.
the class SqlPrettyWriterTest method assertExprPrintsTo.
protected void assertExprPrintsTo(boolean newlines, final String sql, String expected) {
final SqlCall valuesCall = (SqlCall) parseQuery("VALUES (" + sql + ")");
final SqlCall rowCall = valuesCall.operand(0);
final SqlNode node = rowCall.operand(0);
final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
prettyWriter.setAlwaysUseParentheses(false);
if (newlines) {
prettyWriter.setCaseClausesOnNewLines(true);
}
String actual = prettyWriter.format(node);
getDiffRepos().assertEquals("formatted", expected, actual);
// Now parse the result, and make sure it is structurally equivalent
// to the original.
final String actual2 = actual.replaceAll("`", "\"");
final SqlNode valuesCall2 = parseQuery("VALUES (" + actual2 + ")");
assertTrue(valuesCall.equalsDeep(valuesCall2, Litmus.THROW));
}
use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.
the class SqlPrettyWriterTest method assertPrintsTo.
protected void assertPrintsTo(boolean newlines, final String sql, String expected) {
final SqlNode node = parseQuery(sql);
final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
prettyWriter.setAlwaysUseParentheses(false);
if (newlines) {
prettyWriter.setCaseClausesOnNewLines(true);
}
String actual = prettyWriter.format(node);
getDiffRepos().assertEquals("formatted", expected, actual);
// Now parse the result, and make sure it is structurally equivalent
// to the original.
final String actual2 = actual.replaceAll("`", "\"");
final SqlNode node2 = parseQuery(actual2);
assertTrue(node.equalsDeep(node2, Litmus.THROW));
}
use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.
the class SqlPrettyWriterTest method testParenthesizeAllExprs.
@Test
public void testParenthesizeAllExprs() throws Exception {
final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
prettyWriter.setAlwaysUseParentheses(true);
checkSimple(prettyWriter, "${desc}", "${formatted}");
}
use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.
the class SqlPrettyWriterTest method testIndent8.
@Test
public void testIndent8() throws Exception {
final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
prettyWriter.setIndentation(8);
checkSimple(prettyWriter, "${desc}", "${formatted}");
}
use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.
the class SqlPrettyWriterTest method testClausesNotOnNewLine.
@Test
public void testClausesNotOnNewLine() throws Exception {
final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
prettyWriter.setClauseStartsLine(false);
checkSimple(prettyWriter, "${desc}", "${formatted}");
}
Aggregations