Skip to content

Commit

Permalink
use checkNotNull
Browse files Browse the repository at this point in the history
  • Loading branch information
d87zhang committed Dec 21, 2024
1 parent 6284af8 commit 0589ae9
Showing 1 changed file with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
Expand All @@ -38,8 +39,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.annotation.Nullable;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.iceberg.BaseMetastoreTableOperations;
import org.apache.iceberg.BaseTable;
Expand Down Expand Up @@ -353,7 +352,7 @@ protected String defaultWarehouseLocation(TableIdentifier tableIdentifier) {
"Namespace does not exist: %s", tableIdentifier.namespace());
}
List<PolarisEntity> namespacePath = resolvedNamespace.getRawFullPath();
String namespaceLocation = resolveLocationForPath(namespacePath);
String namespaceLocation = resolveLocationForPath(callContext, namespacePath);
return SLASH.join(namespaceLocation, tableIdentifier.name());
}
}
Expand Down Expand Up @@ -534,13 +533,14 @@ private String resolveNamespaceLocation(Namespace namespace, Map<String, String>
? getResolvedParentNamespace(namespace).getRawFullPath()
: List.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());

String parentLocation = resolveLocationForPath(parentPath);
String parentLocation = resolveLocationForPath(callContext, parentPath);

return parentLocation + "/" + namespace.level(namespace.length() - 1);
}
}

private static @Nonnull String resolveLocationForPath(List<PolarisEntity> parentPath) {
private static @Nonnull String resolveLocationForPath(
@Nonnull CallContext callContext, List<PolarisEntity> parentPath) {
// always take the first object. If it has the base-location, stop there
AtomicBoolean foundBaseLocation = new AtomicBoolean(false);
return parentPath.reversed().stream()
Expand All @@ -553,33 +553,40 @@ private String resolveNamespaceLocation(Namespace namespace, Map<String, String>
.toList()
.reversed()
.stream()
.map(this::baseLocation)
.map(entity -> baseLocation(callContext, entity))
.map(BasePolarisCatalog::stripLeadingTrailingSlash)
.collect(Collectors.joining("/"));
}

private static @Nullable String baseLocation(PolarisEntity entity) {
private static @Nullable String baseLocation(
@Nonnull CallContext callContext, PolarisEntity entity) {
if (entity.getType().equals(PolarisEntityType.CATALOG)) {
CatalogEntity catEntity = CatalogEntity.of(entity);
String catalogDefaultBaseLocation = catEntity.getDefaultBaseLocation();
if (catalogDefaultBaseLocation == null) {
LOGGER.debug(
"Tried to resolve location with catalog with null default base location. Catalog = {}",
catEntity);
}
callContext
.getPolarisCallContext()
.getDiagServices()
.checkNotNull(
catalogDefaultBaseLocation,
"Tried to resolve location with catalog with null default base location",
"catalog = {}",
catEntity);
return catalogDefaultBaseLocation;
} else {
String baseLocation =
entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION);
entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION);
if (baseLocation != null) {
return baseLocation;
} else {
String entityName = entity.getName();
if (entityName == null) {
LOGGER.debug(
"Tried to resolve location with entity without base location or name. entity = {}",
entity);
}
callContext
.getPolarisCallContext()
.getDiagServices()
.checkNotNull(
entityName,
"Tried to resolve location with entity without base location or name",
"entity = {}",
entity);
return entityName;
}
}
Expand Down

0 comments on commit 0589ae9

Please sign in to comment.