twalthr commented on a change in pull request #8764:  
[FLINK-12798][table-planner][table-api-java] Port TableEnvironment to 
table-api-java module
URL: https://github.com/apache/flink/pull/8764#discussion_r296143105
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java
 ##########
 @@ -0,0 +1,455 @@
+/*
+ * 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.api.internal;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.streaming.api.transformations.StreamTransformation;
+import org.apache.flink.table.api.CatalogNotExistException;
+import org.apache.flink.table.api.QueryConfig;
+import org.apache.flink.table.api.StreamQueryConfig;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.catalog.ConnectorCatalogTable;
+import org.apache.flink.table.catalog.ExternalCatalog;
+import org.apache.flink.table.catalog.FunctionCatalog;
+import org.apache.flink.table.catalog.FunctionLookup;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.QueryOperationCatalogView;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.descriptors.ConnectorDescriptor;
+import org.apache.flink.table.descriptors.StreamTableDescriptor;
+import org.apache.flink.table.descriptors.TableDescriptor;
+import org.apache.flink.table.executor.Executor;
+import org.apache.flink.table.expressions.TableReferenceExpression;
+import org.apache.flink.table.expressions.lookups.TableReferenceLookup;
+import org.apache.flink.table.functions.ScalarFunction;
+import org.apache.flink.table.operations.CatalogQueryOperation;
+import org.apache.flink.table.operations.CatalogSinkModifyOperation;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.table.operations.Operation;
+import org.apache.flink.table.operations.OperationTreeBuilder;
+import org.apache.flink.table.operations.QueryOperation;
+import org.apache.flink.table.operations.TableSourceQueryOperation;
+import org.apache.flink.table.planner.Planner;
+import org.apache.flink.table.planner.QueryConfigProvider;
+import org.apache.flink.table.sinks.TableSink;
+import org.apache.flink.table.sources.TableSource;
+import org.apache.flink.table.sources.TableSourceValidation;
+import org.apache.flink.util.StringUtils;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Implementation of {@link TableEnvironment} that works exclusively with 
Table API interfaces.
+ * Only {@link TableSource} is supported as an input and {@link TableSink} as 
an output. It also does
+ * not bind to any particular {@code StreamExecutionEnvironment}.
+ */
+@Internal
+public class TableEnvironmentImpl implements TableEnvironment {
+
+       private final CatalogManager catalogManager;
+
+       private final String defaultCatalogName;
+       private final String defaultDatabaseName;
+       private final TableConfig tableConfig;
+       private final OperationTreeBuilder operationTreeBuilder;
+
+       protected final Executor execEnv;
+       protected final FunctionCatalog functionCatalog;
+       protected final QueryConfigProvider queryConfigProvider = new 
QueryConfigProvider();
+       protected final Planner planner;
+
+       protected TableEnvironmentImpl(
+                       CatalogManager catalogManager,
+                       TableConfig tableConfig,
+                       Executor executor,
+                       FunctionCatalog functionCatalog,
+                       Planner planner) {
+               this.catalogManager = catalogManager;
+               this.execEnv = executor;
+
+               this.tableConfig = tableConfig;
+               this.tableConfig.setPlannerConfig(queryConfigProvider);
+               this.defaultCatalogName = tableConfig.getBuiltInCatalogName();
+               this.defaultDatabaseName = tableConfig.getBuiltInDatabaseName();
+
+               this.functionCatalog = functionCatalog;
+               this.planner = planner;
+               this.operationTreeBuilder = lookupTreeBuilder(
+                       path -> {
+                               Optional<CatalogQueryOperation> 
catalogTableOperation = scanInternal(path);
+                               return catalogTableOperation.map(tableOperation 
-> new TableReferenceExpression(path, tableOperation));
+                       },
+                       functionCatalog
+               );
+       }
+
+       private static OperationTreeBuilder lookupTreeBuilder(
+               TableReferenceLookup tableReferenceLookup,
+               FunctionLookup functionDefinitionCatalog) {
+               try {
+                       Class<?> clazz = 
Class.forName("org.apache.flink.table.operations.OperationTreeBuilderFactory");
+                       Method createMethod = clazz.getMethod(
+                               "create",
+                               TableReferenceLookup.class,
+                               FunctionLookup.class);
+
+                       return (OperationTreeBuilder) createMethod.invoke(null, 
tableReferenceLookup, functionDefinitionCatalog);
+               } catch (Exception e) {
+                       throw new TableException(
+                               "Could not instantiate the operation builder.  
Make sure the planner module is on the classpath");
 
 Review comment:
   nit: remove 1 space

----------------------------------------------------------------
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

Reply via email to