1 package com.mapd.parser.extension.ddl;
3 import com.google.gson.annotations.Expose;
5 import org.apache.calcite.sql.SqlDdl;
6 import org.apache.calcite.sql.SqlKind;
7 import org.apache.calcite.sql.SqlNode;
8 import org.apache.calcite.sql.SqlNodeList;
10 import org.apache.calcite.sql.SqlSpecialOperator;
11 import org.apache.calcite.sql.SqlWriter;
12 import org.apache.calcite.sql.SqlWriterConfig;
13 import org.apache.calcite.sql.dialect.CalciteSqlDialect;
14 import org.apache.calcite.sql.parser.SqlParserPos;
15 import org.apache.calcite.sql.pretty.SqlPrettyWriter;
17 import org.apache.calcite.util.JsonBuilder;
19 import java.util.List;
32 new SqlSpecialOperator(
"INSERT_INTO_TABLE_AS_SELECT", SqlKind.OTHER_DDL);
35 SqlParserPos pos, SqlNode table, SqlNode
query, SqlNodeList
columnList) {
48 public void unparse(SqlWriter writer,
int leftPrec,
int rightPrec) {
49 writer.keyword(
"INSERT");
50 writer.keyword(
"INTO");
51 name.unparse(writer, leftPrec, rightPrec);
53 SqlWriter.Frame frame = writer.startList(
"(",
")");
56 c.unparse(writer, 0, 0);
58 writer.endList(frame);
61 writer.newlineAndIndent();
62 query.unparse(writer, 0, 0);
69 Map<String, Object> map = jsonBuilder.map();
71 map.put(
"command",
"INSERT_INTO_TABLE_AS_SELECT");
72 map.put(
"name", this.name.toString());
79 SqlWriterConfig c = SqlPrettyWriter.config()
80 .withDialect(CalciteSqlDialect.DEFAULT)
81 .withQuoteAllIdentifiers(
false)
82 .withSelectListItemsOnSeparateLines(
false)
83 .withWhereListItemsOnSeparateLines(
false)
84 .withValuesListNewline(
false);
85 SqlPrettyWriter writer =
new SqlPrettyWriter(c);
86 this.query.unparse(writer, 0, 0);
87 map.put(
"query", writer.toString());
90 List<Object> col_list = jsonBuilder.list();
92 col_list.add(col.toString());
94 jsonBuilder.put(map,
"columns", col_list);
97 Map<String, Object> payload = jsonBuilder.map();
98 payload.put(
"payload", map);
100 return jsonBuilder.toJsonString(payload);
static final SqlOperator OPERATOR
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
List< SqlNode > getOperandList()
SqlInsertIntoTable(SqlParserPos pos, SqlNode table, SqlNode query, SqlNodeList columnList)
final SqlNodeList columnList