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 @@ -30,8 +30,9 @@ public enum PolarisEntitySubType {
ANY_SUBTYPE(-1, null),
// the NULL value is used when an entity has no subtype, i.e. NOT_APPLICABLE really
NULL_SUBTYPE(0, null),
TABLE(2, PolarisEntityType.ICEBERG_TABLE_LIKE),
VIEW(3, PolarisEntityType.ICEBERG_TABLE_LIKE);
ICEBERG_TABLE(2, PolarisEntityType.TABLE_LIKE),
ICEBERG_VIEW(3, PolarisEntityType.TABLE_LIKE),
GENERIC_TABLE(4, PolarisEntityType.TABLE_LIKE);

// to efficiently map the code of a subtype to its corresponding subtype enum, use a reverse
// array which is initialized below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public enum PolarisEntityType {
CATALOG(4, ROOT, false, false),
CATALOG_ROLE(5, CATALOG, true, false),
NAMESPACE(6, CATALOG, false, true),
// generic table is either a view or a real table
ICEBERG_TABLE_LIKE(7, NAMESPACE, false, false),
TABLE_LIKE(7, NAMESPACE, false, false),
TASK(8, ROOT, false, false),
FILE(9, ICEBERG_TABLE_LIKE, false, false),
POLICY(10, NAMESPACE, false, false),
GENERIC_TABLE(11, NAMESPACE, false, false);
FILE(9, TABLE_LIKE, false, false),
POLICY(10, NAMESPACE, false, false);

// to efficiently map a code to its corresponding entity type, use a reverse array which
// is initialized below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ public enum PolarisPrivilege {
TABLE_CREATE(6, PolarisEntityType.NAMESPACE),
VIEW_CREATE(7, PolarisEntityType.NAMESPACE),
NAMESPACE_DROP(8, PolarisEntityType.NAMESPACE),
TABLE_DROP(9, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
VIEW_DROP(10, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.VIEW),
TABLE_DROP(9, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
VIEW_DROP(10, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_VIEW),
NAMESPACE_LIST(11, PolarisEntityType.NAMESPACE),
TABLE_LIST(12, PolarisEntityType.NAMESPACE),
VIEW_LIST(13, PolarisEntityType.NAMESPACE),
NAMESPACE_READ_PROPERTIES(14, PolarisEntityType.NAMESPACE),
TABLE_READ_PROPERTIES(15, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
VIEW_READ_PROPERTIES(16, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.VIEW),
TABLE_READ_PROPERTIES(15, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
VIEW_READ_PROPERTIES(16, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_VIEW),
NAMESPACE_WRITE_PROPERTIES(17, PolarisEntityType.NAMESPACE),
TABLE_WRITE_PROPERTIES(18, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
VIEW_WRITE_PROPERTIES(19, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.VIEW),
TABLE_READ_DATA(20, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
TABLE_WRITE_DATA(21, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
TABLE_WRITE_PROPERTIES(18, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
VIEW_WRITE_PROPERTIES(19, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_VIEW),
TABLE_READ_DATA(20, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
TABLE_WRITE_DATA(21, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
NAMESPACE_FULL_METADATA(22, PolarisEntityType.NAMESPACE),
TABLE_FULL_METADATA(23, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
VIEW_FULL_METADATA(24, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.VIEW),
TABLE_FULL_METADATA(23, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
VIEW_FULL_METADATA(24, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_VIEW),
CATALOG_CREATE(25, PolarisEntityType.ROOT),
CATALOG_DROP(26, PolarisEntityType.CATALOG),
CATALOG_LIST(27, PolarisEntityType.ROOT),
Expand All @@ -70,14 +70,14 @@ public enum PolarisPrivilege {
CATALOG_ROLE_LIST_GRANTS(35, PolarisEntityType.PRINCIPAL),
CATALOG_LIST_GRANTS(36, PolarisEntityType.CATALOG),
NAMESPACE_LIST_GRANTS(37, PolarisEntityType.NAMESPACE),
TABLE_LIST_GRANTS(38, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
VIEW_LIST_GRANTS(39, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.VIEW),
TABLE_LIST_GRANTS(38, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
VIEW_LIST_GRANTS(39, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_VIEW),
CATALOG_MANAGE_GRANTS_ON_SECURABLE(40, PolarisEntityType.CATALOG),
NAMESPACE_MANAGE_GRANTS_ON_SECURABLE(41, PolarisEntityType.NAMESPACE),
TABLE_MANAGE_GRANTS_ON_SECURABLE(
42, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.TABLE),
42, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_TABLE),
VIEW_MANAGE_GRANTS_ON_SECURABLE(
43, PolarisEntityType.ICEBERG_TABLE_LIKE, PolarisEntitySubType.VIEW),
43, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ICEBERG_VIEW),
PRINCIPAL_CREATE(44, PolarisEntityType.ROOT),
PRINCIPAL_DROP(45, PolarisEntityType.PRINCIPAL),
PRINCIPAL_LIST(46, PolarisEntityType.ROOT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.core.entity;
package org.apache.polaris.core.entity.table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.rest.RESTUtil;
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;

/**
* A {@link PolarisEntity} implementation for generic tables. These tables are not Iceberg-like in
* that they may not have a schema or base location. Similarly to {@link IcebergTableLikeEntity}
* however, these tables have an identifier and a parent namespace.
* A {@link TableLikeEntity} implementation for generic tables. These tables are not Iceberg-like in
* that they may not have a schema or base location.
*/
public class GenericTableEntity extends PolarisEntity {
public class GenericTableEntity extends TableLikeEntity {

public static final String FORMAT_KEY = "format";

Expand All @@ -52,7 +56,8 @@ public static class Builder
extends PolarisEntity.BaseBuilder<GenericTableEntity, GenericTableEntity.Builder> {
public Builder(TableIdentifier tableIdentifier, String format) {
super();
setType(PolarisEntityType.GENERIC_TABLE);
setType(PolarisEntityType.TABLE_LIKE);
setSubType(PolarisEntitySubType.GENERIC_TABLE);
setTableIdentifier(tableIdentifier);
setFormat(format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.core.entity;
package org.apache.polaris.core.entity.table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Optional;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.rest.RESTUtil;

public class IcebergTableLikeEntity extends PolarisEntity {
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.PolarisEntityConstants;
import org.apache.polaris.core.entity.PolarisEntityType;

/**
* An entity type for {@link TableLikeEntity} instances that conform to iceberg semantics around
* locations. This includes both Iceberg tables and Iceberg views.
*/
public class IcebergTableLikeEntity extends TableLikeEntity {
// For applicable types, this key on the "internalProperties" map will return the location
// of the internalProperties JSON file.
public static final String METADATA_LOCATION_KEY = "metadata-location";
Expand All @@ -46,22 +55,6 @@ public static IcebergTableLikeEntity of(PolarisBaseEntity sourceEntity) {
return null;
}

@JsonIgnore
public TableIdentifier getTableIdentifier() {
Namespace parent = getParentNamespace();
return TableIdentifier.of(parent, getName());
}

@JsonIgnore
public Namespace getParentNamespace() {
String encodedNamespace =
getInternalPropertiesAsMap().get(NamespaceEntity.PARENT_NAMESPACE_KEY);
if (encodedNamespace == null) {
return Namespace.empty();
}
return RESTUtil.decodeNamespace(encodedNamespace);
}

@JsonIgnore
public String getMetadataLocation() {
return getInternalPropertiesAsMap().get(METADATA_LOCATION_KEY);
Expand All @@ -82,7 +75,7 @@ public String getBaseLocation() {
public static class Builder extends PolarisEntity.BaseBuilder<IcebergTableLikeEntity, Builder> {
public Builder(TableIdentifier identifier, String metadataLocation) {
super();
setType(PolarisEntityType.ICEBERG_TABLE_LIKE);
setType(PolarisEntityType.TABLE_LIKE);
Copy link
Contributor

Choose a reason for hiding this comment

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

One quick question here, where would the subtype for the ICEBERG_TABLE OR VIEW set? I see for generic table it is set during build

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For those types, it's set during entity construction e.g. here

setTableIdentifier(identifier);
setMetadataLocation(metadataLocation);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.core.entity.table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.annotation.Nonnull;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.rest.RESTUtil;
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.PolarisEntityType;

/**
* An entity type for all table-like entities including Iceberg tables, Iceberg views, and generic
* tables. This entity maps to {@link PolarisEntityType#TABLE_LIKE}
*/
public abstract class TableLikeEntity extends PolarisEntity {

public TableLikeEntity(@Nonnull PolarisBaseEntity sourceEntity) {
super(sourceEntity);
}

@JsonIgnore
public TableIdentifier getTableIdentifier() {
Namespace parent = getParentNamespace();
return TableIdentifier.of(parent, getName());
}

@JsonIgnore
public Namespace getParentNamespace() {
String encodedNamespace =
getInternalPropertiesAsMap().get(NamespaceEntity.PARENT_NAMESPACE_KEY);
if (encodedNamespace == null) {
return Namespace.empty();
}
return RESTUtil.decodeNamespace(encodedNamespace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ public ResolverStatus resolveAll() {

// validate input
diagnostics.check(
entityType != PolarisEntityType.NAMESPACE
&& entityType != PolarisEntityType.ICEBERG_TABLE_LIKE,
entityType != PolarisEntityType.NAMESPACE && entityType != PolarisEntityType.TABLE_LIKE,
"cannot_be_path");
diagnostics.check(
entityType.isTopLevel() || this.referenceCatalogName != null, "reference_catalog_expected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.polaris.core.policy.validator.datacompaction;

import static org.apache.polaris.core.entity.PolarisEntityType.CATALOG;
import static org.apache.polaris.core.entity.PolarisEntityType.ICEBERG_TABLE_LIKE;
import static org.apache.polaris.core.entity.PolarisEntityType.NAMESPACE;
import static org.apache.polaris.core.entity.PolarisEntityType.TABLE_LIKE;

import java.util.Set;
import org.apache.polaris.core.entity.PolarisEntitySubType;
Expand All @@ -32,7 +32,7 @@ public class DataCompactionPolicyValidator implements PolicyValidator {
public static final DataCompactionPolicyValidator INSTANCE = new DataCompactionPolicyValidator();

private static final Set<PolarisEntityType> ATTACHABLE_ENTITY_TYPES =
Set.of(CATALOG, NAMESPACE, ICEBERG_TABLE_LIKE);
Set.of(CATALOG, NAMESPACE, TABLE_LIKE);

@Override
public void validate(String content) throws InvalidPolicyException {
Expand All @@ -49,7 +49,7 @@ public boolean canAttach(PolarisEntityType entityType, PolarisEntitySubType enti
return false;
}

if (entityType == ICEBERG_TABLE_LIKE && entitySubType != PolarisEntitySubType.TABLE) {
if (entityType == TABLE_LIKE && entitySubType != PolarisEntitySubType.ICEBERG_TABLE) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.IcebergTableLikeEntity;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.core.entity.table.IcebergTableLikeEntity;
import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
import org.apache.polaris.core.storage.azure.AzureStorageConfigurationInfo;
import org.apache.polaris.core.storage.gcp.GcpStorageConfigurationInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Map<String, String> getIfPresent(StorageCredentialCacheKey key) {
private boolean isTypeSupported(PolarisEntityType type) {
return type == PolarisEntityType.CATALOG
|| type == PolarisEntityType.NAMESPACE
|| type == PolarisEntityType.ICEBERG_TABLE_LIKE
|| type == PolarisEntityType.TABLE_LIKE
|| type == PolarisEntityType.TASK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ void testRefresh() {
PolarisBaseEntity T6v1 =
this.tm.ensureExistsByName(
List.of(catalog, N5, N5_N6),
PolarisEntityType.ICEBERG_TABLE_LIKE,
PolarisEntitySubType.TABLE,
PolarisEntityType.TABLE_LIKE,
PolarisEntitySubType.ICEBERG_TABLE,
"T6");
Assertions.assertThat(T6v1).isNotNull();

Expand Down Expand Up @@ -435,8 +435,7 @@ void testRenameAndCacheDestinationBeforeLoadingSource() {
Assertions.assertThat(lookup).isNotNull();

EntityCacheByNameKey T4_name =
new EntityCacheByNameKey(
N1.getCatalogId(), N1.getId(), PolarisEntityType.ICEBERG_TABLE_LIKE, "T4");
new EntityCacheByNameKey(N1.getCatalogId(), N1.getId(), PolarisEntityType.TABLE_LIKE, "T4");
lookup = cache.getOrLoadEntityByName(callCtx, T4_name);
Assertions.assertThat(lookup).isNotNull();
ResolvedPolarisEntity cacheEntry_T4 = lookup.getCacheEntry();
Expand All @@ -451,7 +450,7 @@ void testRenameAndCacheDestinationBeforeLoadingSource() {
// load the renamed entity into cache
EntityCacheByNameKey T4_renamed =
new EntityCacheByNameKey(
N1.getCatalogId(), N1.getId(), PolarisEntityType.ICEBERG_TABLE_LIKE, "T4_renamed");
N1.getCatalogId(), N1.getId(), PolarisEntityType.TABLE_LIKE, "T4_renamed");
lookup = cache.getOrLoadEntityByName(callCtx, T4_renamed);
Assertions.assertThat(lookup).isNotNull();
ResolvedPolarisEntity cacheEntry_T4_renamed = lookup.getCacheEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ void testResolvePath(boolean useCache) {

// N1/N2/T1 which exists
ResolverPath N1_N2_T1 =
new ResolverPath(List.of("N1", "N2", "T1"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N1", "N2", "T1"), PolarisEntityType.TABLE_LIKE);
this.resolveDriver(this.cache, "test", N1_N2_T1, null, null);

// N1/N2/T1 which exists
ResolverPath N1_N2_V1 =
new ResolverPath(List.of("N1", "N2", "V1"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N1", "N2", "V1"), PolarisEntityType.TABLE_LIKE);
this.resolveDriver(this.cache, "test", N1_N2_V1, null, null);

// N5/N6 which exists
Expand All @@ -230,7 +230,7 @@ void testResolvePath(boolean useCache) {

// N5/N6/T5 which exists
ResolverPath N5_N6_T5 =
new ResolverPath(List.of("N5", "N6", "T5"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N5", "N6", "T5"), PolarisEntityType.TABLE_LIKE);
this.resolveDriver(this.cache, "test", N5_N6_T5, null, null);

// N7/N8 which exists
Expand All @@ -248,7 +248,7 @@ void testResolvePath(boolean useCache) {

// Error scenarios: N5/N6/T8 which does not exists
ResolverPath N5_N6_T8 =
new ResolverPath(List.of("N5", "N6", "T8"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N5", "N6", "T8"), PolarisEntityType.TABLE_LIKE);
this.resolveDriver(
this.cache,
"test",
Expand All @@ -258,7 +258,7 @@ void testResolvePath(boolean useCache) {

// Error scenarios: N8/N6/T8 which does not exists
ResolverPath N8_N6_T8 =
new ResolverPath(List.of("N8", "N6", "T8"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N8", "N6", "T8"), PolarisEntityType.TABLE_LIKE);
this.resolveDriver(
this.cache,
"test",
Expand All @@ -277,8 +277,7 @@ void testResolvePath(boolean useCache) {
ResolverStatus.StatusEnum.PATH_COULD_NOT_BE_FULLY_RESOLVED);

// except if the optional flag is specified
N5_N6_T8 =
new ResolverPath(List.of("N5", "N6", "T8"), PolarisEntityType.ICEBERG_TABLE_LIKE, true);
N5_N6_T8 = new ResolverPath(List.of("N5", "N6", "T8"), PolarisEntityType.TABLE_LIKE, true);
Resolver resolver =
this.resolveDriver(this.cache, "test", null, List.of(N1, N5_N6_T8, N5_N6_T5, N1_N2), null);
// get all the resolved paths
Expand Down Expand Up @@ -366,7 +365,7 @@ void testPathConsistency(boolean useCache) {
ResolverPath N1_N2_PATH = new ResolverPath(List.of("N1", "N2"), PolarisEntityType.NAMESPACE);
this.resolveDriver(this.cache, "test", N1_N2_PATH, null, null);
ResolverPath N1_N2_T1_PATH =
new ResolverPath(List.of("N1", "N2", "T1"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N1", "N2", "T1"), PolarisEntityType.TABLE_LIKE);
Resolver resolver = this.resolveDriver(this.cache, "test", N1_N2_T1_PATH, null, null);

// get the catalog
Expand Down Expand Up @@ -400,7 +399,7 @@ void testPathConsistency(boolean useCache) {

// but we should be able to resolve it under N1/N3
ResolverPath N1_N3_T1_PATH =
new ResolverPath(List.of("N1", "N3", "T1"), PolarisEntityType.ICEBERG_TABLE_LIKE);
new ResolverPath(List.of("N1", "N3", "T1"), PolarisEntityType.TABLE_LIKE);
this.resolveDriver(this.cache, "test", N1_N3_T1_PATH, null, null);
}

Expand Down
Loading