17 package com.mapd.parser.extension.ddl;
19 import com.google.common.collect.ImmutableList;
24 import org.apache.calcite.schema.ColumnStrategy;
25 import org.apache.calcite.sql.SqlBasicTypeNameSpec;
26 import org.apache.calcite.sql.SqlCall;
27 import org.apache.calcite.sql.SqlIdentifier;
28 import org.apache.calcite.sql.SqlKind;
29 import org.apache.calcite.sql.SqlNode;
31 import org.apache.calcite.sql.SqlSpecialOperator;
32 import org.apache.calcite.sql.SqlTypeNameSpec;
33 import org.apache.calcite.sql.SqlWriter;
34 import org.apache.calcite.sql.parser.SqlParserPos;
37 import java.util.List;
47 private static final SqlSpecialOperator
OPERATOR =
48 new SqlSpecialOperator(
"COLUMN_DECL", SqlKind.COLUMN_DECL);
50 public final SqlIdentifier
name;
79 public void unparse(SqlWriter writer,
int leftPrec,
int rightPrec) {
80 name.unparse(writer, 0, 0);
81 dataType.unparse(writer, 0, 0);
82 if (
dataType.getNullable() != null && !dataType.getNullable()) {
83 writer.keyword(
"NOT NULL");
88 writer.keyword(
"DEFAULT");
92 throw new AssertionError(
"unexpected: " +
strategy);
97 private void exp(SqlWriter writer) {
98 if (writer.isAlwaysUseParentheses()) {
99 defaultValue.unparse(writer, 0, 0);
102 defaultValue.unparse(writer, 0, 0);
110 Map<String, Object> map = jsonBuilder.map();
112 jsonBuilder.put(map,
"type",
"SQL_COLUMN_DECLARATION");
114 jsonBuilder.put(map,
"name",
name == null ? null : name.toString());
117 map,
"default",
defaultValue == null ? null : defaultValue.toString());
118 jsonBuilder.put(map,
"nullable", !Boolean.FALSE.equals(dataType.getNullable()));
119 jsonBuilder.put(map,
"encodingType", dataType.getEncodingString());
120 jsonBuilder.put(map,
"encodingSize", dataType.getEncodingSize());
122 SqlTypeNameSpec dataTypeSpec = dataType.getTypeNameSpec();
124 map = ((HeavyDBGeoTypeNameSpec) dataTypeSpec).toJsonMap(map);
126 boolean isText =
false;
128 HeavyDBTypeNameSpec heavyDBDataTypeSpec = (HeavyDBTypeNameSpec) dataTypeSpec;
130 jsonBuilder.put(map,
"arraySize", heavyDBDataTypeSpec.getArraySize());
132 isText = heavyDBDataTypeSpec.getIsText();
135 map,
"precision", ((SqlBasicTypeNameSpec) dataTypeSpec).getPrecision());
136 jsonBuilder.put(map,
"scale", ((SqlBasicTypeNameSpec) dataTypeSpec).getScale());
138 jsonBuilder.put(map,
"sqltype",
"TEXT");
145 return jsonBuilder.toJsonString(map);
final ColumnStrategy strategy
SqlOperator getOperator()
List< SqlNode > getOperandList()
void exp(SqlWriter writer)
final HeavyDBSqlDataTypeSpec dataType
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
final SqlNode defaultValue
static final SqlSpecialOperator OPERATOR
SqlColumnDeclaration(SqlParserPos pos, SqlIdentifier name, HeavyDBSqlDataTypeSpec dataType, SqlNode defaultValue, ColumnStrategy strategy)