You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/05/14 14:11:10 UTC

[GitHub] [flink] dawidwys commented on a change in pull request #8404: [FLINK-11476][table] Create CatalogManager to manage multiple catalogs

dawidwys commented on a change in pull request #8404: [FLINK-11476][table] Create CatalogManager to manage multiple catalogs
URL: https://github.com/apache/flink/pull/8404#discussion_r283818770
 
 

 ##########
 File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/catalog/CalciteCatalogTable.java
 ##########
 @@ -0,0 +1,87 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.calcite.FlinkTypeFactory;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.schema.Table;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Thin wrapper around Calcite specific {@link Table}, this is a temporary solution
+ * that allows to register those tables in the {@link CatalogManager}.
+ * TODO remove once we decouple TableEnvironment from Calcite.
+ */
+@Internal
+public class CalciteCatalogTable implements CatalogBaseTable {
+	private final Table table;
+	private final FlinkTypeFactory typeFactory;
+
+	public CalciteCatalogTable(Table table, FlinkTypeFactory typeFactory) {
+		this.table = table;
+		this.typeFactory = typeFactory;
+	}
+
+	public Table getTable() {
+		return table;
+	}
+
+	@Override
+	public Map<String, String> getProperties() {
+		throw new UnsupportedOperationException("Calcite table cannot be expressed as a map of properties.");
+	}
+
+	@Override
+	public TableSchema getSchema() {
+		RelDataType relDataType = table.getRowType(typeFactory);
+
+		String[] fieldNames = relDataType.getFieldNames().toArray(new String[0]);
+		TypeInformation[] fieldTypes = relDataType.getFieldList()
+			.stream()
+			.map(field -> FlinkTypeFactory.toTypeInfo(field.getType())).toArray(TypeInformation[]::new);
+
+		return new TableSchema(fieldNames, fieldTypes);
+	}
+
+	@Override
+	public String getComment() {
+		return null;
+	}
+
+	@Override
+	public CatalogBaseTable copy() {
+		return this;
 
 Review comment:
   I agree this would be better. Unfortunately this makes it impossible to register the table in the catalog as it creates a copy on either `createTable` or `getTable`.  

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services