You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2021/10/08 21:39:10 UTC

[iceberg] branch master updated: API: Move generic catalog methods to API (#3244)

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

blue 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 a89a902  API: Move generic catalog methods to API (#3244)
a89a902 is described below

commit a89a902dde6c6ed334f26762051b9403ade5ed65
Author: Ryan Blue <bl...@apache.org>
AuthorDate: Fri Oct 8 14:38:57 2021 -0700

    API: Move generic catalog methods to API (#3244)
---
 .../java/org/apache/iceberg/catalog/Catalog.java   | 38 +++++++++++++---
 .../org/apache/iceberg/BaseMetastoreCatalog.java   | 51 ----------------------
 .../java/org/apache/iceberg/CachingCatalog.java    | 34 ---------------
 3 files changed, 32 insertions(+), 91 deletions(-)

diff --git a/api/src/main/java/org/apache/iceberg/catalog/Catalog.java b/api/src/main/java/org/apache/iceberg/catalog/Catalog.java
index 6702762..6cb523b 100644
--- a/api/src/main/java/org/apache/iceberg/catalog/Catalog.java
+++ b/api/src/main/java/org/apache/iceberg/catalog/Catalog.java
@@ -64,12 +64,19 @@ public interface Catalog {
    * @return a Table instance
    * @throws AlreadyExistsException if the table already exists
    */
-  Table createTable(
+  default Table createTable(
       TableIdentifier identifier,
       Schema schema,
       PartitionSpec spec,
       String location,
-      Map<String, String> properties);
+      Map<String, String> properties) {
+
+    return buildTable(identifier, schema)
+        .withPartitionSpec(spec)
+        .withLocation(location)
+        .withProperties(properties)
+        .create();
+  }
 
   /**
    * Create a table.
@@ -130,12 +137,19 @@ public interface Catalog {
    * @return a {@link Transaction} to create the table
    * @throws AlreadyExistsException if the table already exists
    */
-  Transaction newCreateTableTransaction(
+  default Transaction newCreateTableTransaction(
       TableIdentifier identifier,
       Schema schema,
       PartitionSpec spec,
       String location,
-      Map<String, String> properties);
+      Map<String, String> properties) {
+
+    return buildTable(identifier, schema)
+        .withPartitionSpec(spec)
+        .withLocation(location)
+        .withProperties(properties)
+        .createTransaction();
+  }
 
   /**
    * Start a transaction to create a table.
@@ -197,13 +211,25 @@ public interface Catalog {
    * @return a {@link Transaction} to replace the table
    * @throws NoSuchTableException if the table doesn't exist and orCreate is false
    */
-  Transaction newReplaceTableTransaction(
+  default Transaction newReplaceTableTransaction(
       TableIdentifier identifier,
       Schema schema,
       PartitionSpec spec,
       String location,
       Map<String, String> properties,
-      boolean orCreate);
+      boolean orCreate) {
+
+    TableBuilder tableBuilder = buildTable(identifier, schema)
+        .withPartitionSpec(spec)
+        .withLocation(location)
+        .withProperties(properties);
+
+    if (orCreate) {
+      return tableBuilder.createOrReplaceTransaction();
+    } else {
+      return tableBuilder.replaceTransaction();
+    }
+  }
 
   /**
    * Start a transaction to replace a table.
diff --git a/core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java b/core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java
index 0730667..9cea03d 100644
--- a/core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java
@@ -35,57 +35,6 @@ public abstract class BaseMetastoreCatalog implements Catalog {
   private static final Logger LOG = LoggerFactory.getLogger(BaseMetastoreCatalog.class);
 
   @Override
-  public Table createTable(
-      TableIdentifier identifier,
-      Schema schema,
-      PartitionSpec spec,
-      String location,
-      Map<String, String> properties) {
-
-    return buildTable(identifier, schema)
-        .withPartitionSpec(spec)
-        .withLocation(location)
-        .withProperties(properties)
-        .create();
-  }
-
-  @Override
-  public Transaction newCreateTableTransaction(
-      TableIdentifier identifier,
-      Schema schema,
-      PartitionSpec spec,
-      String location,
-      Map<String, String> properties) {
-
-    return buildTable(identifier, schema)
-        .withPartitionSpec(spec)
-        .withLocation(location)
-        .withProperties(properties)
-        .createTransaction();
-  }
-
-  @Override
-  public Transaction newReplaceTableTransaction(
-      TableIdentifier identifier,
-      Schema schema,
-      PartitionSpec spec,
-      String location,
-      Map<String, String> properties,
-      boolean orCreate) {
-
-    TableBuilder tableBuilder = buildTable(identifier, schema)
-        .withPartitionSpec(spec)
-        .withLocation(location)
-        .withProperties(properties);
-
-    if (orCreate) {
-      return tableBuilder.createOrReplaceTransaction();
-    } else {
-      return tableBuilder.replaceTransaction();
-    }
-  }
-
-  @Override
   public Table loadTable(TableIdentifier identifier) {
     Table result;
     if (isValidIdentifier(identifier)) {
diff --git a/core/src/main/java/org/apache/iceberg/CachingCatalog.java b/core/src/main/java/org/apache/iceberg/CachingCatalog.java
index 95c01a5..dfc5350 100644
--- a/core/src/main/java/org/apache/iceberg/CachingCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/CachingCatalog.java
@@ -97,40 +97,6 @@ public class CachingCatalog implements Catalog {
   }
 
   @Override
-  public Table createTable(TableIdentifier ident, Schema schema, PartitionSpec spec, String location,
-                           Map<String, String> properties) {
-    return buildTable(ident, schema)
-        .withPartitionSpec(spec)
-        .withLocation(location)
-        .withProperties(properties)
-        .create();
-  }
-
-  @Override
-  public Transaction newCreateTableTransaction(TableIdentifier ident, Schema schema, PartitionSpec spec,
-                                               String location, Map<String, String> properties) {
-    return buildTable(ident, schema)
-        .withPartitionSpec(spec)
-        .withLocation(location)
-        .withProperties(properties)
-        .createTransaction();
-  }
-
-  @Override
-  public Transaction newReplaceTableTransaction(TableIdentifier ident, Schema schema, PartitionSpec spec,
-                                                String location, Map<String, String> properties, boolean orCreate) {
-    TableBuilder builder = buildTable(ident, schema)
-        .withPartitionSpec(spec)
-        .withLocation(location)
-        .withProperties(properties);
-    if (orCreate) {
-      return builder.createOrReplaceTransaction();
-    } else {
-      return builder.replaceTransaction();
-    }
-  }
-
-  @Override
   public boolean dropTable(TableIdentifier ident, boolean purge) {
     boolean dropped = catalog.dropTable(ident, purge);
     invalidate(canonicalizeIdentifier(ident));