OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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.SqlCall;
6 import org.apache.calcite.sql.SqlDdl;
7 import org.apache.calcite.sql.SqlIdentifier;
8 import org.apache.calcite.sql.SqlKind;
9 import org.apache.calcite.sql.SqlNode;
10 import org.apache.calcite.sql.SqlOperator;
11 import org.apache.calcite.sql.SqlSpecialOperator;
12 import org.apache.calcite.sql.parser.SqlParserPos;
14 import org.apache.calcite.util.JsonBuilder;
15 import org.apache.calcite.util.Pair;
16 
17 import java.io.*;
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 
25 public class SqlRenameTable extends SqlDdl {
26  private static final SqlOperator OPERATOR =
27  new SqlSpecialOperator("RENAME_TABLE", SqlKind.OTHER_DDL);
28 
29  @Expose
30  private List<Pair<String, String>> tableNames = new ArrayList<Pair<String, String>>();
31  @Expose
32  private String command;
33 
35  final SqlParserPos pos, final List<Pair<String, String>> tableNamesIn) {
36  super(OPERATOR, pos);
37  this.tableNames = tableNamesIn;
38  this.command = OPERATOR.getName();
39  }
40 
41  @Override
42  public List<SqlNode> getOperandList() {
43  return null;
44  }
45 
46  @Override
47  public String toString() {
48  JsonBuilder jsonBuilder = new EscapedStringJsonBuilder();
49  Map<String, Object> map = jsonBuilder.map();
50 
51  map.put("command", "RENAME_TABLE");
52 
53  List<Object> elements_list = jsonBuilder.list();
54  for (Pair<String, String> value : this.tableNames) {
55  Map<String, Object> pairMap = jsonBuilder.map();
56  pairMap.put("name", value.left);
57  pairMap.put("newName", value.right);
58  elements_list.add(pairMap);
59  }
60  map.put("tableNames", elements_list);
61 
62  Map<String, Object> payload = jsonBuilder.map();
63  payload.put("payload", map);
64 
65  // to Debug:
66  // System.out.println(jsonBuilder.toJsonString(payload));
67 
68  return jsonBuilder.toJsonString(payload);
69  }
70 }
SqlRenameTable(final SqlParserPos pos, final List< Pair< String, String >> tableNamesIn)
List< Pair< String, String > > tableNames