lirui-apache commented on a change in pull request #8859: [FLINK-12905][table-planner] Enable querying CatalogViews in legacy planner URL: https://github.com/apache/flink/pull/8859#discussion_r324507895
########## File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/FlinkViewTable.java ########## @@ -0,0 +1,65 @@ +/* + * 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.flink.table.planner; + +import org.apache.flink.table.api.SqlDialect; +import org.apache.flink.table.api.TableConfig; +import org.apache.flink.table.api.ValidationException; + +import org.apache.calcite.plan.RelOptTable; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.type.RelProtoDataType; +import org.apache.calcite.schema.impl.ViewTable; + +import java.util.List; + +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** + * Thin extension to {@link ViewTable} that performs {@link SqlDialect} check + * before expanding the view. It throws exception if the view's dialect is different + * from configured in the {@link TableConfig}. + */ +public class FlinkViewTable extends ViewTable { + private final SqlDialect viewDialect; + + public FlinkViewTable( + SqlDialect viewDialect, + RelProtoDataType rowType, + String viewSql, + List<String> schemaPath, + List<String> viewPath) { + super(null, rowType, viewSql, schemaPath, viewPath); + this.viewDialect = checkNotNull(viewDialect); + } + + @Override + public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) { + TableConfig tableConfig = context.getCluster().getPlanner().getContext().unwrap(TableConfig.class); + SqlDialect sqlDialect = tableConfig.getSqlDialect(); + if (!viewDialect.equals(sqlDialect)) { Review comment: Perhaps a more general question is what're the implications of setting sql dialect. According to the JavaDoc of `SqlDialect`, HIVE dialect is required only if users want to use some Hive-specific features e.g. `INSERT OVERWRITE`. Enforcing a dialect check for views might confuse users. For example, users need to worry about dialect even if the query is common enough to be supported by both DEFAULT and HIVE dialects. Besides, it prevents mixed usage of generic and hive views, which doesn't seem very user friendly. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
