OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlCreateDataframe.java
Go to the documentation of this file.
1 package com.mapd.parser.extension.ddl;
2 
3 import com.google.gson.annotations.Expose;
5 
6 import org.apache.calcite.runtime.CalciteException;
7 import org.apache.calcite.sql.SqlCall;
8 import org.apache.calcite.sql.SqlCreate;
9 import org.apache.calcite.sql.SqlIdentifier;
10 import org.apache.calcite.sql.SqlKind;
11 import org.apache.calcite.sql.SqlNode;
12 import org.apache.calcite.sql.SqlNodeList;
14 import org.apache.calcite.sql.SqlSpecialOperator;
15 import org.apache.calcite.sql.parser.SqlParserPos;
17 import org.apache.calcite.util.JsonBuilder;
18 
19 import java.util.List;
20 import java.util.Map;
21 
25 public class SqlCreateDataframe extends SqlCreate {
26  private static final SqlOperator OPERATOR =
27  new SqlSpecialOperator("CREATE_DATAFRAME", SqlKind.OTHER_DDL);
28 
29  @Expose
30  private String command;
31  @Expose
32  private SqlIdentifier name;
33  @Expose
34  private SqlNodeList elementList;
35  @Expose
36  private SqlNode filePath;
37  @Expose
39 
40  public SqlCreateDataframe(final SqlParserPos pos,
41  SqlIdentifier name,
42  SqlNodeList elementList,
43  SqlNode filePath,
45  super(OPERATOR, pos, false, false);
46  this.command = OPERATOR.getName();
47  this.name = name;
48  this.elementList = elementList;
49  this.filePath = filePath;
50  this.options = options;
51  }
52 
53  @Override
54  public List<SqlNode> getOperandList() {
55  return null;
56  }
57 
58  @Override
59  public String toString() {
60  JsonBuilder jsonBuilder = new EscapedStringJsonBuilder();
61  Map<String, Object> map = jsonBuilder.map();
62 
63  map.put("command", this.command);
64  map.put("name", this.name.toString());
65 
66  List<Object> elements_list = jsonBuilder.list();
67  if (elementList != null) {
68  for (SqlNode elementNode : this.elementList) {
69  if (!(elementNode instanceof SqlCall)) {
70  throw new CalciteException("Column definition for dataframe "
71  + this.name.toString()
72  + " is invalid: " + elementNode.toString(),
73  null);
74  }
75  elements_list.add(elementNode);
76  }
77  }
78  jsonBuilder.put(map, "elementList", elements_list);
79 
80  jsonBuilder.put(map, "filePath", this.filePath.toString());
81 
82  if (this.options != null) {
83  map.put("options", this.options);
84  }
85 
86  Map<String, Object> payload = jsonBuilder.map();
87  payload.put("payload", map);
88 
89  // To Debug:
90  // System.out.println(jsonBuilder.toJsonString(payload));
91 
92  return jsonBuilder.toJsonString(payload);
93  }
94 }
SqlCreateDataframe(final SqlParserPos pos, SqlIdentifier name, SqlNodeList elementList, SqlNode filePath, HeavyDBOptionsMap options)