Search in sources :

Example 41 with SqlWriter

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

the class SqlCreateHiveDatabase method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.keyword("CREATE DATABASE");
    if (isIfNotExists()) {
        writer.keyword("IF NOT EXISTS");
    }
    getDatabaseName().unparse(writer, leftPrec, rightPrec);
    if (getComment().isPresent()) {
        writer.newlineAndIndent();
        writer.keyword("COMMENT");
        getComment().get().unparse(writer, leftPrec, rightPrec);
    }
    if (location != null) {
        writer.newlineAndIndent();
        writer.keyword("LOCATION");
        location.unparse(writer, leftPrec, rightPrec);
    }
    if (originPropList.size() > 0) {
        writer.keyword("WITH 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 42 with SqlWriter

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

the class SqlCreateHiveView method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.keyword("CREATE VIEW");
    if (isIfNotExists()) {
        writer.keyword("IF NOT EXISTS");
    }
    getViewName().unparse(writer, leftPrec, rightPrec);
    if (getFieldList().size() > 0) {
        getFieldList().unparse(writer, 1, rightPrec);
    }
    getComment().ifPresent(c -> {
        writer.newlineAndIndent();
        writer.keyword("COMMENT");
        c.unparse(writer, leftPrec, rightPrec);
    });
    if (originPropList.size() > 0) {
        writer.newlineAndIndent();
        writer.keyword("TBLPROPERTIES");
        SqlWriter.Frame withFrame = writer.startList("(", ")");
        for (SqlNode property : originPropList) {
            printIndent(writer);
            property.unparse(writer, leftPrec, rightPrec);
        }
        writer.newlineAndIndent();
        writer.endList(withFrame);
    }
    writer.newlineAndIndent();
    writer.keyword("AS");
    writer.newlineAndIndent();
    getQuery().unparse(writer, leftPrec, rightPrec);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

Example 43 with SqlWriter

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

the class RichSqlHiveInsert method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.startList(SqlWriter.FrameTypeEnum.SELECT);
    String insertKeyword = "INSERT INTO";
    if (isUpsert()) {
        insertKeyword = "UPSERT INTO";
    } else if (isOverwrite()) {
        insertKeyword = "INSERT OVERWRITE";
    }
    writer.sep(insertKeyword);
    final int opLeft = getOperator().getLeftPrec();
    final int opRight = getOperator().getRightPrec();
    getTargetTable().unparse(writer, opLeft, opRight);
    if (getTargetColumnList() != null) {
        getTargetColumnList().unparse(writer, opLeft, opRight);
    }
    writer.newlineAndIndent();
    if (allPartKeys != null && allPartKeys.size() > 0) {
        writer.keyword("PARTITION");
        SqlWriter.Frame frame = writer.startList("(", ")");
        for (SqlNode node : allPartKeys) {
            writer.sep(",", false);
            SqlIdentifier partKey = (SqlIdentifier) node;
            SqlProperty spec = partKeyToSpec.get(partKey);
            if (spec != null) {
                spec.unparse(writer, leftPrec, rightPrec);
            } else {
                partKey.unparse(writer, leftPrec, rightPrec);
            }
        }
        writer.endList(frame);
        writer.newlineAndIndent();
    }
    getSource().unparse(writer, 0, 0);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlProperty(org.apache.flink.sql.parser.SqlProperty) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 44 with SqlWriter

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

the class SqlAlterDatabase method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    writer.keyword("ALTER DATABASE");
    databaseName.unparse(writer, leftPrec, rightPrec);
    writer.keyword("SET");
    SqlWriter.Frame withFrame = writer.startList("(", ")");
    for (SqlNode property : propertyList) {
        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 45 with SqlWriter

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

the class SqlTableConstraint method unparse.

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    if (this.constraintName != null) {
        writer.keyword("CONSTRAINT");
        this.constraintName.unparse(writer, leftPrec, rightPrec);
    }
    this.uniqueSpec.unparse(writer, leftPrec, rightPrec);
    if (isTableConstraint) {
        SqlWriter.Frame frame = writer.startList("(", ")");
        for (SqlNode column : this.columns) {
            writer.sep(",", false);
            column.unparse(writer, leftPrec, rightPrec);
        }
        writer.endList(frame);
    }
    if (this.enforcement != null) {
        this.enforcement.unparse(writer, leftPrec, rightPrec);
    }
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlNode(org.apache.calcite.sql.SqlNode)

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