OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlRenameTable.java
Go to the documentation of this file.
1 package com.mapd.parser.extension.ddl;
2 
3 import com.google.gson.annotations.Expose;
4 
5 import org.apache.calcite.sql.SqlDdl;
6 import org.apache.calcite.sql.SqlKind;
7 import org.apache.calcite.sql.SqlNode;
9 import org.apache.calcite.sql.SqlSpecialOperator;
10 import org.apache.calcite.sql.parser.SqlParserPos;
12 import org.apache.calcite.util.JsonBuilder;
13 import org.apache.calcite.util.Pair;
14 
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Map;
18 
22 public class SqlRenameTable extends SqlDdl {
23  private static final SqlOperator OPERATOR =
24  new SqlSpecialOperator("RENAME_TABLE", SqlKind.OTHER_DDL);
25 
26  @Expose
27  private List<Pair<String, String>> tableNames = new ArrayList<Pair<String, String>>();
28 
30  final SqlParserPos pos, final List<Pair<String, String>> tableNamesIn) {
31  super(OPERATOR, pos);
32  this.tableNames = tableNamesIn;
33  }
34 
35  @Override
36  public List<SqlNode> getOperandList() {
37  return null;
38  }
39 
40  @Override
41  public String toString() {
42  JsonBuilder jsonBuilder = new EscapedStringJsonBuilder();
43  Map<String, Object> map = jsonBuilder.map();
44 
45  map.put("command", "RENAME_TABLE");
46 
47  List<Object> elements_list = jsonBuilder.list();
48  for (Pair<String, String> value : this.tableNames) {
49  Map<String, Object> pairMap = jsonBuilder.map();
50  pairMap.put("name", value.left);
51  pairMap.put("newName", value.right);
52  elements_list.add(pairMap);
53  }
54  map.put("tableNames", elements_list);
55 
56  Map<String, Object> payload = jsonBuilder.map();
57  payload.put("payload", map);
58 
59  // to Debug:
60  // System.out.println(jsonBuilder.toJsonString(payload));
61 
62  return jsonBuilder.toJsonString(payload);
63  }
64 }
SqlRenameTable(final SqlParserPos pos, final List< Pair< String, String >> tableNamesIn)
List< Pair< String, String > > tableNames