OmniSciDB  6686921089
 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 replace, boolean temporary, boolean ifNotExists, SqlIdentifier name, SqlNodeList columnList, OmniSciOptionsMap withOptions, SqlNode query)
 

Private Attributes

final OmniSciOptionsMap options
 

Static Private Attributes

static final SqlOperator OPERATOR
 

Detailed Description

Parse tree for

statement.

Definition at line 46 of file SqlCreateTable.java.

Constructor & Destructor Documentation

com.mapd.parser.extension.ddl.SqlCreateTable.SqlCreateTable ( SqlParserPos  pos,
boolean  replace,
boolean  temporary,
boolean  ifNotExists,
SqlIdentifier  name,
SqlNodeList  columnList,
OmniSciOptionsMap  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.

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

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 104 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.

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

Definition at line 78 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.

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

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 OmniSciOptionsMap 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: