Skip to content
Open
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 @@ -41,6 +41,7 @@
import org.apache.iceberg.rest.responses.ListNamespacesResponse;
import org.apache.iceberg.rest.responses.ListTablesResponse;
import org.apache.iceberg.rest.responses.LoadTableResponse;
import org.apache.polaris.core.entity.NamespaceEntity;

/**
* A simple, non-exhaustive set of helper methods for accessing the Iceberg REST API.
Expand Down Expand Up @@ -112,7 +113,8 @@ public List<Namespace> listAllNamespacesChildFirst(String catalog) {
}

public void deleteNamespace(String catalog, Namespace namespace) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response response =
request("v1/{cat}/namespaces/" + ns, Map.of("cat", catalog)).delete()) {
assertThat(response.getStatus()).isEqualTo(NO_CONTENT.getStatusCode());
Expand All @@ -130,7 +132,8 @@ public void purge(String catalog, Namespace ns) {
}

public List<TableIdentifier> listTables(String catalog, Namespace namespace) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request("v1/{cat}/namespaces/" + ns + "/tables", Map.of("cat", catalog)).get()) {
assertThat(res.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
Expand All @@ -140,7 +143,8 @@ public List<TableIdentifier> listTables(String catalog, Namespace namespace) {

public ListTablesResponse listTables(
String catalog, Namespace namespace, String pageToken, String pageSize) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
Map<String, String> queryParams = new HashMap<>();
queryParams.put("pageToken", pageToken);
queryParams.put("pageSize", pageSize);
Expand All @@ -153,7 +157,9 @@ public ListTablesResponse listTables(
}

public void dropTable(String catalog, TableIdentifier id) {
String ns = RESTUtil.encodeNamespace(id.namespace());
String ns =
RESTUtil.encodeNamespace(
id.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"v1/{cat}/namespaces/" + ns + "/tables/{table}",
Expand All @@ -178,7 +184,9 @@ public LoadTableResponse loadTable(
HashMap<String, String> allHeaders = new HashMap<>(defaultHeaders());
allHeaders.putAll(headers);

String ns = RESTUtil.encodeNamespace(id.namespace());
String ns =
RESTUtil.encodeNamespace(
id.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"v1/{cat}/namespaces/" + ns + "/tables/{table}",
Expand All @@ -197,7 +205,8 @@ public LoadTableResponse loadTable(
}

public List<TableIdentifier> listViews(String catalog, Namespace namespace) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request("v1/{cat}/namespaces/" + ns + "/views", Map.of("cat", catalog)).get()) {
assertThat(res.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
Expand All @@ -207,7 +216,8 @@ public List<TableIdentifier> listViews(String catalog, Namespace namespace) {

public ListTablesResponse listViews(
String catalog, Namespace namespace, String pageToken, String pageSize) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
Map<String, String> queryParams = new HashMap<>();
queryParams.put("pageToken", pageToken);
queryParams.put("pageSize", pageSize);
Expand All @@ -220,7 +230,9 @@ public ListTablesResponse listViews(
}

public void dropView(String catalog, TableIdentifier id) {
String ns = RESTUtil.encodeNamespace(id.namespace());
String ns =
RESTUtil.encodeNamespace(
id.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"v1/{cat}/namespaces/" + ns + "/views/{view}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.service.types.CreateGenericTableRequest;
import org.apache.polaris.service.types.GenericTable;
import org.apache.polaris.service.types.ListGenericTablesResponse;
Expand All @@ -50,7 +51,8 @@ public void purge(String catalog, Namespace ns) {
}

public List<TableIdentifier> listGenericTables(String catalog, Namespace namespace) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request("polaris/v1/{cat}/namespaces/{ns}/generic-tables", Map.of("cat", catalog, "ns", ns))
.get()) {
Expand All @@ -60,7 +62,9 @@ public List<TableIdentifier> listGenericTables(String catalog, Namespace namespa
}

public void dropGenericTable(String catalog, TableIdentifier id) {
String ns = RESTUtil.encodeNamespace(id.namespace());
String ns =
RESTUtil.encodeNamespace(
id.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"polaris/v1/{cat}/namespaces/{ns}/generic-tables/{table}",
Expand All @@ -71,7 +75,9 @@ public void dropGenericTable(String catalog, TableIdentifier id) {
}

public GenericTable getGenericTable(String catalog, TableIdentifier id) {
String ns = RESTUtil.encodeNamespace(id.namespace());
String ns =
RESTUtil.encodeNamespace(
id.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"polaris/v1/{cat}/namespaces/{ns}/generic-tables/{table}",
Expand All @@ -83,7 +89,9 @@ public GenericTable getGenericTable(String catalog, TableIdentifier id) {

public GenericTable createGenericTable(
String catalog, TableIdentifier id, String format, Map<String, String> properties) {
String ns = RESTUtil.encodeNamespace(id.namespace());
String ns =
RESTUtil.encodeNamespace(
id.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"polaris/v1/{cat}/namespaces/{ns}/generic-tables/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.rest.RESTUtil;
import org.apache.polaris.core.entity.NamespaceEntity;
import org.apache.polaris.core.policy.PolicyType;
import org.apache.polaris.core.policy.exceptions.PolicyInUseException;
import org.apache.polaris.service.types.ApplicablePolicy;
Expand Down Expand Up @@ -56,7 +57,8 @@ public List<PolicyIdentifier> listPolicies(String catalog, Namespace namespace)
}

public List<PolicyIdentifier> listPolicies(String catalog, Namespace namespace, PolicyType type) {
String ns = RESTUtil.encodeNamespace(namespace);
String ns =
RESTUtil.encodeNamespace(namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
Map<String, String> queryParams = new HashMap<>();
if (type != null) {
queryParams.put("policyType", type.getName());
Expand All @@ -77,7 +79,9 @@ public void dropPolicy(String catalog, PolicyIdentifier policyIdentifier) {
}

public void dropPolicy(String catalog, PolicyIdentifier policyIdentifier, Boolean detachAll) {
String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
Map<String, String> queryParams = new HashMap<>();
if (detachAll != null) {
queryParams.put("detach-all", detachAll.toString());
Expand All @@ -96,7 +100,9 @@ public void dropPolicy(String catalog, PolicyIdentifier policyIdentifier, Boolea
}

public Policy loadPolicy(String catalog, PolicyIdentifier policyIdentifier) {
String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
request(
"polaris/v1/{cat}/namespaces/{ns}/policies/{policy}",
Expand All @@ -113,7 +119,9 @@ public Policy createPolicy(
PolicyType policyType,
String content,
String description) {
String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
CreatePolicyRequest request =
CreatePolicyRequest.builder()
.setType(policyType.getName())
Expand All @@ -135,7 +143,9 @@ public Policy updatePolicy(
String newContent,
String newDescription,
int currentPolicyVersion) {
String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
UpdatePolicyRequest request =
UpdatePolicyRequest.builder()
.setContent(newContent)
Expand All @@ -157,7 +167,9 @@ public void attachPolicy(
PolicyIdentifier policyIdentifier,
PolicyAttachmentTarget target,
Map<String, String> parameters) {
String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
AttachPolicyRequest request =
AttachPolicyRequest.builder().setTarget(target).setParameters(parameters).build();
try (Response res =
Expand All @@ -171,7 +183,9 @@ public void attachPolicy(

public void detachPolicy(
String catalog, PolicyIdentifier policyIdentifier, PolicyAttachmentTarget target) {
String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
DetachPolicyRequest request = DetachPolicyRequest.builder().setTarget(target).build();
try (Response res =
request(
Expand All @@ -184,7 +198,11 @@ public void detachPolicy(

public List<ApplicablePolicy> getApplicablePolicies(
String catalog, Namespace namespace, String targetName, PolicyType policyType) {
String ns = namespace != null ? RESTUtil.encodeNamespace(namespace) : null;
String ns =
namespace != null
? RESTUtil.encodeNamespace(
namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8)
: null;
Map<String, String> queryParams = new HashMap<>();
if (ns != null) {
queryParams.put("namespace", ns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.polaris.core.admin.model.TablePrivilege;
import org.apache.polaris.core.catalog.PolarisCatalogHelpers;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.NamespaceEntity;
import org.apache.polaris.core.policy.PredefinedPolicyTypes;
import org.apache.polaris.core.policy.exceptions.PolicyInUseException;
import org.apache.polaris.service.it.env.CatalogConfig;
Expand Down Expand Up @@ -110,7 +111,8 @@ public class PolarisPolicyServiceIntegrationTest {
private static final PolicyIdentifier NS1_P3 = new PolicyIdentifier(NS1, "P3");
private static final TableIdentifier NS2_T1 = TableIdentifier.of(NS2, "T1");

private static final String NS1_NAME = RESTUtil.encodeNamespace(NS1);
private static final String NS1_NAME =
RESTUtil.encodeNamespace(NS1, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
private static final String INVALID_NAMESPACE = "INVALID_NAMESPACE";
private static final String INVALID_POLICY = "INVALID_POLICY";
private static final String INVALID_TABLE = "INVALID_TABLE";
Expand Down Expand Up @@ -296,7 +298,9 @@ public void testCreatePolicyWithInvalidName(String policyName) {
restCatalog.createNamespace(NS1);
PolicyIdentifier policyIdentifier = new PolicyIdentifier(NS1, policyName);

String ns = RESTUtil.encodeNamespace(policyIdentifier.getNamespace());
String ns =
RESTUtil.encodeNamespace(
policyIdentifier.getNamespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
CreatePolicyRequest request =
CreatePolicyRequest.builder()
.setType(PredefinedPolicyTypes.DATA_COMPACTION.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.apache.polaris.core.admin.model.ViewPrivilege;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.NamespaceEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.service.it.env.CatalogApi;
import org.apache.polaris.service.it.env.CatalogConfig;
Expand Down Expand Up @@ -1536,7 +1537,9 @@ public void testDropNonExistingGenericTable() {
TableIdentifier tableIdentifier = TableIdentifier.of(namespace, "tbl1");

try {
String ns = RESTUtil.encodeNamespace(tableIdentifier.namespace());
String ns =
RESTUtil.encodeNamespace(
tableIdentifier.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
genericTableApi
.request(
Expand Down Expand Up @@ -1617,7 +1620,9 @@ public void testCreateGenericTableWithReservedProperty() {
restCatalog.createNamespace(namespace);
TableIdentifier tableIdentifier = TableIdentifier.of(namespace, "tbl1");

String ns = RESTUtil.encodeNamespace(tableIdentifier.namespace());
String ns =
RESTUtil.encodeNamespace(
tableIdentifier.namespace(), NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
try (Response res =
genericTableApi
.request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class NamespaceEntity extends PolarisEntity implements LocationBasedEntit
// RESTUtil-encoded parent namespace.
public static final String PARENT_NAMESPACE_KEY = "parent-namespace";

/** The URL-encoded UTF-8 representation of the namespace separator character (0x1F). */
public static final String NAMESPACE_SEPARATOR_URLENCODED_UTF_8 = "%1F";

public NamespaceEntity(PolarisBaseEntity sourceEntity) {
super(sourceEntity);
Preconditions.checkState(
Expand All @@ -55,7 +58,7 @@ public Namespace getParentNamespace() {
if (encodedNamespace == null) {
return Namespace.empty();
}
return RESTUtil.decodeNamespace(encodedNamespace);
return RESTUtil.decodeNamespace(encodedNamespace, NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
}

public Namespace asNamespace() {
Expand Down Expand Up @@ -89,7 +92,9 @@ public Builder setBaseLocation(String baseLocation) {

public Builder setParentNamespace(Namespace namespace) {
if (namespace != null && !namespace.isEmpty()) {
internalProperties.put(PARENT_NAMESPACE_KEY, RESTUtil.encodeNamespace(namespace));
internalProperties.put(
PARENT_NAMESPACE_KEY,
RESTUtil.encodeNamespace(namespace, NAMESPACE_SEPARATOR_URLENCODED_UTF_8));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public GenericTableEntity.Builder setTableIdentifier(TableIdentifier identifier)
public GenericTableEntity.Builder setParentNamespace(Namespace namespace) {
if (namespace != null && !namespace.isEmpty()) {
internalProperties.put(
NamespaceEntity.PARENT_NAMESPACE_KEY, RESTUtil.encodeNamespace(namespace));
NamespaceEntity.PARENT_NAMESPACE_KEY,
RESTUtil.encodeNamespace(
namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public Builder setTableIdentifier(TableIdentifier identifier) {
public Builder setParentNamespace(Namespace namespace) {
if (namespace != null && !namespace.isEmpty()) {
internalProperties.put(
NamespaceEntity.PARENT_NAMESPACE_KEY, RESTUtil.encodeNamespace(namespace));
NamespaceEntity.PARENT_NAMESPACE_KEY,
RESTUtil.encodeNamespace(
namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public Namespace getParentNamespace() {
if (encodedNamespace == null) {
return Namespace.empty();
}
return RESTUtil.decodeNamespace(encodedNamespace);
return RESTUtil.decodeNamespace(
encodedNamespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public int getPolicyVersion() {
public Namespace getParentNamespace() {
String parentNamespace = getInternalPropertiesAsMap().get(NamespaceEntity.PARENT_NAMESPACE_KEY);
if (parentNamespace != null) {
return RESTUtil.decodeNamespace(parentNamespace);
return RESTUtil.decodeNamespace(
parentNamespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8);
}
return null;
}
Expand Down Expand Up @@ -114,7 +115,9 @@ public PolicyEntity build() {
public Builder setParentNamespace(Namespace namespace) {
if (namespace != null && !namespace.isEmpty()) {
internalProperties.put(
NamespaceEntity.PARENT_NAMESPACE_KEY, RESTUtil.encodeNamespace(namespace));
NamespaceEntity.PARENT_NAMESPACE_KEY,
RESTUtil.encodeNamespace(
namespace, NamespaceEntity.NAMESPACE_SEPARATOR_URLENCODED_UTF_8));
}
return this;
}
Expand Down
Loading
Loading