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/01/14 19:01:28 UTC

[incubator-iceberg] branch master updated: Allow schema updates in transactions. (#70)

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 04f560f  Allow schema updates in transactions. (#70)
04f560f is described below

commit 04f560fde8bb9d2407dba7bdbf5703a50e7581d4
Author: Ryan Blue <rd...@users.noreply.github.com>
AuthorDate: Mon Jan 14 11:01:24 2019 -0800

    Allow schema updates in transactions. (#70)
    
    This is safe because schema updates can always read older data. If a
    transaction includes a write followed by a schema update, the new schema
    can read the data that was just written. Also, writers are allowed to
    write with older schemas because the current schema can read any file
    written with an older schema. If a transaction includes a schema update
    followed by a write, using either the original schema or the new schema
    will work.
---
 api/src/main/java/com/netflix/iceberg/Transaction.java      |  7 +++++++
 core/src/main/java/com/netflix/iceberg/BaseTransaction.java | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/api/src/main/java/com/netflix/iceberg/Transaction.java b/api/src/main/java/com/netflix/iceberg/Transaction.java
index 7d09723..8ab4b64 100644
--- a/api/src/main/java/com/netflix/iceberg/Transaction.java
+++ b/api/src/main/java/com/netflix/iceberg/Transaction.java
@@ -34,6 +34,13 @@ public interface Transaction {
   Table table();
 
   /**
+   * Create a new {@link UpdateSchema} to alter the columns of this table.
+   *
+   * @return a new {@link UpdateSchema}
+   */
+  UpdateSchema updateSchema();
+
+  /**
    * Create a new {@link UpdateProperties} to update table properties.
    *
    * @return a new {@link UpdateProperties}
diff --git a/core/src/main/java/com/netflix/iceberg/BaseTransaction.java b/core/src/main/java/com/netflix/iceberg/BaseTransaction.java
index b7c3a32..e7d9864 100644
--- a/core/src/main/java/com/netflix/iceberg/BaseTransaction.java
+++ b/core/src/main/java/com/netflix/iceberg/BaseTransaction.java
@@ -100,6 +100,14 @@ class BaseTransaction implements Transaction {
   }
 
   @Override
+  public UpdateSchema updateSchema() {
+    checkLastOperationCommitted("UpdateSchema");
+    UpdateSchema schemaChange = new SchemaUpdate(transactionOps);
+    updates.add(schemaChange);
+    return schemaChange;
+  }
+
+  @Override
   public UpdateProperties updateProperties() {
     checkLastOperationCommitted("UpdateProperties");
     UpdateProperties props = new PropertiesUpdate(transactionOps);
@@ -319,7 +327,7 @@ class BaseTransaction implements Transaction {
 
     @Override
     public UpdateSchema updateSchema() {
-      throw new UnsupportedOperationException("Transaction tables do not support schema updates");
+      return BaseTransaction.this.updateSchema();
     }
 
     @Override