Skip to content

Commit edaf474

Browse files
authored
[GOBBLIN-2169] avoid npe while overwrite if table has no previous snapshot (#4071)
1 parent b4e4d4a commit edaf474

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg

gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTable.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ protected void registerIcebergTable(TableMetadata srcMetadata, TableMetadata dst
234234
*
235235
* @param icebergPartitionFilterPredicate the predicate to filter partitions
236236
* @return a list of data files that match the partition filter predicate
237-
* @throws TableNotFoundException if error occurred while accessing the table metadata
238-
* @throws RuntimeException if error occurred while reading the manifest file
237+
* @throws IOException if error occurred while accessing the table metadata or reading the manifest file
239238
*/
240239
public List<DataFile> getPartitionSpecificDataFiles(Predicate<StructLike> icebergPartitionFilterPredicate)
241240
throws IOException {
@@ -286,7 +285,13 @@ protected void overwritePartition(List<DataFile> dataFiles, String partitionColN
286285
if (dataFiles.isEmpty()) {
287286
return;
288287
}
289-
log.info("~{}~ SnapshotId before overwrite: {}", tableId, accessTableMetadata().currentSnapshot().snapshotId());
288+
TableMetadata tableMetadata = accessTableMetadata();
289+
Optional<Snapshot> currentSnapshot = Optional.ofNullable(tableMetadata.currentSnapshot());
290+
if (currentSnapshot.isPresent()) {
291+
log.info("~{}~ SnapshotId before overwrite: {}", tableId, currentSnapshot.get().snapshotId());
292+
} else {
293+
log.warn("~{}~ No current snapshot found before overwrite", tableId);
294+
}
290295
OverwriteFiles overwriteFiles = this.table.newOverwrite();
291296
overwriteFiles.overwriteByRowFilter(Expressions.equal(partitionColName, partitionValue));
292297
dataFiles.forEach(overwriteFiles::addFile);

0 commit comments

Comments
 (0)