199 JsonBuilder jsonBuilder =
new EscapedStringJsonBuilder();
200 Map<String, Object> map = jsonBuilder.map();
202 map.put(
"command",
"ALTER_TABLE");
203 map.put(
"tableName", this.tableName.toString());
206 map.put(
"alterType",
"RENAME_TABLE");
207 map.put(
"newTableName", this.newTableName.toString());
210 map.put(
"alterType",
"RENAME_COLUMN");
211 map.put(
"columnName", this.columnName.toString());
212 map.put(
"newColumnName", this.newColumnName.toString());
215 map.put(
"alterType",
"ADD_COLUMN");
217 List<Object> elements_list = jsonBuilder.list();
219 if (!(elementNode instanceof SqlCall)) {
220 throw new CalciteException(
"Column definition for table "
222 +
" is invalid: " + elementNode.toString(),
225 elements_list.add(elementNode);
227 map.put(
"columnData", elements_list);
232 map.put(
"alterType",
"ALTER_COLUMN");
233 if (this.columnList != null) {
234 List<Object> elements_list = jsonBuilder.list();
235 for (SqlNode elementNode : this.columnList) {
236 if (!(elementNode instanceof SqlCall)) {
237 throw new CalciteException(
"Column definition " + this.
tableName.toString()
238 +
" is invalid: " + elementNode.toString(),
242 SqlVisitor<Object> sqlVisitor =
new SqlBasicVisitor<Object>() {
244 public Object visit(SqlIdentifier
id) {
245 column_name = id.toString();
249 public Object visit(SqlDataTypeSpec spec) {
250 if (!(spec.getTypeNameSpec() instanceof SqlBasicTypeNameSpec)) {
251 throw new CalciteException(
"Type definition for column "
252 + column_name.toString()
253 +
" is invalid: " + spec.toString(),
259 String column_name =
"<UNSET>";
261 elementNode.accept(sqlVisitor);
263 elements_list.add(elementNode);
265 map.put(
"alterData", elements_list);
269 map.put(
"alterType",
"DROP_COLUMN");
270 map.put(
"columnData", this.columnList.toString());
273 map.put(
"alterType",
"ALTER_OPTIONS");
274 map.put(
"options", this.options);
278 Map<String, Object> payload = jsonBuilder.map();
279 payload.put(
"payload", map);
280 return jsonBuilder.toJsonString(payload);