OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalciteSqlValidator.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 org.apache.calcite.prepare;
18 
20 
21 import org.apache.calcite.adapter.java.JavaTypeFactory;
22 import org.apache.calcite.rel.type.RelDataType;
23 import org.apache.calcite.sql.SqlIdentifier;
24 import org.apache.calcite.sql.SqlInsert;
25 import org.apache.calcite.sql.SqlNode;
26 import org.apache.calcite.sql.SqlOperatorTable;
27 import org.apache.calcite.sql.validate.SelectScope;
28 import org.apache.calcite.sql.validate.SqlConformance;
29 import org.apache.calcite.sql.validate.SqlValidator.Config;
31 import org.apache.calcite.sql.validate.SqlValidatorScope;
32 import org.apache.calcite.sql.validate.SqlValidatorTable;
33 
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37 
45  CalciteSqlValidator(SqlOperatorTable opTab,
46  CalciteCatalogReader catalogReader,
47  JavaTypeFactory typeFactory,
48  Config config) {
49  super(opTab, catalogReader, typeFactory, config);
50  }
51 
52  @Override
53  protected RelDataType getLogicalSourceRowType(
54  RelDataType sourceRowType, SqlInsert insert) {
55  final RelDataType superType = super.getLogicalSourceRowType(sourceRowType, insert);
56  return ((JavaTypeFactory) typeFactory).toSql(superType);
57  }
58 
59  @Override
60  protected RelDataType getLogicalTargetRowType(
61  RelDataType targetRowType, SqlInsert insert) {
62  final RelDataType superType = super.getLogicalTargetRowType(targetRowType, insert);
63  return ((JavaTypeFactory) typeFactory).toSql(superType);
64  }
65 
66  @Override
67  protected void addToSelectList(List<SqlNode> list,
68  Set<String> aliases,
69  List<Map.Entry<String, RelDataType>> fieldList,
70  SqlNode exp,
71  SelectScope scope,
72  boolean includeSystemVars) {
73  if (includeSystemVars || !isSystemColumn(exp, scope)) {
74  super.addToSelectList(list, aliases, fieldList, exp, scope, includeSystemVars);
75  }
76  }
77 
78  private boolean isSystemColumn(final SqlNode exp, final SelectScope scope) {
79  if (exp instanceof SqlIdentifier) {
80  SqlIdentifier columnId = (SqlIdentifier) exp;
81  // Expects columnId.names[0] to be table name and columnId.names[1] to be column
82  // name
83  if (columnId.names != null && columnId.names.size() == 2) {
84  SqlValidatorTable sqlValidatorTable =
85  scope.fullyQualify(columnId).namespace.getTable();
86  if (sqlValidatorTable != null) {
87  HeavyDBTable table =
88  (HeavyDBTable) sqlValidatorTable.unwrap(HeavyDBTable.class);
89  return table.isSystemColumn(columnId.names.get(1));
90  }
91  }
92  }
93  return false;
94  }
95 
96  @Override
97  protected void checkTypeAssignment(SqlValidatorScope sourceScope,
98  SqlValidatorTable table,
99  RelDataType sourceRowType,
100  RelDataType targetRowType,
101  SqlNode query) {
102  // disabling assignment checking in calcite and instead letting HEAVY.AI server
103  // handle
104  }
105 }
CalciteSqlValidator(SqlOperatorTable opTab, CalciteCatalogReader catalogReader, JavaTypeFactory typeFactory, Config config)
boolean isSystemColumn(final SqlNode exp, final SelectScope scope)
void checkTypeAssignment(SqlValidatorScope sourceScope, SqlValidatorTable table, RelDataType sourceRowType, RelDataType targetRowType, SqlNode query)
void addToSelectList(List< SqlNode > list, Set< String > aliases, List< Map.Entry< String, RelDataType >> fieldList, SqlNode exp, SelectScope scope, boolean includeSystemVars)
RelDataType getLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert)
RelDataType getLogicalTargetRowType(RelDataType targetRowType, SqlInsert insert)