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 04426e8
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,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 +534,13 @@ 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,20 +553,18 @@ 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 =
Expand All @@ -575,11 +573,9 @@ private String resolveNamespaceLocation(Namespace namespace, Map<String, String>
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 04426e8

Please sign in to comment.