17 package com.mapd.parser.extension.ddl;
19 import org.apache.calcite.sql.SqlCreate;
20 import org.apache.calcite.sql.SqlIdentifier;
21 import org.apache.calcite.sql.SqlKind;
22 import org.apache.calcite.sql.SqlNode;
23 import org.apache.calcite.sql.SqlNodeList;
25 import org.apache.calcite.sql.SqlSpecialOperator;
26 import org.apache.calcite.sql.SqlWriter;
27 import org.apache.calcite.sql.SqlWriterConfig;
28 import org.apache.calcite.sql.dialect.CalciteSqlDialect;
29 import org.apache.calcite.sql.parser.SqlParserPos;
30 import org.apache.calcite.sql.pretty.SqlPrettyWriter;
32 import org.apache.calcite.util.ImmutableNullableList;
34 import java.util.List;
36 import java.util.Objects;
42 public final SqlIdentifier
name;
47 new SqlSpecialOperator(
"CREATE VIEW", SqlKind.CREATE_VIEW);
55 super(
OPERATOR, pos,
false, ifNotExists);
56 this.name = Objects.requireNonNull(
name);
58 this.query = Objects.requireNonNull(
query);
66 public void unparse(SqlWriter writer,
int leftPrec,
int rightPrec) {
67 writer.keyword(
"CREATE VIEW");
68 name.unparse(writer, leftPrec, rightPrec);
70 SqlWriter.Frame frame = writer.startList(
"(",
")");
73 c.unparse(writer, 0, 0);
75 writer.endList(frame);
78 writer.newlineAndIndent();
79 query.unparse(writer, 0, 0);
85 Map<String, Object> map = jsonBuilder.map();
87 jsonBuilder.put(map,
"name", this.name.toString());
89 SqlWriterConfig c = SqlPrettyWriter.config()
90 .withDialect(CalciteSqlDialect.DEFAULT)
91 .withQuoteAllIdentifiers(
false)
92 .withSelectListItemsOnSeparateLines(
false)
93 .withWhereListItemsOnSeparateLines(
false)
94 .withValuesListNewline(
false);
95 SqlPrettyWriter writer =
new SqlPrettyWriter(c);
96 this.query.unparse(writer, 0, 0);
97 jsonBuilder.put(map,
"query", writer.toString());
98 jsonBuilder.put(map,
"ifNotExists", this.ifNotExists);
100 map.put(
"command",
"CREATE_VIEW");
101 Map<String, Object> payload = jsonBuilder.map();
102 payload.put(
"payload", map);
103 return jsonBuilder.toJsonString(payload);
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
static final SqlOperator OPERATOR
final SqlNodeList columnList
List< SqlNode > getOperandList()
SqlCreateView(SqlParserPos pos, boolean ifNotExists, SqlIdentifier name, SqlNodeList columnList, SqlNode query)