17 package com.mapd.parser.extension.ddl;
19 import org.apache.calcite.sql.SqlCall;
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.parser.SqlParserPos;
29 import org.apache.calcite.util.ImmutableNullableList;
31 import java.util.ArrayList;
32 import java.util.List;
42 private static final SqlSpecialOperator
UNIQUE =
43 new SqlSpecialOperator(
"UNIQUE", SqlKind.UNIQUE);
45 protected static final SqlSpecialOperator
PRIMARY =
46 new SqlSpecialOperator(
"PRIMARY KEY", SqlKind.PRIMARY_KEY);
48 private final SqlIdentifier
name;
87 SqlNodeList colList = SqlNodeList.of(colName);
88 return new SqlKeyConstraint(pos,
new SqlIdentifier(
"SHARD_KEY", pos), colList);
93 SqlParserPos pos, SqlIdentifier colName, SqlIdentifier
referencesCol) {
94 SqlNodeList colList = SqlNodeList.of(colName);
96 pos,
new SqlIdentifier(
"SHARED_DICT", pos), colList, referencesCol);
110 public void unparse(SqlWriter writer,
int leftPrec,
int rightPrec) {
112 writer.keyword(
"CONSTRAINT");
113 name.unparse(writer, 0, 0);
116 columnList.unparse(writer, 1, 1);
122 Map<String, Object> map = jsonBuilder.map();
124 jsonBuilder.put(map,
"type",
"SQL_COLUMN_CONSTRAINT");
126 jsonBuilder.put(map,
"name", this.name == null ? null : this.name.toString());
128 List<String> colNamesList =
new ArrayList<String>();
129 for (
int i = 0; i < columnList.size(); i++) {
130 SqlNode colNode = columnList.get(i);
131 colNamesList.add(colNode.toString());
133 jsonBuilder.put(map,
"columns", colNamesList);
135 Map<String, Object> referencesMap = jsonBuilder.map();
138 jsonBuilder.put(referencesMap,
"column", referencesCol.toString());
140 jsonBuilder.put(referencesMap,
"table", referencesCol.getComponent(0).
toString());
142 referencesMap,
"column", referencesCol.getComponent(1).
toString());
145 jsonBuilder.put(map,
"references", referencesMap);
147 return jsonBuilder.toJsonString(map);
SqlKeyConstraint(SqlParserPos pos, SqlIdentifier name, SqlNodeList columnList, SqlIdentifier referencesCol)
static SqlKeyConstraint unique(SqlParserPos pos, SqlIdentifier name, SqlNodeList columnList)
static SqlKeyConstraint sharedDict(SqlParserPos pos, SqlIdentifier colName, SqlIdentifier referencesCol)
static SqlKeyConstraint primary(SqlParserPos pos, SqlIdentifier name, SqlNodeList columnList)
SqlKeyConstraint(SqlParserPos pos, SqlIdentifier name, SqlNodeList columnList)
SqlOperator getOperator()
static final SqlSpecialOperator UNIQUE
static SqlKeyConstraint shard(SqlParserPos pos, SqlIdentifier colName)
final SqlIdentifier referencesCol
List< SqlNode > getOperandList()
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
static final SqlSpecialOperator PRIMARY
final SqlNodeList columnList