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

[iceberg] branch master updated: Core: Serialize all specs in SerializableTable (#2975)

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

aokolnychyi 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 fe08748  Core: Serialize all specs in SerializableTable (#2975)
fe08748 is described below

commit fe08748783ee1e2de890a1f138bfeaee616cadd8
Author: Anton Okolnychyi <ao...@apple.com>
AuthorDate: Fri Aug 13 20:09:45 2021 -1000

    Core: Serialize all specs in SerializableTable (#2975)
---
 .../java/org/apache/iceberg/SerializableTable.java | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/SerializableTable.java b/core/src/main/java/org/apache/iceberg/SerializableTable.java
index d8f623d..492a900 100644
--- a/core/src/main/java/org/apache/iceberg/SerializableTable.java
+++ b/core/src/main/java/org/apache/iceberg/SerializableTable.java
@@ -54,7 +54,8 @@ public class SerializableTable implements Table, Serializable {
   private final String metadataFileLocation;
   private final Map<String, String> properties;
   private final String schemaAsJson;
-  private final String specAsJson;
+  private final int defaultSpecId;
+  private final Map<Integer, String> specAsJsonMap;
   private final String sortOrderAsJson;
   private final FileIO io;
   private final EncryptionManager encryption;
@@ -62,7 +63,7 @@ public class SerializableTable implements Table, Serializable {
 
   private transient volatile Table lazyTable = null;
   private transient volatile Schema lazySchema = null;
-  private transient volatile PartitionSpec lazySpec = null;
+  private transient volatile Map<Integer, PartitionSpec> lazySpecs = null;
   private transient volatile SortOrder lazySortOrder = null;
 
   private SerializableTable(Table table) {
@@ -71,7 +72,10 @@ public class SerializableTable implements Table, Serializable {
     this.metadataFileLocation = metadataFileLocation(table);
     this.properties = SerializableMap.copyOf(table.properties());
     this.schemaAsJson = SchemaParser.toJson(table.schema());
-    this.specAsJson = PartitionSpecParser.toJson(table.spec());
+    this.defaultSpecId = table.spec().specId();
+    this.specAsJsonMap = Maps.newHashMap();
+    Map<Integer, PartitionSpec> specs = table.specs();
+    specs.forEach((specId, spec) -> specAsJsonMap.put(specId, PartitionSpecParser.toJson(spec)));
     this.sortOrderAsJson = SortOrderParser.toJson(table.sortOrder());
     this.io = fileIO(table);
     this.encryption = table.encryption();
@@ -168,23 +172,27 @@ public class SerializableTable implements Table, Serializable {
 
   @Override
   public PartitionSpec spec() {
-    if (lazySpec == null) {
+    return specs().get(defaultSpecId);
+  }
+
+  @Override
+  public Map<Integer, PartitionSpec> specs() {
+    if (lazySpecs == null) {
       synchronized (this) {
-        if (lazySpec == null && lazyTable == null) {
+        if (lazySpecs == null && lazyTable == null) {
           // prefer parsing JSON as opposed to loading the metadata
-          this.lazySpec = PartitionSpecParser.fromJson(schema(), specAsJson);
-        } else if (lazySpec == null) {
-          this.lazySpec = lazyTable.spec();
+          Map<Integer, PartitionSpec> specs = Maps.newHashMapWithExpectedSize(specAsJsonMap.size());
+          specAsJsonMap.forEach((specId, specAsJson) -> {
+            specs.put(specId, PartitionSpecParser.fromJson(schema(), specAsJson));
+          });
+          this.lazySpecs = specs;
+        } else if (lazySpecs == null) {
+          this.lazySpecs = lazyTable.specs();
         }
       }
     }
 
-    return lazySpec;
-  }
-
-  @Override
-  public Map<Integer, PartitionSpec> specs() {
-    return lazyTable().specs();
+    return lazySpecs;
   }
 
   @Override