gyfora commented on a change in pull request #78: Kudu Connector rework
URL: https://github.com/apache/bahir-flink/pull/78#discussion_r410405052
 
 

 ##########
 File path: 
flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduCatalog.java
 ##########
 @@ -0,0 +1,348 @@
+/*
+ * 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.connectors.kudu.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
+import org.apache.flink.connectors.kudu.table.utils.KuduTableUtils;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.TableFactory;
+import org.apache.flink.util.StringUtils;
+
+import org.apache.flink.shaded.guava18.com.google.common.collect.Lists;
+
+import org.apache.kudu.ColumnSchema;
+import org.apache.kudu.client.AlterTableOptions;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduException;
+import org.apache.kudu.client.KuduTable;
+import org.apache.kudu.shaded.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static 
org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_HASH_COLS;
+import static 
org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_MASTERS;
+import static 
org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_PRIMARY_KEY_COLS;
+import static 
org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_REPLICAS;
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Catalog for reading and creating Kudu tables.
+ */
+@PublicEvolving
+public class KuduCatalog extends AbstractReadOnlyCatalog {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(KuduCatalog.class);
+    private final KuduTableFactory tableFactory = new KuduTableFactory();
+    private final String kuduMasters;
+    private KuduClient kuduClient;
+
+    /**
+     * Create a new {@link KuduCatalog} with the specified catalog name and 
kudu master addresses.
+     *
+     * @param catalogName Name of the catalog (used by the table environment)
+     * @param kuduMasters Connection address to Kudu
+     */
+    public KuduCatalog(String catalogName, String kuduMasters) {
+        super(catalogName, EnvironmentSettings.DEFAULT_BUILTIN_DATABASE);
+        this.kuduMasters = kuduMasters;
+        this.kuduClient = createClient();
+    }
+
+    /**
+     * Create a new {@link KuduCatalog} with the specified kudu master 
addresses.
+     *
+     * @param kuduMasters Connection address to Kudu
+     */
+    public KuduCatalog(String kuduMasters) {
+        this("kudu", kuduMasters);
+    }
+
+    public Optional<TableFactory> getTableFactory() {
+        return Optional.of(getKuduTableFactory());
+    }
+
+    public KuduTableFactory getKuduTableFactory() {
+        return tableFactory;
+    }
+
+    private KuduClient createClient() {
+        return new KuduClient.KuduClientBuilder(kuduMasters).build();
+    }
+
+    @Override
+    public void open() {}
+
+    @Override
+    public void close() {
+        try {
+            if (kuduClient != null) {
+                kuduClient.close();
+            }
+        } catch (KuduException e) {
+            LOG.error("Error while closing kudu client", e);
+        }
+    }
+
+    public ObjectPath getObjectPath(String tableName) {
+        return new ObjectPath(getDefaultDatabase(), tableName);
+    }
+
+    @Override
+    public List<String> listTables(String databaseName) throws 
DatabaseNotExistException, CatalogException {
 
 Review comment:
   For now we decided to not introduce any database concept in this catalog for 
the reasons you highlighted and treat everything as a single database.
   
   In the future we could improve this and adapt the convention you mentioned. 
In that case the default could be the global namespace as it is now.

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