Search in sources :

Example 16 with SqlPrettyWriter

use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.

the class SqlPrettyWriterTest method testSelectListExtraIndentFlag.

@Test
public void testSelectListExtraIndentFlag() throws Exception {
    final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
    prettyWriter.setSelectListItemsOnSeparateLines(true);
    prettyWriter.setSelectListExtraIndentFlag(false);
    checkSimple(prettyWriter, "${desc}", "${formatted}");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) Test(org.junit.Test)

Example 17 with SqlPrettyWriter

use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.

the class SqlPrettyWriterTest method testOnlyQuoteIdentifiersWhichNeedIt.

@Test
public void testOnlyQuoteIdentifiersWhichNeedIt() throws Exception {
    final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
    prettyWriter.setQuoteAllIdentifiers(false);
    checkSimple(prettyWriter, "${desc}", "${formatted}");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) Test(org.junit.Test)

Example 18 with SqlPrettyWriter

use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.

the class SqlPrettyWriterTest method checkPrettySeparateLines.

private void checkPrettySeparateLines(String sql) {
    final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
    prettyWriter.setSelectListItemsOnSeparateLines(true);
    prettyWriter.setSelectListExtraIndentFlag(false);
    final SqlNode node = parseQuery(sql);
    // Describe settings
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    prettyWriter.describe(pw, true);
    pw.flush();
    String desc = sw.toString();
    getDiffRepos().assertEquals("desc", "${desc}", desc);
    prettyWriter.setWhereListItemsOnSeparateLines(true);
    // Format
    String actual = prettyWriter.format(node);
    getDiffRepos().assertEquals("formatted", "${formatted}", actual);
}
Also used : StringWriter(java.io.StringWriter) SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) SqlNode(org.apache.calcite.sql.SqlNode) PrintWriter(java.io.PrintWriter)

Example 19 with SqlPrettyWriter

use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.

the class SqlPrettyWriterTest method testKeywordsLowerCase.

@Test
public void testKeywordsLowerCase() throws Exception {
    final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
    prettyWriter.setKeywordsLowerCase(true);
    checkSimple(prettyWriter, "${desc}", "${formatted}");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) Test(org.junit.Test)

Example 20 with SqlPrettyWriter

use of org.apache.calcite.sql.pretty.SqlPrettyWriter in project calcite by apache.

the class SqlPrettyWriterTest method testSelectListItemsOnSeparateLines.

@Test
public void testSelectListItemsOnSeparateLines() throws Exception {
    final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
    prettyWriter.setSelectListItemsOnSeparateLines(true);
    checkSimple(prettyWriter, "${desc}", "${formatted}");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) Test(org.junit.Test)

Aggregations

SqlPrettyWriter (org.apache.calcite.sql.pretty.SqlPrettyWriter)30 SqlNode (org.apache.calcite.sql.SqlNode)12 Test (org.junit.Test)12 SqlWriterConfig (org.apache.calcite.sql.SqlWriterConfig)7 SQLException (java.sql.SQLException)4 SqlCall (org.apache.calcite.sql.SqlCall)4 SqlParseException (org.apache.calcite.sql.parser.SqlParseException)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 PreparedStatement (java.sql.PreparedStatement)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RelRoot (org.apache.calcite.rel.RelRoot)3 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)3 SqlString (org.apache.calcite.sql.util.SqlString)3 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)3 Planner (org.apache.calcite.tools.Planner)3 RelConversionException (org.apache.calcite.tools.RelConversionException)3 ValidationException (org.apache.calcite.tools.ValidationException)3 SqlIdentifier (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier)2