Allow passing the unpartitioned spec to DataFiles.builder. (#71)
authorRyan Blue <rdblue@users.noreply.github.com>
Mon, 14 Jan 2019 18:55:57 +0000 (10:55 -0800)
committerGitHub <noreply@github.com>
Mon, 14 Jan 2019 18:55:57 +0000 (10:55 -0800)
core/src/main/java/com/netflix/iceberg/DataFiles.java

index bee5252..b3bac11 100644 (file)
@@ -194,8 +194,8 @@ public class DataFiles {
 
     public Builder(PartitionSpec spec) {
       this.spec = spec;
-      this.partitionData = newPartitionData(spec);
-      this.isPartitioned = true;
+      this.isPartitioned = spec.fields().size() > 0;
+      this.partitionData = isPartitioned ? newPartitionData(spec) : null;
     }
 
     public void clear() {
@@ -284,7 +284,7 @@ public class DataFiles {
     }
 
     public Builder withPartitionPath(String partitionPath) {
-      Preconditions.checkArgument(isPartitioned,
+      Preconditions.checkArgument(isPartitioned || partitionPath.isEmpty(),
           "Cannot add partition data for an unpartitioned table");
       this.partitionData = fillFromPath(spec, partitionPath, partitionData);
       return this;