Search in sources :

Example 16 with SqlPrettyWriter

use of org.apache.beam.vendor.calcite.v1_28_0.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 17 with SqlPrettyWriter

use of org.apache.beam.vendor.calcite.v1_28_0.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)

Example 18 with SqlPrettyWriter

use of org.apache.beam.vendor.calcite.v1_28_0.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));
}
Also used : SqlCall(org.apache.calcite.sql.SqlCall) SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 19 with SqlPrettyWriter

use of org.apache.beam.vendor.calcite.v1_28_0.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));
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 20 with SqlPrettyWriter

use of org.apache.beam.vendor.calcite.v1_28_0.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}");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) Test(org.junit.Test)

Aggregations

SqlPrettyWriter (org.apache.calcite.sql.pretty.SqlPrettyWriter)22 Test (org.junit.Test)13 SqlNode (org.apache.calcite.sql.SqlNode)7 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 SqlString (org.apache.calcite.sql.util.SqlString)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 SqlIdentifier (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier)2 SqlNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode)2 SqlWriter (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter)2 SqlPrettyWriter (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.pretty.SqlPrettyWriter)2 SqlCall (org.apache.calcite.sql.SqlCall)2 SqlNodeList (org.apache.calcite.sql.SqlNodeList)2 SqlSelect (org.apache.calcite.sql.SqlSelect)2 SqlWriter (org.apache.calcite.sql.SqlWriter)2 SqlParseException (org.apache.calcite.sql.parser.SqlParseException)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 MappingField (com.hazelcast.sql.impl.schema.MappingField)1