Skip to content

Commit

Permalink
Handle polaris iceberg update case for previous location empty
Browse files Browse the repository at this point in the history
  • Loading branch information
insyncoss committed Feb 1, 2023
1 parent 20f9809 commit dd680fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ public void update(final ConnectorRequestContext requestContext, final TableInfo
}
final String prevLoc = newTableMetadata.get(DirectSqlTable.PARAM_PREVIOUS_METADATA_LOCATION);
final String newLoc = newTableMetadata.get(DirectSqlTable.PARAM_METADATA_LOCATION);
if (StringUtils.isBlank(prevLoc) || StringUtils.isBlank(newLoc)) {
if (StringUtils.isBlank(prevLoc)) {
log.info("Provided previous {} empty for {} with new {}, treating as no location update needed.",
prevLoc, name, newLoc);
return;
}
if (StringUtils.isBlank(newLoc)) {
final String message = String.format(
"Invalid metadata for %s. Provided previous %s or new %s location is empty.",
name, prevLoc, newLoc);
Expand All @@ -246,12 +251,18 @@ public void update(final ConnectorRequestContext requestContext, final TableInfo
// if succeeded then done, else try to figure out why and throw corresponding exception
if (updated) {
requestContext.setIgnoreErrorsAfterUpdate(true);
log.warn("Success servicing Iceberg commit request for table: {}, "
+ "previousLocation: {}, newLocation: {}",
tableInfo.getName(), prevLoc, newLoc);
return;
}
final PolarisTableEntity table = polarisStoreService
.getTable(name.getDatabaseName(), name.getTableName())
.orElseThrow(() -> new TableNotFoundException(name));
final String existingLoc = table.getMetadataLocation();
log.warn("Error servicing Iceberg commit request for tableId: {}, "
+ "previousLocation: {}, existingLocation: {}, newLocation: {}",
table.getTblId(), prevLoc, existingLoc, newLoc);
if (StringUtils.isBlank(existingLoc)) {
final String message = String.format(
"Invalid metadata location for %s existing location is empty.", name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ public void testUpdateTableReject() {
polarisTableService.create(requestContext, tableInfo0);
final TableInfo tableResult0 = polarisTableService.get(requestContext, qualifiedName);
Assert.assertEquals(tableResult0.getMetadata().get("metadata_location"), location0);
// check update location without setting prev location fails
metadata.put("metadata_location", location1);
// check update location without setting location fails
metadata.put("previous_metadata_location", location1);
metadata.remove("metadata_location");
final TableInfo tableInfo1 = TableInfo.builder().name(qualifiedName).metadata(metadata).build();
Assertions.assertThrows(InvalidMetaException.class,
() -> polarisTableService.update(requestContext, tableInfo1));
Expand Down

0 comments on commit dd680fd

Please sign in to comment.