Search in sources :

Example 6 with SqlWriter

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter in project calcite by apache.

the class SqlCreateMaterializedView method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.keyword("CREATE");
    writer.keyword("MATERIALIZED VIEW");
    if (ifNotExists) {
        writer.keyword("IF NOT EXISTS");
    }
    name.unparse(writer, leftPrec, rightPrec);
    if (columnList != null) {
        SqlWriter.Frame frame = writer.startList("(", ")");
        for (SqlNode c : columnList) {
            writer.sep(",");
            c.unparse(writer, 0, 0);
        }
        writer.endList(frame);
    }
    writer.keyword("AS");
    writer.newlineAndIndent();
    query.unparse(writer, 0, 0);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 7 with SqlWriter

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter in project calcite by apache.

the class MssqlSqlDialect method unparseSqlDatetimeArithmetic.

@Override
public void unparseSqlDatetimeArithmetic(SqlWriter writer, SqlCall call, SqlKind sqlKind, int leftPrec, int rightPrec) {
    final SqlWriter.Frame frame = writer.startFunCall("DATEADD");
    SqlNode operand = call.operand(1);
    if (operand instanceof SqlIntervalLiteral) {
        // There is no DATESUB method available, so change the sign.
        unparseSqlIntervalLiteralMssql(writer, (SqlIntervalLiteral) operand, sqlKind == SqlKind.MINUS ? -1 : 1);
    } else {
        operand.unparse(writer, leftPrec, rightPrec);
    }
    writer.sep(",", true);
    call.operand(0).unparse(writer, leftPrec, rightPrec);
    writer.endList(frame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlIntervalLiteral(org.apache.calcite.sql.SqlIntervalLiteral) SqlNode(org.apache.calcite.sql.SqlNode)

Example 8 with SqlWriter

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter in project flink by apache.

the class SqlAlterHiveDatabaseProps method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    super.unparse(writer, leftPrec, rightPrec);
    writer.keyword("DBPROPERTIES");
    SqlWriter.Frame withFrame = writer.startList("(", ")");
    for (SqlNode property : originPropList) {
        printIndent(writer);
        property.unparse(writer, leftPrec, rightPrec);
    }
    writer.newlineAndIndent();
    writer.endList(withFrame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 9 with SqlWriter

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter in project flink by apache.

the class SqlAlterHiveViewProperties method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.keyword("ALTER VIEW");
    viewIdentifier.unparse(writer, leftPrec, rightPrec);
    writer.keyword("SET TBLPROPERTIES");
    SqlWriter.Frame withFrame = writer.startList("(", ")");
    for (SqlNode property : getPropertyList()) {
        printIndent(writer);
        property.unparse(writer, leftPrec, rightPrec);
    }
    writer.newlineAndIndent();
    writer.endList(withFrame);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 10 with SqlWriter

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter in project flink by apache.

the class SqlCreateHiveTable method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.keyword("CREATE");
    if (isTemporary()) {
        writer.keyword("TEMPORARY");
    }
    if (isExternal) {
        writer.keyword("EXTERNAL");
    }
    writer.keyword("TABLE");
    if (ifNotExists) {
        writer.keyword("IF NOT EXISTS");
    }
    getTableName().unparse(writer, leftPrec, rightPrec);
    // columns
    SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.create("sds"), "(", ")");
    unparseColumns(creationContext, origColList, writer, leftPrec, rightPrec);
    for (SqlTableConstraint tableConstraint : creationContext.constraints) {
        printIndent(writer);
        tableConstraint.getConstraintNameIdentifier().ifPresent(name -> {
            writer.keyword("CONSTRAINT");
            name.unparse(writer, leftPrec, rightPrec);
        });
        writer.keyword("PRIMARY KEY");
        SqlWriter.Frame pkFrame = writer.startList("(", ")");
        tableConstraint.getColumns().unparse(writer, leftPrec, rightPrec);
        writer.endList(pkFrame);
        creationContext.pkTrait.unparse(writer, leftPrec, rightPrec);
    }
    writer.newlineAndIndent();
    writer.endList(frame);
    // table comment
    getComment().ifPresent(c -> {
        writer.keyword("COMMENT");
        c.unparse(writer, leftPrec, rightPrec);
    });
    // partitions
    if (origPartColList.size() > 0) {
        writer.newlineAndIndent();
        writer.keyword("PARTITIONED BY");
        SqlWriter.Frame partitionedByFrame = writer.startList("(", ")");
        unparseColumns(creationContext, origPartColList, writer, leftPrec, rightPrec);
        writer.newlineAndIndent();
        writer.endList(partitionedByFrame);
    }
    // row format
    unparseRowFormat(writer, leftPrec, rightPrec);
    // stored as
    unparseStoredAs(writer, leftPrec, rightPrec);
    // location
    if (location != null) {
        writer.newlineAndIndent();
        writer.keyword("LOCATION");
        location.unparse(writer, leftPrec, rightPrec);
    }
    // properties
    if (originPropList.size() > 0) {
        writer.newlineAndIndent();
        writer.keyword("TBLPROPERTIES");
        unparsePropList(originPropList, writer, leftPrec, rightPrec);
    }
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlTableConstraint(org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint)

Aggregations

SqlWriter (org.apache.calcite.sql.SqlWriter)48 SqlNode (org.apache.calcite.sql.SqlNode)40 SqlNodeList (org.apache.calcite.sql.SqlNodeList)5 SqlNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode)4 SqlWriter (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlWriter)4 SqlJsonConstructorNullClause (org.apache.calcite.sql.SqlJsonConstructorNullClause)3 SqlIdentifier (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier)2 SqlPrettyWriter (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.pretty.SqlPrettyWriter)2 SqlLiteral (org.apache.calcite.sql.SqlLiteral)2 SqlTableConstraint (org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint)2 Test (org.junit.Test)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 HazelcastSqlCase (com.hazelcast.jet.sql.impl.validate.operators.special.HazelcastSqlCase)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 TimeUnitRange (org.apache.calcite.avatica.util.TimeUnitRange)1 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1