Search in sources :

Example 21 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 testIndent8.

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

Example 22 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 testClausesNotOnNewLine.

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

Example 23 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 testDamiansSubQueryStyle.

@Test
public void testDamiansSubQueryStyle() throws Exception {
    // Note that ( is at the indent, SELECT is on the same line, and ) is
    // below it.
    final SqlPrettyWriter prettyWriter = new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
    prettyWriter.setSubQueryStyle(SqlWriter.SubQueryStyle.BLACK);
    checkSimple(prettyWriter, "${desc}", "${formatted}");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) Test(org.junit.Test)

Example 24 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 SqlParserTest method testSqlOptions.

@Test
public void testSqlOptions() throws SqlParseException {
    SqlNode node = getSqlParser("alter system set schema = true").parseStmt();
    SqlSetOption opt = (SqlSetOption) node;
    assertThat(opt.getScope(), equalTo("SYSTEM"));
    SqlPrettyWriter writer = new SqlPrettyWriter(CalciteSqlDialect.DEFAULT);
    assertThat(writer.format(opt.getName()), equalTo("\"SCHEMA\""));
    writer = new SqlPrettyWriter(CalciteSqlDialect.DEFAULT);
    assertThat(writer.format(opt.getValue()), equalTo("TRUE"));
    writer = new SqlPrettyWriter(CalciteSqlDialect.DEFAULT);
    assertThat(writer.format(opt), equalTo("ALTER SYSTEM SET \"SCHEMA\" = TRUE"));
    sql("alter system set \"a number\" = 1").ok("ALTER SYSTEM SET `a number` = 1").node(isDdl());
    check("alter system set flag = false", "ALTER SYSTEM SET `FLAG` = FALSE");
    check("alter system set approx = -12.3450", "ALTER SYSTEM SET `APPROX` = -12.3450");
    check("alter system set onOff = on", "ALTER SYSTEM SET `ONOFF` = `ON`");
    check("alter system set onOff = off", "ALTER SYSTEM SET `ONOFF` = `OFF`");
    check("alter system set baz = foo", "ALTER SYSTEM SET `BAZ` = `FOO`");
    check("alter system set \"a\".\"number\" = 1", "ALTER SYSTEM SET `a`.`number` = 1");
    sql("set approx = -12.3450").ok("SET `APPROX` = -12.3450").node(isDdl());
    node = getSqlParser("reset schema").parseStmt();
    opt = (SqlSetOption) node;
    assertThat(opt.getScope(), equalTo(null));
    writer = new SqlPrettyWriter(CalciteSqlDialect.DEFAULT);
    assertThat(writer.format(opt.getName()), equalTo("\"SCHEMA\""));
    assertThat(opt.getValue(), equalTo(null));
    writer = new SqlPrettyWriter(CalciteSqlDialect.DEFAULT);
    assertThat(writer.format(opt), equalTo("RESET \"SCHEMA\""));
    check("alter system RESET flag", "ALTER SYSTEM RESET `FLAG`");
    sql("reset onOff").ok("RESET `ONOFF`").node(isDdl());
    check("reset \"this\".\"is\".\"sparta\"", "RESET `this`.`is`.`sparta`");
    check("alter system reset all", "ALTER SYSTEM RESET `ALL`");
    check("reset all", "RESET `ALL`");
    // expressions not allowed
    checkFails("alter system set aString = 'abc' ^||^ 'def' ", "(?s)Encountered \"\\|\\|\" at line 1, column 34\\..*");
    // multiple assignments not allowed
    checkFails("alter system set x = 1^,^ y = 2", "(?s)Encountered \",\" at line 1, column 23\\..*");
}
Also used : SqlPrettyWriter(org.apache.calcite.sql.pretty.SqlPrettyWriter) SqlSetOption(org.apache.calcite.sql.SqlSetOption) SqlNode(org.apache.calcite.sql.SqlNode) 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