nssalian commented on a change in pull request #3275:
URL: https://github.com/apache/iceberg/pull/3275#discussion_r735045406



##########
File path: core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java
##########
@@ -252,8 +267,34 @@ public void setConf(Configuration conf) {
 
   @Override
   public void createNamespace(Namespace namespace, Map<String, String> 
metadata) {
-    throw new UnsupportedOperationException("Cannot create namespace " + 
namespace +
-        ": createNamespace is not supported");
+    if (namespaceExists(namespace)) {
+      throw new AlreadyExistsException("Namespace already exists: %s", 
namespace);
+    }
+
+    String namespaceName = JdbcUtil.namespaceToString(namespace);
+    try {
+      int insertRecord = connections.run(conn -> {
+        try (PreparedStatement sql = 
conn.prepareStatement(JdbcUtil.DO_COMMIT_CREATE_NAMESPACE_SQL)) {
+          sql.setString(1, catalogName);
+          sql.setString(2, namespaceName);
+          sql.setString(3, "createdAt");
+          sql.setString(4, Instant.now().toString());

Review comment:
       Makes sense. Thanks for clarifying the metadata part.

##########
File path: core/src/test/java/org/apache/iceberg/jdbc/TestJdbcCatalog.java
##########
@@ -555,6 +555,13 @@ public void testDropNamespace() {
         "is not empty. 1 tables exist.", () -> 
catalog.dropNamespace(tbl4.namespace()));
   }
 
+  @Test
+  public void testCreateNamespace() {
+    Namespace testNamespace = Namespace.of("testDb", "ns1", "ns2");
+    catalog.createNamespace(testNamespace, null);

Review comment:
       Fixed

##########
File path: core/src/main/java/org/apache/iceberg/jdbc/JdbcUtil.java
##########
@@ -69,6 +70,33 @@
       " (" + CATALOG_NAME + ", " + TABLE_NAMESPACE + ", " + TABLE_NAME +
       ", " + METADATA_LOCATION + ", " + PREVIOUS_METADATA_LOCATION + ") " +
       " VALUES (?,?,?,?,null)";
+
+  // Catalog Namespace Properties
+  protected static final String NAMESPACE_PROPERTIES_TABLE_NAME = 
"iceberg_namespace_properties";
+  protected static final String NAMESPACE_NAME = "namespace_name";

Review comment:
       Fixed

##########
File path: core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java
##########
@@ -359,22 +400,30 @@ public void close() {
   public boolean namespaceExists(Namespace namespace) {
     try {
       return connections.run(conn -> {
-        boolean exists = false;
-
+        boolean tableExists = false;
         try (PreparedStatement sql = 
conn.prepareStatement(JdbcUtil.GET_NAMESPACE_SQL)) {
           sql.setString(1, catalogName);
           sql.setString(2, JdbcUtil.namespaceToString(namespace) + "%");
           ResultSet rs = sql.executeQuery();
           if (rs.next()) {
-            exists = true;
+            tableExists = true;
           }
 
           rs.close();
         }
+        boolean namespacePropertyExists = false;

Review comment:
       Fixed




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

To unsubscribe, e-mail: [email protected]

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