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 2019/06/28 15:49:10 UTC

[incubator-iceberg] branch master updated: Move BaseTransaction factory methods to Transaction (#234)

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/incubator-iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 846d1e4  Move BaseTransaction factory methods to Transaction (#234)
846d1e4 is described below

commit 846d1e4db2e37fa352486e522dfa64f0fa3e04ec
Author: David Phillips <da...@acz.org>
AuthorDate: Fri Jun 28 08:49:06 2019 -0700

    Move BaseTransaction factory methods to Transaction (#234)
---
 .../org/apache/iceberg/BaseMetastoreTables.java    |  6 ++--
 .../main/java/org/apache/iceberg/BaseTable.java    |  2 +-
 .../java/org/apache/iceberg/BaseTransaction.java   | 16 +--------
 .../main/java/org/apache/iceberg/Transactions.java | 40 ++++++++++++++++++++++
 .../test/java/org/apache/iceberg/TestTables.java   |  6 ++--
 5 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/BaseMetastoreTables.java b/core/src/main/java/org/apache/iceberg/BaseMetastoreTables.java
index 8004167..9026111 100644
--- a/core/src/main/java/org/apache/iceberg/BaseMetastoreTables.java
+++ b/core/src/main/java/org/apache/iceberg/BaseMetastoreTables.java
@@ -81,7 +81,7 @@ public abstract class BaseMetastoreTables implements Tables {
     String location = defaultWarehouseLocation(conf, database, table);
     TableMetadata metadata = TableMetadata.newTableMetadata(ops, schema, spec, location, properties);
 
-    return BaseTransaction.createTableTransaction(ops, metadata);
+    return Transactions.createTableTransaction(ops, metadata);
   }
 
   public Transaction beginReplace(Schema schema, PartitionSpec spec,
@@ -97,11 +97,11 @@ public abstract class BaseMetastoreTables implements Tables {
     TableMetadata metadata;
     if (current != null) {
       metadata = current.buildReplacement(schema, spec, properties);
-      return BaseTransaction.replaceTableTransaction(ops, metadata);
+      return Transactions.replaceTableTransaction(ops, metadata);
     } else {
       String location = defaultWarehouseLocation(conf, database, table);
       metadata = TableMetadata.newTableMetadata(ops, schema, spec, location, properties);
-      return BaseTransaction.createTableTransaction(ops, metadata);
+      return Transactions.createTableTransaction(ops, metadata);
     }
   }
 
diff --git a/core/src/main/java/org/apache/iceberg/BaseTable.java b/core/src/main/java/org/apache/iceberg/BaseTable.java
index 395ab3c..32182ab 100644
--- a/core/src/main/java/org/apache/iceberg/BaseTable.java
+++ b/core/src/main/java/org/apache/iceberg/BaseTable.java
@@ -150,7 +150,7 @@ public class BaseTable implements Table, HasTableOperations {
 
   @Override
   public Transaction newTransaction() {
-    return BaseTransaction.newTransaction(ops);
+    return Transactions.newTransaction(ops);
   }
 
   @Override
diff --git a/core/src/main/java/org/apache/iceberg/BaseTransaction.java b/core/src/main/java/org/apache/iceberg/BaseTransaction.java
index d21b728..ee70433 100644
--- a/core/src/main/java/org/apache/iceberg/BaseTransaction.java
+++ b/core/src/main/java/org/apache/iceberg/BaseTransaction.java
@@ -49,20 +49,6 @@ class BaseTransaction implements Transaction {
     SIMPLE
   }
 
-  static Transaction replaceTableTransaction(TableOperations ops, TableMetadata start) {
-    return new BaseTransaction(ops, start);
-  }
-
-  static Transaction createTableTransaction(TableOperations ops, TableMetadata start) {
-    Preconditions.checkArgument(ops.current() == null,
-        "Cannot start create table transaction: table already exists");
-    return new BaseTransaction(ops, start);
-  }
-
-  static Transaction newTransaction(TableOperations ops) {
-    return new BaseTransaction(ops, ops.refresh());
-  }
-
   private final TableOperations ops;
   private final TransactionTable transactionTable;
   private final TableOperations transactionOps;
@@ -75,7 +61,7 @@ class BaseTransaction implements Transaction {
   private TableMetadata lastBase;
   private TableMetadata current;
 
-  private BaseTransaction(TableOperations ops, TableMetadata start) {
+  BaseTransaction(TableOperations ops, TableMetadata start) {
     this.ops = ops;
     this.transactionTable = new TransactionTable();
     this.transactionOps = new TransactionTableOperations();
diff --git a/core/src/main/java/org/apache/iceberg/Transactions.java b/core/src/main/java/org/apache/iceberg/Transactions.java
new file mode 100644
index 0000000..c7708c9
--- /dev/null
+++ b/core/src/main/java/org/apache/iceberg/Transactions.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+import com.google.common.base.Preconditions;
+
+public final class Transactions {
+  private Transactions() {}
+
+  public static Transaction replaceTableTransaction(TableOperations ops, TableMetadata start) {
+    return new BaseTransaction(ops, start);
+  }
+
+  public static Transaction createTableTransaction(TableOperations ops, TableMetadata start) {
+    Preconditions.checkArgument(ops.current() == null,
+            "Cannot start create table transaction: table already exists");
+    return new BaseTransaction(ops, start);
+  }
+
+  public static Transaction newTransaction(TableOperations ops) {
+    return new BaseTransaction(ops, ops.refresh());
+  }
+}
diff --git a/core/src/test/java/org/apache/iceberg/TestTables.java b/core/src/test/java/org/apache/iceberg/TestTables.java
index db8e574..4275205 100644
--- a/core/src/test/java/org/apache/iceberg/TestTables.java
+++ b/core/src/test/java/org/apache/iceberg/TestTables.java
@@ -55,7 +55,7 @@ public class TestTables {
 
     TableMetadata metadata = TableMetadata.newTableMetadata(ops, schema, spec, temp.toString());
 
-    return BaseTransaction.createTableTransaction(ops, metadata);
+    return Transactions.createTableTransaction(ops, metadata);
   }
 
   public static Transaction beginReplace(File temp, String name, Schema schema, PartitionSpec spec) {
@@ -70,10 +70,10 @@ public class TestTables {
     TableMetadata metadata;
     if (current != null) {
       metadata = current.buildReplacement(schema, spec, properties);
-      return BaseTransaction.replaceTableTransaction(ops, metadata);
+      return Transactions.replaceTableTransaction(ops, metadata);
     } else {
       metadata = newTableMetadata(ops, schema, spec, temp.toString(), properties);
-      return BaseTransaction.createTableTransaction(ops, metadata);
+      return Transactions.createTableTransaction(ops, metadata);
     }
   }