You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ja...@apache.org on 2023/04/27 14:32:20 UTC

[iceberg] branch master updated: Core: Move table-creation-without-namespace-test to CatalogTests (#7349)

This is an automated email from the ASF dual-hosted git repository.

jackye pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ca688531c Core: Move table-creation-without-namespace-test to CatalogTests (#7349)
8ca688531c is described below

commit 8ca688531c9001a2ee99c47bb38514804941379d
Author: Eduard Tudenhoefner <et...@gmail.com>
AuthorDate: Thu Apr 27 16:32:13 2023 +0200

    Core: Move table-creation-without-namespace-test to CatalogTests (#7349)
---
 .../org/apache/iceberg/inmemory/InMemoryCatalog.java    | 14 +++++++-------
 .../java/org/apache/iceberg/catalog/CatalogTests.java   | 12 ++++++++++++
 .../apache/iceberg/inmemory/TestInMemoryCatalog.java    | 17 -----------------
 3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java b/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java
index 256c3fe6ef..e9f25c8c84 100644
--- a/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java
@@ -127,7 +127,7 @@ public class InMemoryCatalog extends BaseMetastoreCatalog implements SupportsNam
   public List<TableIdentifier> listTables(Namespace namespace) {
     if (!namespaceExists(namespace) && !namespace.isEmpty()) {
       throw new NoSuchNamespaceException(
-          "Cannot list tables for namespace: Namespace %s does not exist", namespace);
+          "Cannot list tables for namespace. Namespace does not exist: %s", namespace);
     }
 
     return tables.keySet().stream()
@@ -144,24 +144,24 @@ public class InMemoryCatalog extends BaseMetastoreCatalog implements SupportsNam
 
     if (!namespaceExists(toTableIdentifier.namespace())) {
       throw new NoSuchNamespaceException(
-          "Cannot rename %s to %s: Namespace %s does not exist",
+          "Cannot rename %s to %s. Namespace does not exist: %s",
           fromTableIdentifier, toTableIdentifier, toTableIdentifier.namespace());
     }
 
     if (!tables.containsKey(fromTableIdentifier)) {
       throw new NoSuchTableException(
-          "Cannot rename %s to %s: Table does not exist", fromTableIdentifier, toTableIdentifier);
+          "Cannot rename %s to %s. Table does not exist", fromTableIdentifier, toTableIdentifier);
     }
 
     if (tables.containsKey(toTableIdentifier)) {
       throw new AlreadyExistsException(
-          "Cannot rename %s to %s: Table already exists", fromTableIdentifier, toTableIdentifier);
+          "Cannot rename %s to %s. Table already exists", fromTableIdentifier, toTableIdentifier);
     }
 
     String fromLocation = tables.remove(fromTableIdentifier);
     Preconditions.checkState(
         null != fromLocation,
-        "Cannot rename from %s to %s: Source table does not exist",
+        "Cannot rename from %s to %s. Source table does not exist",
         fromTableIdentifier,
         toTableIdentifier);
 
@@ -177,7 +177,7 @@ public class InMemoryCatalog extends BaseMetastoreCatalog implements SupportsNam
   public void createNamespace(Namespace namespace, Map<String, String> metadata) {
     if (namespaceExists(namespace)) {
       throw new AlreadyExistsException(
-          "Cannot create namespace %s: Namespace already exists", namespace);
+          "Cannot create namespace %s. Namespace already exists", namespace);
     }
 
     namespaces.put(namespace, ImmutableMap.copyOf(metadata));
@@ -315,7 +315,7 @@ public class InMemoryCatalog extends BaseMetastoreCatalog implements SupportsNam
 
       if (null == base && !namespaceExists(tableIdentifier.namespace())) {
         throw new NoSuchNamespaceException(
-            "Cannot create table %s. Namespace %s does not exist",
+            "Cannot create table %s. Namespace does not exist: %s",
             tableIdentifier, tableIdentifier.namespace());
       }
 
diff --git a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
index dfeea82193..b66ab940a8 100644
--- a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
@@ -65,6 +65,7 @@ import org.apache.iceberg.util.CharSequenceSet;
 import org.assertj.core.api.Assertions;
 import org.junit.Assert;
 import org.junit.Assume;
+import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.Test;
 
 public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
@@ -2509,6 +2510,17 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
     }
   }
 
+  @Test
+  public void tableCreationWithoutNamespace() {
+    Assumptions.assumeTrue(requiresNamespaceCreate());
+
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog().buildTable(TableIdentifier.of("non-existing", "table"), SCHEMA).create())
+        .isInstanceOf(NoSuchNamespaceException.class)
+        .hasMessageEndingWith("Namespace does not exist: non-existing");
+  }
+
   private static void assertEmpty(String context, Catalog catalog, Namespace ns) {
     try {
       Assert.assertEquals(context, 0, catalog.listTables(ns).size());
diff --git a/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryCatalog.java b/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryCatalog.java
index 827ec8a6a3..63cd24b4e2 100644
--- a/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/inmemory/TestInMemoryCatalog.java
@@ -19,13 +19,8 @@
 package org.apache.iceberg.inmemory;
 
 import org.apache.iceberg.catalog.CatalogTests;
-import org.apache.iceberg.catalog.TableIdentifier;
-import org.apache.iceberg.exceptions.NoSuchNamespaceException;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
-import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
 
 public class TestInMemoryCatalog extends CatalogTests<InMemoryCatalog> {
   private InMemoryCatalog catalog;
@@ -45,16 +40,4 @@ public class TestInMemoryCatalog extends CatalogTests<InMemoryCatalog> {
   protected boolean requiresNamespaceCreate() {
     return true;
   }
-
-  @Test
-  public void tableCreationWithoutNamespace() {
-    Assumptions.assumeTrue(requiresNamespaceCreate());
-
-    // this should be moved to CatalogTests at some point, but TestNessieCatalog currently fails
-    // with a different exception than we would expect
-    Assertions.assertThatThrownBy(
-            () -> catalog().buildTable(TableIdentifier.of("ns", "table"), SCHEMA).create())
-        .isInstanceOf(NoSuchNamespaceException.class)
-        .hasMessage("Cannot create table ns.table. Namespace ns does not exist");
-  }
 }