OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlCreateRole.java
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to you under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package com.mapd.parser.extension.ddl;
18 
19 import org.apache.calcite.sql.SqlCreate;
20 import org.apache.calcite.sql.SqlIdentifier;
21 import org.apache.calcite.sql.SqlKind;
22 import org.apache.calcite.sql.SqlNode;
23 import org.apache.calcite.sql.SqlNodeList;
25 import org.apache.calcite.sql.SqlSpecialOperator;
26 import org.apache.calcite.sql.SqlWriter;
27 import org.apache.calcite.sql.SqlWriterConfig;
28 import org.apache.calcite.sql.dialect.CalciteSqlDialect;
29 import org.apache.calcite.sql.parser.Span;
30 import org.apache.calcite.sql.parser.SqlParserPos;
31 import org.apache.calcite.sql.pretty.SqlPrettyWriter;
33 import org.apache.calcite.util.ImmutableNullableList;
34 
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Objects;
38 
42 public class SqlCreateRole extends SqlCreate {
43  public final SqlIdentifier role;
44 
45  private static final SqlOperator OPERATOR =
46  new SqlSpecialOperator("CREATE_ROLE", SqlKind.OTHER_DDL);
47 
49  SqlCreateRole(SqlParserPos pos, SqlIdentifier role) {
50  super(OPERATOR, pos, false, false);
51  this.role = Objects.requireNonNull(role);
52  }
53 
54  public List<SqlNode> getOperandList() {
55  return ImmutableNullableList.of(role);
56  }
57 
58  @Override
59  public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
60  writer.keyword("CREATE");
61  writer.keyword("ROLE");
62  role.unparse(writer, leftPrec, rightPrec);
63  }
64 
65  @Override
66  public String toString() {
68  Map<String, Object> map = jsonBuilder.map();
69  jsonBuilder.put(map, "role", this.role.toString());
70  map.put("command", "CREATE_ROLE");
71  Map<String, Object> payload = jsonBuilder.map();
72  payload.put("payload", map);
73  return jsonBuilder.toJsonString(payload);
74  }
75 }
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
SqlCreateRole(SqlParserPos pos, SqlIdentifier role)