ismailsimsek commented on a change in pull request #1870:
URL: https://github.com/apache/iceberg/pull/1870#discussion_r537080968



##########
File path: core/src/main/java/org/apache/iceberg/hadoop/JdbcNamespaceDao.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.iceberg.hadoop;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.dbutils.QueryRunner;
+import org.apache.commons.dbutils.handlers.BeanHandler;
+import org.apache.commons.dbutils.handlers.BeanListHandler;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JdbcNamespaceDao {
+  public static final String NAMESPACES_TABLE_NAME = "iceberg_namespaces";
+  public static final String NAMESPACES_TABLE_DDL = "CREATE TABLE IF NOT 
EXISTS " +
+          JdbcNamespaceDao.NAMESPACES_TABLE_NAME + " ( " +
+          "catalogName VARCHAR(1255) NOT NULL," +
+          "namespace VARCHAR(1255) NOT NULL," +
+          "namespaceMetadata VARCHAR(32768)," +
+          "PRIMARY KEY (catalogName, namespace) " +
+          ");";
+  private static final Logger LOG = 
LoggerFactory.getLogger(JdbcNamespaceDao.class);
+  private final String catalogName;
+  private QueryRunner queryRunner;
+
+
+  public JdbcNamespaceDao(QueryRunner queryRunner, String catalogName) {
+    this.queryRunner = queryRunner;
+    this.catalogName = catalogName;
+  }
+
+  public JdbcNamespace get(Namespace namespace) throws SQLException {
+    return queryRunner.query("SELECT * FROM " + NAMESPACES_TABLE_NAME + " 
WHERE catalogName = " +
+                    "? AND namespace = ? ;",
+            new BeanHandler<>(JdbcNamespace.class), catalogName, 
namespace.toString());
+  }
+
+  public boolean isExists(Namespace namespace) {
+    try {
+      return this.get(namespace) != null;
+    } catch (SQLException throwables) {
+      return false;
+    }
+  }
+
+  public List<JdbcNamespace> getAll() throws SQLException {

Review comment:
       right seems like this one (`getAll()`) is not needed, but kept it and 
added   `public List<Namespace> getChildren(Namespace namespace)`




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to