Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GOBBLIN-2169] Fix NPE while overwrite if table has no previous snapshot #4071

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
avoid npe while overwrite if table has no previous snapshot
  • Loading branch information
Blazer-007 committed Oct 30, 2024
commit 0e54438abdfb9635bad801d8812c2ec4dbb31365
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ protected void registerIcebergTable(TableMetadata srcMetadata, TableMetadata dst
*
* @param icebergPartitionFilterPredicate the predicate to filter partitions
* @return a list of data files that match the partition filter predicate
* @throws TableNotFoundException if error occurred while accessing the table metadata
* @throws RuntimeException if error occurred while reading the manifest file
* @throws IOException if error occurred while accessing the table metadata or reading the manifest file
*/
public List<DataFile> getPartitionSpecificDataFiles(Predicate<StructLike> icebergPartitionFilterPredicate)
throws IOException {
Comment on lines 239 to 240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't the last line here also throw an NPE for the same reason?

  public List<DataFile> getPartitionSpecificDataFiles(Predicate<StructLike> icebergPartitionFilterPredicate)
      throws IOException {
    TableMetadata tableMetadata = accessTableMetadata();
    Snapshot currentSnapshot = tableMetadata.currentSnapshot();
    long currentSnapshotId = currentSnapshot.snapshotId();

looking quickly at this class, there are several places that are not resilient to the unexpected circumstance of a table having existing and metadata, but not actually any snapshots yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand Down Expand Up @@ -286,7 +285,13 @@ protected void overwritePartition(List<DataFile> dataFiles, String partitionColN
if (dataFiles.isEmpty()) {
return;
}
log.info("~{}~ SnapshotId before overwrite: {}", tableId, accessTableMetadata().currentSnapshot().snapshotId());
TableMetadata tableMetadata = accessTableMetadata();
Optional<Snapshot> currentSnapshot = Optional.ofNullable(tableMetadata.currentSnapshot());
if (currentSnapshot.isPresent()) {
log.info("~{}~ SnapshotId before overwrite: {}", tableId, currentSnapshot.get().snapshotId());
} else {
log.warn("~{}~ No current snapshot found before overwrite", tableId);
}
OverwriteFiles overwriteFiles = this.table.newOverwrite();
overwriteFiles.overwriteByRowFilter(Expressions.equal(partitionColName, partitionValue));
dataFiles.forEach(overwriteFiles::addFile);
Expand Down
Loading