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 2020/02/18 17:35:34 UTC
[incubator-iceberg] branch master updated: Fix
HadoopTableOperations with create transactions (#806)
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 0b49194 Fix HadoopTableOperations with create transactions (#806)
0b49194 is described below
commit 0b491941fdffa2b276dab242f0594463af2b549a
Author: Xiang Li <wa...@gmail.com>
AuthorDate: Wed Feb 19 01:35:26 2020 +0800
Fix HadoopTableOperations with create transactions (#806)
Calling locationProvider() threw a NullPointerException because current metadata was null without a temporary table operations instance.
---
.../iceberg/hadoop/HadoopTableOperations.java | 46 ++++++++++++++++++++++
.../apache/iceberg/hadoop/TestHadoopCatalog.java | 17 ++++++++
2 files changed, 63 insertions(+)
diff --git a/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java b/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java
index 2657be4..ff16bf6 100644
--- a/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java
+++ b/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java
@@ -36,6 +36,7 @@ import org.apache.iceberg.TableMetadata;
import org.apache.iceberg.TableMetadataParser;
import org.apache.iceberg.TableOperations;
import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.exceptions.CommitFailedException;
import org.apache.iceberg.exceptions.RuntimeIOException;
import org.apache.iceberg.exceptions.ValidationException;
@@ -180,6 +181,51 @@ public class HadoopTableOperations implements TableOperations {
return metadataPath(fileName).toString();
}
+ @Override
+ public TableOperations temp(TableMetadata uncommittedMetadata) {
+ return new TableOperations() {
+ @Override
+ public TableMetadata current() {
+ return uncommittedMetadata;
+ }
+
+ @Override
+ public TableMetadata refresh() {
+ throw new UnsupportedOperationException("Cannot call refresh on temporary table operations");
+ }
+
+ @Override
+ public void commit(TableMetadata base, TableMetadata metadata) {
+ throw new UnsupportedOperationException("Cannot call commit on temporary table operations");
+ }
+
+ @Override
+ public String metadataFileLocation(String fileName) {
+ return HadoopTableOperations.this.metadataFileLocation(fileName);
+ }
+
+ @Override
+ public LocationProvider locationProvider() {
+ return LocationProviders.locationsFor(uncommittedMetadata.location(), uncommittedMetadata.properties());
+ }
+
+ @Override
+ public FileIO io() {
+ return HadoopTableOperations.this.io();
+ }
+
+ @Override
+ public EncryptionManager encryption() {
+ return HadoopTableOperations.this.encryption();
+ }
+
+ @Override
+ public long newSnapshotId() {
+ return HadoopTableOperations.this.newSnapshotId();
+ }
+ };
+ }
+
private Path getMetadataFile(int metadataVersion) throws IOException {
for (TableMetadataParser.Codec codec : TableMetadataParser.Codec.values()) {
Path metadataFile = metadataFilePath(metadataVersion, codec);
diff --git a/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCatalog.java b/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCatalog.java
index cb9d339..18c5650 100644
--- a/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCatalog.java
@@ -21,6 +21,7 @@ package org.apache.iceberg.hadoop;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import java.io.IOException;
import java.util.List;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
@@ -28,6 +29,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Transaction;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.NotFoundException;
@@ -111,4 +113,19 @@ public class TestHadoopCatalog extends HadoopTableTestBase {
catalog.listTables(Namespace.of("db", "ns1", "ns2"));
});
}
+
+ @Test
+ public void testCallingLocationProviderWhenNoCurrentMetadata() throws IOException {
+ Configuration conf = new Configuration();
+ String warehousePath = temp.newFolder().getAbsolutePath();
+ HadoopCatalog catalog = new HadoopCatalog(conf, warehousePath);
+
+ TableIdentifier tableIdent = TableIdentifier.of("ns1", "ns2", "table1");
+ Transaction create = catalog.newCreateTableTransaction(tableIdent, SCHEMA);
+ create.table().locationProvider(); // NPE triggered if not handled appropriately
+ create.commitTransaction();
+
+ Assert.assertEquals("1 table expected", 1, catalog.listTables(Namespace.of("ns1", "ns2")).size());
+ catalog.dropTable(tableIdent, true);
+ }
}