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

Public Member Functions

List< SqlNode > getOperandList ()
 
void unparse (SqlWriter writer, int leftPrec, int rightPrec)
 
String toString ()
 

Public Attributes

final boolean temporary
 
final SqlIdentifier name
 
final SqlNodeList columnList
 
SqlNode query = null
 

Protected Member Functions

 SqlCreateTable (SqlParserPos pos, boolean temporary, boolean ifNotExists, SqlIdentifier name, SqlNodeList columnList, HeavyDBOptionsMap withOptions, SqlNode query)
 

Private Attributes

final HeavyDBOptionsMap options
 

Static Private Attributes

static final SqlOperator OPERATOR
 

Detailed Description

Parse tree for

CREATE TABLE

statement.

Definition at line 46 of file SqlCreateTable.java.

Constructor & Destructor Documentation

com.mapd.parser.extension.ddl.SqlCreateTable.SqlCreateTable ( SqlParserPos  pos,
boolean  temporary,
boolean  ifNotExists,
SqlIdentifier  name,
SqlNodeList  columnList,
HeavyDBOptionsMap  withOptions,
SqlNode  query 
)
inlineprotected

Creates a SqlCreateTable.

Definition at line 57 of file SqlCreateTable.java.

References com.mapd.parser.extension.ddl.SqlCreateTable.columnList, com.mapd.parser.extension.ddl.SqlCreateTable.name, com.mapd.parser.extension.ddl.SqlCreateTable.OPERATOR, com.mapd.parser.extension.ddl.SqlCreateTable.query, and com.mapd.parser.extension.ddl.SqlCreateTable.temporary.

63  {
64  super(OPERATOR, pos, false, ifNotExists);
65  this.temporary = temporary;
66  this.name = Objects.requireNonNull(name);
67  this.options = withOptions;
68  this.columnList = columnList; // may be null
69  this.query = query; // for "CREATE TABLE ... AS query"; may be null
70  }

Member Function Documentation

List<SqlNode> com.mapd.parser.extension.ddl.SqlCreateTable.getOperandList ( )
inline
String com.mapd.parser.extension.ddl.SqlCreateTable.toString ( )
inline

Definition at line 103 of file SqlCreateTable.java.

References com.mapd.parser.extension.ddl.SqlCreateTable.columnList, com.mapd.parser.extension.ddl.SqlCreateTable.name, and com.mapd.parser.extension.ddl.SqlCreateTable.query.

103  {
104  JsonBuilder jsonBuilder = new EscapedStringJsonBuilder();
105  Map<String, Object> map = jsonBuilder.map();
106 
107  jsonBuilder.put(map, "command", "CREATE_TABLE");
108  jsonBuilder.put(map, "name", this.name.toString());
109 
110  if (query != null) {
111  // By default ... toString() seems to single-quote too much stuff
112  // for the SELECT stmt to be executed later
113  // ->
114  // use PrettyWriter to output a cleaner SQL statement
115  //
116  SqlWriterConfig c = SqlPrettyWriter.config()
117  .withDialect(CalciteSqlDialect.DEFAULT)
118  .withQuoteAllIdentifiers(false)
119  .withSelectListItemsOnSeparateLines(false)
120  .withWhereListItemsOnSeparateLines(false)
121  .withValuesListNewline(false);
122  SqlPrettyWriter writer = new SqlPrettyWriter(c);
123  this.query.unparse(writer, 0, 0);
124  jsonBuilder.put(map, "query", writer.toString());
125  }
126 
127  List<Object> elements_list = jsonBuilder.list();
128  if (columnList != null) {
129  for (SqlNode elementNode : this.columnList) {
130  if (!(elementNode instanceof SqlCall)) {
131  throw new CalciteException("Column definition for table " + this.name.toString()
132  + " is invalid: " + elementNode.toString(),
133  null);
134  }
135  elements_list.add(elementNode);
136  }
137  }
138  jsonBuilder.put(map, "elements", elements_list);
139  jsonBuilder.put(map, "temporary", this.temporary);
140  jsonBuilder.put(map, "ifNotExists", this.ifNotExists);
141 
142  map.put("options", this.options);
143 
144  Map<String, Object> payload = jsonBuilder.map();
145  payload.put("payload", map);
146 
147  // To Debug:
148  // System.out.println(jsonBuilder.toJsonString(payload))
149 
150  return jsonBuilder.toJsonString(payload);
151  }
void com.mapd.parser.extension.ddl.SqlCreateTable.unparse ( SqlWriter  writer,
int  leftPrec,
int  rightPrec 
)
inline

Definition at line 77 of file SqlCreateTable.java.

References com.mapd.parser.extension.ddl.SqlCreateTable.columnList, com.mapd.parser.extension.ddl.SqlCreateTable.query, and com.mapd.parser.extension.ddl.SqlCreateTable.temporary.

77  {
78  writer.keyword("CREATE");
79  if (temporary) {
80  writer.keyword("TEMPORARY");
81  }
82  writer.keyword("TABLE");
83  if (ifNotExists) {
84  writer.keyword("IF NOT EXISTS");
85  }
86  name.unparse(writer, leftPrec, rightPrec);
87  if (columnList != null) {
88  SqlWriter.Frame frame = writer.startList("(", ")");
89  for (SqlNode c : columnList) {
90  writer.sep(",");
91  c.unparse(writer, 0, 0);
92  }
93  writer.endList(frame);
94  }
95  if (query != null) {
96  writer.keyword("AS");
97  writer.newlineAndIndent();
98  query.unparse(writer, 0, 0);
99  }
100  }

Member Data Documentation

final SqlOperator com.mapd.parser.extension.ddl.SqlCreateTable.OPERATOR
staticprivate
Initial value:
=
new SqlSpecialOperator("CREATE TABLE", SqlKind.CREATE_TABLE)

Definition at line 53 of file SqlCreateTable.java.

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

final HeavyDBOptionsMap com.mapd.parser.extension.ddl.SqlCreateTable.options
private

Definition at line 51 of file SqlCreateTable.java.

final boolean com.mapd.parser.extension.ddl.SqlCreateTable.temporary

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