Add calcite sql validator
Project: http://git-wip-us.apache.org/repos/asf/incubator-gearpump/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-gearpump/commit/4a22d8ac Tree: http://git-wip-us.apache.org/repos/asf/incubator-gearpump/tree/4a22d8ac Diff: http://git-wip-us.apache.org/repos/asf/incubator-gearpump/diff/4a22d8ac Branch: refs/heads/sql Commit: 4a22d8ac95ca12893bc23187901c32d0e71ec8c2 Parents: 83d8578 Author: Buddhi Ayesha <buddhiayesha...@cse.mrt.ac.lk> Authored: Sat Jun 17 15:02:58 2017 +0530 Committer: manuzhang <owenzhang1...@gmail.com> Committed: Sun Jul 9 07:52:48 2017 +0800 ---------------------------------------------------------------------- .../calcite/validator/CalciteSqlValidator.java | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-gearpump/blob/4a22d8ac/experiments/sql/src/main/java/org/apache/calcite/validator/CalciteSqlValidator.java ---------------------------------------------------------------------- diff --git a/experiments/sql/src/main/java/org/apache/calcite/validator/CalciteSqlValidator.java b/experiments/sql/src/main/java/org/apache/calcite/validator/CalciteSqlValidator.java new file mode 100644 index 0000000..fb132e2 --- /dev/null +++ b/experiments/sql/src/main/java/org/apache/calcite/validator/CalciteSqlValidator.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.calcite.validator; + +import org.apache.calcite.adapter.java.JavaTypeFactory; +import org.apache.calcite.prepare.CalciteCatalogReader; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.sql.SqlInsert; +import org.apache.calcite.sql.SqlOperatorTable; +import org.apache.calcite.sql.validate.SqlConformance; +import org.apache.calcite.sql.validate.SqlValidatorImpl; + +public class CalciteSqlValidator extends SqlValidatorImpl { + public CalciteSqlValidator(SqlOperatorTable opTab, + CalciteCatalogReader catalogReader, JavaTypeFactory typeFactory, + SqlConformance conformance) { + super(opTab, catalogReader, typeFactory, conformance); + } + + @Override + protected RelDataType getLogicalSourceRowType( + RelDataType sourceRowType, SqlInsert insert) { + final RelDataType superType = + super.getLogicalSourceRowType(sourceRowType, insert); + return ((JavaTypeFactory) typeFactory).toSql(superType); + } + + @Override + protected RelDataType getLogicalTargetRowType( + RelDataType targetRowType, SqlInsert insert) { + final RelDataType superType = + super.getLogicalTargetRowType(targetRowType, insert); + return ((JavaTypeFactory) typeFactory).toSql(superType); + } +}