OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlCheckConstraint.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.SqlCall;
20 import org.apache.calcite.sql.SqlIdentifier;
21 import org.apache.calcite.sql.SqlKind;
22 import org.apache.calcite.sql.SqlNode;
24 import org.apache.calcite.sql.SqlSpecialOperator;
25 import org.apache.calcite.sql.SqlWriter;
26 import org.apache.calcite.sql.parser.SqlParserPos;
27 import org.apache.calcite.util.ImmutableNullableList;
28 
29 import java.util.List;
30 
37 public class SqlCheckConstraint extends SqlCall {
38  private static final SqlSpecialOperator OPERATOR =
39  new SqlSpecialOperator("CHECK", SqlKind.CHECK);
40 
41  private final SqlIdentifier name;
42  private final SqlNode expression;
43 
45  SqlCheckConstraint(SqlParserPos pos, SqlIdentifier name, SqlNode expression) {
46  super(pos);
47  this.name = name; // may be null
48  this.expression = expression;
49  }
50 
51  @Override
53  return OPERATOR;
54  }
55 
56  @Override
57  public List<SqlNode> getOperandList() {
58  return ImmutableNullableList.of(name, expression);
59  }
60 
61  @Override
62  public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
63  if (name != null) {
64  writer.keyword("CONSTRAINT");
65  name.unparse(writer, 0, 0);
66  }
67  writer.keyword("CHECK");
68  if (writer.isAlwaysUseParentheses()) {
69  expression.unparse(writer, 0, 0);
70  } else {
71  writer.sep("(");
72  expression.unparse(writer, 0, 0);
73  writer.sep(")");
74  }
75  }
76 }
void unparse(SqlWriter writer, int leftPrec, int rightPrec)
SqlCheckConstraint(SqlParserPos pos, SqlIdentifier name, SqlNode expression)