Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public CatalogEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.CATALOG, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable CatalogEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public CatalogRoleEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.CATALOG_ROLE, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable CatalogRoleEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public NamespaceEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.NAMESPACE, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable NamespaceEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public PrincipalEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.PRINCIPAL, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable PrincipalEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public PrincipalRoleEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.PRINCIPAL_ROLE, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable PrincipalRoleEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public TaskEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.TASK, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable TaskEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.polaris.core.entity.table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Preconditions;
import jakarta.annotation.Nullable;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
Expand All @@ -41,6 +42,10 @@ public class GenericTableEntity extends TableLikeEntity {

public GenericTableEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
getSubType() == PolarisEntitySubType.GENERIC_TABLE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable GenericTableEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.polaris.core.entity.table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Preconditions;
import jakarta.annotation.Nullable;
import java.util.Optional;
import org.apache.iceberg.catalog.Namespace;
Expand All @@ -28,6 +29,7 @@
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;

/**
Expand All @@ -47,6 +49,12 @@ public class IcebergTableLikeEntity extends TableLikeEntity {

public IcebergTableLikeEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
PolarisEntitySubType subType = getSubType();
Preconditions.checkState(
subType == PolarisEntitySubType.ICEBERG_TABLE
|| subType == PolarisEntitySubType.ICEBERG_VIEW,
"Invalid entity sub type: %s",
subType);
}

public static @Nullable IcebergTableLikeEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down Expand Up @@ -75,9 +83,11 @@ public String getBaseLocation() {
}

public static class Builder extends PolarisEntity.BaseBuilder<IcebergTableLikeEntity, Builder> {
public Builder(TableIdentifier identifier, String metadataLocation) {
public Builder(
PolarisEntitySubType subType, TableIdentifier identifier, String metadataLocation) {
super();
setType(PolarisEntityType.TABLE_LIKE);
setSubType(subType);
setTableIdentifier(identifier);
setMetadataLocation(metadataLocation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.polaris.core.entity.NamespaceEntity;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;

public class PolicyEntity extends PolarisEntity {
Expand All @@ -39,6 +40,10 @@ public class PolicyEntity extends PolarisEntity {
super(sourceEntity);
Preconditions.checkState(
getType() == PolarisEntityType.POLICY, "Invalid entity type: %s", getType());
Preconditions.checkState(
getSubType() == PolarisEntitySubType.NULL_SUBTYPE,
"Invalid entity sub type: %s",
getSubType());
}

public static @Nullable PolicyEntity of(@Nullable PolarisBaseEntity sourceEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.table.IcebergTableLikeEntity;
import org.apache.polaris.core.persistence.ResolvedPolarisEntity;
import org.assertj.core.api.Assertions;
Expand All @@ -48,7 +49,9 @@ private ResolvedPolarisEntity getEntity(
String properties,
Optional<String> internalProperties) {
Map<String, String> propertiesMap = getPropertiesMap(properties);
var entity = new IcebergTableLikeEntity.Builder(TableIdentifier.of(name), metadataLocation);
var entity =
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, TableIdentifier.of(name), metadataLocation);
entity.setProperties(propertiesMap);
internalProperties.ifPresent(
p -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,18 @@ private int getEntityWeight(PolarisEntity entity) {

@Test
void testEntityWeigher() {
var smallEntity = new IcebergTableLikeEntity.Builder(TableIdentifier.of("ns.t1"), "").build();
var smallEntity =
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, TableIdentifier.of("ns.t1"), "")
.build();
var mediumEntity =
new IcebergTableLikeEntity.Builder(TableIdentifier.of("ns.t1"), "")
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, TableIdentifier.of("ns.t1"), "")
.setMetadataLocation("a".repeat(10000))
.build();
var largeEntity =
new IcebergTableLikeEntity.Builder(TableIdentifier.of("ns.t1"), "")
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, TableIdentifier.of("ns.t1"), "")
.setMetadataLocation("a".repeat(1000 * 1000))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testCanAttachReturnsTrueForNamespaceType() {
@Test
public void testCanAttachReturnsTrueForIcebergTableLikeWithTableSubtype() {
var targetEntity =
new IcebergTableLikeEntity.Builder(tableIdentifier, "").setSubType(ICEBERG_TABLE).build();
new IcebergTableLikeEntity.Builder(ICEBERG_TABLE, tableIdentifier, "").build();
var result = PolicyValidators.canAttach(policyEntity, targetEntity);
assertThat(result)
.isTrue()
Expand All @@ -116,7 +116,7 @@ public void testCanAttachReturnsTrueForIcebergTableLikeWithTableSubtype() {
@Test
public void testCanAttachReturnsFalseForIcebergTableLikeWithNonTableSubtype() {
var targetEntity =
new IcebergTableLikeEntity.Builder(tableIdentifier, "").setSubType(ICEBERG_VIEW).build();
new IcebergTableLikeEntity.Builder(ICEBERG_VIEW, tableIdentifier, "").build();
var result = PolicyValidators.canAttach(policyEntity, targetEntity);
assertThat(result)
.isFalse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public GenericTableEntity createGenericTable(
PolarisResolvedPathWrapper resolvedEntities =
resolvedEntityView.getPassthroughResolvedPath(
tableIdentifier, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ANY_SUBTYPE);
GenericTableEntity entity =
GenericTableEntity.of(
resolvedEntities == null ? null : resolvedEntities.getRawLeafEntity());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not every table-like entity we find here is a generic table

PolarisEntity entity = resolvedEntities == null ? null : resolvedEntities.getRawLeafEntity();
if (null == entity) {
entity =
new GenericTableEntity.Builder(tableIdentifier, format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.entity.PolarisTaskConstants;
import org.apache.polaris.core.entity.table.GenericTableEntity;
import org.apache.polaris.core.entity.table.IcebergTableLikeEntity;
import org.apache.polaris.core.exceptions.CommitConflictException;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
Expand Down Expand Up @@ -1060,6 +1061,7 @@ private void validateNoLocationOverlap(
IcebergTableLikeEntity.of(
new PolarisEntity.Builder()
.setType(PolarisEntityType.TABLE_LIKE)
.setSubType(PolarisEntitySubType.ICEBERG_TABLE)
.setParentId(resolvedNamespace.getLast().getId())
.setProperties(Map.of(PolarisEntityConstants.ENTITY_BASE_LOCATION, location))
.build());
Expand Down Expand Up @@ -1262,8 +1264,11 @@ private <T extends PolarisEntity & LocationBasedEntity> void validateNoLocationO
tbl -> {
PolarisResolvedPathWrapper resolveTablePath =
resolutionManifest.getResolvedPath(tbl);
return IcebergTableLikeEntity.of(resolveTablePath.getRawLeafEntity())
.getBaseLocation();
PolarisEntity tableEntity = resolveTablePath.getRawLeafEntity();
if (tableEntity.getSubType() == PolarisEntitySubType.GENERIC_TABLE) {
return GenericTableEntity.of(tableEntity).getBaseLocation();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since the getBaseLocation() impl is different between GenericTableEntity and IcebergTableLikeEntity this might have actually fixed a bug?

}
return IcebergTableLikeEntity.of(tableEntity).getBaseLocation();
}),
siblingNamespaces.stream()
.filter(ns -> !ns.level(ns.length() - 1).equals(name))
Expand Down Expand Up @@ -1567,9 +1572,9 @@ public void doCommit(TableMetadata base, TableMetadata metadata) {
if (null == entity) {
existingLocation = null;
entity =
new IcebergTableLikeEntity.Builder(tableIdentifier, newLocation)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, newLocation)
.setCatalogId(getCatalogId())
.setSubType(PolarisEntitySubType.ICEBERG_TABLE)
.setBaseLocation(metadata.location())
.setId(
getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId())
Expand Down Expand Up @@ -1904,9 +1909,9 @@ public void doCommit(ViewMetadata base, ViewMetadata metadata) {
if (null == entity) {
existingLocation = null;
entity =
new IcebergTableLikeEntity.Builder(identifier, newLocation)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_VIEW, identifier, newLocation)
.setCatalogId(getCatalogId())
.setSubType(PolarisEntitySubType.ICEBERG_VIEW)
.setId(
getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId())
.build();
Expand Down Expand Up @@ -2503,9 +2508,9 @@ private boolean sendNotificationForTableLike(
if (null == entity) {
existingLocation = null;
entity =
new IcebergTableLikeEntity.Builder(tableIdentifier, newLocation)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, newLocation)
.setCatalogId(getCatalogId())
.setSubType(PolarisEntitySubType.ICEBERG_TABLE)
.setId(
getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId())
.setLastNotificationTimestamp(request.getPayload().getTimestamp())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.AsyncTaskType;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.entity.TaskEntity;
import org.apache.polaris.core.entity.table.IcebergTableLikeEntity;
Expand Down Expand Up @@ -107,7 +108,8 @@ public void testTableCleanup() throws IOException {
.setName("cleanup_" + tableIdentifier)
.withTaskType(AsyncTaskType.ENTITY_CLEANUP_SCHEDULER)
.withData(
new IcebergTableLikeEntity.Builder(tableIdentifier, metadataFile)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, metadataFile)
.setName("table1")
.setCatalogId(1)
.setCreateTimestamp(100)
Expand Down Expand Up @@ -171,7 +173,8 @@ public void close() {
TaskTestUtils.writeTableMetadata(fileIO, metadataFile, snapshot);

IcebergTableLikeEntity icebergTableLikeEntity =
new IcebergTableLikeEntity.Builder(tableIdentifier, metadataFile)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, metadataFile)
.setName("table1")
.setCatalogId(1)
.setCreateTimestamp(100)
Expand Down Expand Up @@ -233,7 +236,8 @@ public void close() {
.setName("cleanup_" + tableIdentifier)
.withTaskType(AsyncTaskType.ENTITY_CLEANUP_SCHEDULER)
.withData(
new IcebergTableLikeEntity.Builder(tableIdentifier, metadataFile)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, metadataFile)
.setName("table1")
.setCatalogId(1)
.setCreateTimestamp(100)
Expand Down Expand Up @@ -350,7 +354,8 @@ public void testTableCleanupMultipleSnapshots() throws IOException {
.setName("cleanup_" + tableIdentifier)
.withTaskType(AsyncTaskType.ENTITY_CLEANUP_SCHEDULER)
.withData(
new IcebergTableLikeEntity.Builder(tableIdentifier, metadataFile)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, metadataFile)
.setName("table1")
.setCatalogId(1)
.setCreateTimestamp(100)
Expand Down Expand Up @@ -516,7 +521,8 @@ public void testTableCleanupMultipleMetadata() throws IOException {
.setName("cleanup_" + tableIdentifier)
.withTaskType(AsyncTaskType.ENTITY_CLEANUP_SCHEDULER)
.withData(
new IcebergTableLikeEntity.Builder(tableIdentifier, secondMetadataFile)
new IcebergTableLikeEntity.Builder(
PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, secondMetadataFile)
.setName("table1")
.setCatalogId(1)
.setCreateTimestamp(100)
Expand Down