OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.parser.extension.ddl.SqlAlterTable Class Reference
+ Inheritance diagram for com.mapd.parser.extension.ddl.SqlAlterTable:
+ Collaboration diagram for com.mapd.parser.extension.ddl.SqlAlterTable:

Classes

enum  AlterType
 
class  Builder
 

Public Member Functions

 SqlAlterTable (final SqlParserPos pos, final SqlIdentifier name)
 
 SqlAlterTable (final SqlParserPos pos, final AlterType alterType, final String tableName, final String newTableName, final String columnName, final String newColumnName, final SqlNodeList columnList, final Map< String, String > options)
 
List< SqlNode > getOperandList ()
 
void unparse (SqlWriter writer, int leftPrec, int rightPrec)
 
String toString ()
 

Private Attributes

AlterType alterType
 
String tableName
 
String newTableName
 
String columnName
 
String newColumnName
 
String command
 
SqlNodeList columnList
 
Map< String, String > options
 

Static Private Attributes

static final SqlOperator OPERATOR
 

Detailed Description

Class that encapsulates all information associated with a ALTER TABLE DDL command.

Definition at line 47 of file SqlAlterTable.java.

Constructor & Destructor Documentation

com.mapd.parser.extension.ddl.SqlAlterTable.SqlAlterTable ( final SqlParserPos  pos,
final SqlIdentifier  name 
)
inline

Definition at line 160 of file SqlAlterTable.java.

References com.mapd.parser.extension.ddl.SqlAlterTable.OPERATOR.

Referenced by com.mapd.parser.extension.ddl.SqlAlterTable.Builder.build().

160  {
161  super(OPERATOR, pos);
162  this.tableName = name.toString();
163  }

+ Here is the caller graph for this function:

com.mapd.parser.extension.ddl.SqlAlterTable.SqlAlterTable ( final SqlParserPos  pos,
final AlterType  alterType,
final String  tableName,
final String  newTableName,
final String  columnName,
final String  newColumnName,
final SqlNodeList  columnList,
final Map< String, String >  options 
)
inline

Definition at line 165 of file SqlAlterTable.java.

References com.mapd.parser.extension.ddl.SqlAlterTable.alterType, com.mapd.parser.extension.ddl.SqlAlterTable.columnList, com.mapd.parser.extension.ddl.SqlAlterTable.columnName, com.mapd.parser.extension.ddl.SqlAlterTable.newColumnName, com.mapd.parser.extension.ddl.SqlAlterTable.newTableName, com.mapd.parser.extension.ddl.SqlAlterTable.OPERATOR, com.mapd.parser.extension.ddl.SqlAlterTable.options, and com.mapd.parser.extension.ddl.SqlAlterTable.tableName.

172  {
173  super(OPERATOR, pos);
174  this.alterType = alterType;
175  this.tableName = tableName;
176  this.newTableName = newTableName;
177  this.columnName = columnName;
178  this.newColumnName = newColumnName;
179  this.options = options;
180  this.columnList = columnList;
181  this.command = OPERATOR.getName();
182  }

Member Function Documentation

List<SqlNode> com.mapd.parser.extension.ddl.SqlAlterTable.getOperandList ( )
inline

Definition at line 185 of file SqlAlterTable.java.

185  {
186  // Add the operands here
187  return null;
188  }
String com.mapd.parser.extension.ddl.SqlAlterTable.toString ( )
inline

Definition at line 198 of file SqlAlterTable.java.

References com.mapd.parser.extension.ddl.SqlAlterTable.alterType, com.mapd.parser.extension.ddl.SqlAlterTable.columnList, com.mapd.parser.extension.ddl.SqlAlterTable.columnName, and com.mapd.parser.extension.ddl.SqlAlterTable.tableName.

198  {
199  JsonBuilder jsonBuilder = new EscapedStringJsonBuilder();
200  Map<String, Object> map = jsonBuilder.map();
201 
202  map.put("command", "ALTER_TABLE");
203  map.put("tableName", this.tableName.toString());
204  switch (this.alterType) {
205  case RENAME_TABLE:
206  map.put("alterType", "RENAME_TABLE");
207  map.put("newTableName", this.newTableName.toString());
208  break;
209  case RENAME_COLUMN:
210  map.put("alterType", "RENAME_COLUMN");
211  map.put("columnName", this.columnName.toString());
212  map.put("newColumnName", this.newColumnName.toString());
213  break;
214  case ADD_COLUMN:
215  map.put("alterType", "ADD_COLUMN");
216  if (this.columnList != null) {
217  List<Object> elements_list = jsonBuilder.list();
218  for (SqlNode elementNode : this.columnList) {
219  if (!(elementNode instanceof SqlCall)) {
220  throw new CalciteException("Column definition for table "
221  + this.columnName.toString()
222  + " is invalid: " + elementNode.toString(),
223  null);
224  }
225  elements_list.add(elementNode);
226  }
227  map.put("columnData", elements_list);
228  }
229 
230  break;
231  case ALTER_COLUMN:
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(),
239  null);
240  }
241 
242  SqlVisitor<Object> sqlVisitor = new SqlBasicVisitor<Object>() {
243  @Override
244  public Object visit(SqlIdentifier id) {
245  column_name = id.toString();
246  return null;
247  }
248  @Override
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(),
254  null);
255  }
256  return null;
257  }
258 
259  String column_name = "<UNSET>";
260  };
261  elementNode.accept(sqlVisitor);
262 
263  elements_list.add(elementNode);
264  }
265  map.put("alterData", elements_list);
266  }
267  break;
268  case DROP_COLUMN:
269  map.put("alterType", "DROP_COLUMN");
270  map.put("columnData", this.columnList.toString());
271  break;
272  case ALTER_OPTIONS:
273  map.put("alterType", "ALTER_OPTIONS");
274  map.put("options", this.options);
275  break;
276  }
277 
278  Map<String, Object> payload = jsonBuilder.map();
279  payload.put("payload", map);
280  return jsonBuilder.toJsonString(payload);
281  }
void com.mapd.parser.extension.ddl.SqlAlterTable.unparse ( SqlWriter  writer,
int  leftPrec,
int  rightPrec 
)
inline

Definition at line 191 of file SqlAlterTable.java.

191  {
192  writer.keyword("ALTER");
193  writer.keyword("TABLE");
194  // add other options data here when/as necessary
195  }

Member Data Documentation

AlterType com.mapd.parser.extension.ddl.SqlAlterTable.alterType
private
SqlNodeList com.mapd.parser.extension.ddl.SqlAlterTable.columnList
private
String com.mapd.parser.extension.ddl.SqlAlterTable.columnName
private
String com.mapd.parser.extension.ddl.SqlAlterTable.command
private

Definition at line 154 of file SqlAlterTable.java.

String com.mapd.parser.extension.ddl.SqlAlterTable.newColumnName
private
String com.mapd.parser.extension.ddl.SqlAlterTable.newTableName
private
final SqlOperator com.mapd.parser.extension.ddl.SqlAlterTable.OPERATOR
staticprivate
Initial value:
=
new SqlSpecialOperator("ALTER_TABLE", SqlKind.OTHER_DDL)

Definition at line 48 of file SqlAlterTable.java.

Referenced by com.mapd.parser.extension.ddl.SqlAlterTable.SqlAlterTable().

Map<String, String> com.mapd.parser.extension.ddl.SqlAlterTable.options
private
String com.mapd.parser.extension.ddl.SqlAlterTable.tableName
private

The documentation for this class was generated from the following file: