17 package com.mapd.parser.extension.ddl;
21 import org.apache.calcite.runtime.CalciteException;
22 import org.apache.calcite.sql.SqlCall;
23 import org.apache.calcite.sql.SqlCreate;
24 import org.apache.calcite.sql.SqlIdentifier;
25 import org.apache.calcite.sql.SqlKind;
26 import org.apache.calcite.sql.SqlNode;
27 import org.apache.calcite.sql.SqlNodeList;
29 import org.apache.calcite.sql.SqlSpecialOperator;
30 import org.apache.calcite.sql.SqlWriter;
31 import org.apache.calcite.sql.SqlWriterConfig;
32 import org.apache.calcite.sql.dialect.CalciteSqlDialect;
33 import org.apache.calcite.sql.parser.SqlParserPos;
34 import org.apache.calcite.sql.pretty.SqlPrettyWriter;
36 import org.apache.calcite.util.ImmutableNullableList;
37 import org.apache.calcite.util.JsonBuilder;
39 import java.util.List;
41 import java.util.Objects;
48 public final SqlIdentifier
name;
53 new SqlSpecialOperator(
"CREATE MODEL", SqlKind.OTHER_DDL);
63 super(
OPERATOR, pos, replace, ifNotExists);
64 this.modelType = Objects.requireNonNull(
modelType);
65 this.name = Objects.requireNonNull(
name);
66 this.options = withOptions;
75 public void unparse(SqlWriter writer,
int leftPrec,
int rightPrec) {
77 writer.keyword(
"CREATE OR REPLACE");
79 writer.keyword(
"CREATE");
81 writer.keyword(
"MODEL");
83 writer.keyword(
"IF NOT EXISTS");
85 writer.keyword(
"OF TYPE");
86 modelType.unparse(writer, leftPrec, rightPrec);
87 name.unparse(writer, leftPrec, rightPrec);
90 writer.newlineAndIndent();
91 query.unparse(writer, 0, 0);
98 Map<String, Object> map = jsonBuilder.map();
100 jsonBuilder.put(map,
"command",
"CREATE_MODEL");
101 jsonBuilder.put(map,
"type", this.modelType.toString());
102 jsonBuilder.put(map,
"name", this.name.toString());
110 SqlWriterConfig c = SqlPrettyWriter.config()
111 .withDialect(CalciteSqlDialect.DEFAULT)
112 .withQuoteAllIdentifiers(
false)
113 .withSelectListItemsOnSeparateLines(
false)
114 .withWhereListItemsOnSeparateLines(
false)
115 .withValuesListNewline(
false);
116 SqlPrettyWriter writer =
new SqlPrettyWriter(c);
117 this.query.unparse(writer, 0, 0);
118 jsonBuilder.put(map,
"query", writer.toString());
121 jsonBuilder.put(map,
"replace", getReplace());
122 jsonBuilder.put(map,
"ifNotExists", this.ifNotExists);
124 map.put(
"options", this.options);
126 Map<String, Object> payload = jsonBuilder.map();
127 payload.put(
"payload", map);
132 return jsonBuilder.toJsonString(payload);
static final SqlOperator OPERATOR
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
final HeavyDBOptionsMap options
List< SqlNode > getOperandList()
SqlCreateModel(SqlParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier modelType, SqlIdentifier name, HeavyDBOptionsMap withOptions, SqlNode query)
final SqlIdentifier modelType