Skip to content

Commit 3b48197

Browse files
authored
Add IcebergCatalogPrefixParser (#923)
This is an extension point to allow customizing the relationship between realm / catalog and Iceberg REST API prefix.
1 parent 9799e85 commit 3b48197

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.service.catalog;
20+
21+
import jakarta.enterprise.context.ApplicationScoped;
22+
import org.apache.polaris.core.context.RealmContext;
23+
24+
@ApplicationScoped
25+
public class DefaultIcebergCatalogPrefixParser implements IcebergCatalogPrefixParser {
26+
@Override
27+
public String prefixToCatalogName(RealmContext realm, String prefix) {
28+
return prefix;
29+
}
30+
31+
@Override
32+
public String catalogNameToPrefix(RealmContext realm, String catalogName) {
33+
return catalogName;
34+
}
35+
}

service/common/src/main/java/org/apache/polaris/service/catalog/IcebergCatalogAdapter.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public class IcebergCatalogAdapter
126126
private final PolarisConfigurationStore configurationStore;
127127
private final PolarisDiagnostics diagnostics;
128128
private final PolarisAuthorizer polarisAuthorizer;
129+
private final IcebergCatalogPrefixParser prefixParser;
129130

130131
@Inject
131132
public IcebergCatalogAdapter(
@@ -136,7 +137,8 @@ public IcebergCatalogAdapter(
136137
PolarisMetaStoreSession session,
137138
PolarisConfigurationStore configurationStore,
138139
PolarisDiagnostics diagnostics,
139-
PolarisAuthorizer polarisAuthorizer) {
140+
PolarisAuthorizer polarisAuthorizer,
141+
IcebergCatalogPrefixParser prefixParser) {
140142
this.realmContext = realmContext;
141143
this.catalogFactory = catalogFactory;
142144
this.entityManager = entityManager;
@@ -145,6 +147,7 @@ public IcebergCatalogAdapter(
145147
this.configurationStore = configurationStore;
146148
this.diagnostics = diagnostics;
147149
this.polarisAuthorizer = polarisAuthorizer;
150+
this.prefixParser = prefixParser;
148151
}
149152

150153
/**
@@ -153,8 +156,9 @@ public IcebergCatalogAdapter(
153156
*/
154157
private Response withCatalog(
155158
SecurityContext securityContext,
156-
String catalogName,
159+
String prefix,
157160
Function<PolarisCatalogHandlerWrapper, Response> action) {
161+
String catalogName = prefixParser.prefixToCatalogName(realmContext, prefix);
158162
try (PolarisCatalogHandlerWrapper wrapper = newHandlerWrapper(securityContext, catalogName)) {
159163
return action.apply(wrapper);
160164
} catch (RuntimeException e) {
@@ -629,10 +633,11 @@ public Response getConfig(
629633
Map<String, String> properties =
630634
PolarisEntity.of(resolvedReferenceCatalog.getEntity()).getPropertiesAsMap();
631635

636+
String prefix = prefixParser.catalogNameToPrefix(realmContext, warehouse);
632637
return Response.ok(
633638
ConfigResponse.builder()
634639
.withDefaults(properties) // catalog properties are defaults
635-
.withOverrides(ImmutableMap.of("prefix", warehouse))
640+
.withOverrides(ImmutableMap.of("prefix", prefix))
636641
.withEndpoints(
637642
ImmutableList.<Endpoint>builder()
638643
.addAll(DEFAULT_ENDPOINTS)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.service.catalog;
20+
21+
import org.apache.polaris.core.context.RealmContext;
22+
23+
/** An extension point for converting Iceberg REST API "prefix" values to Polaris Catalog names. */
24+
public interface IcebergCatalogPrefixParser {
25+
26+
/**
27+
* Produces the name of a Polaris catalog from the given Iceberg Catalog REST API "prefix" for the
28+
* specified realm.
29+
*
30+
* @param realm identifies the realm where the API request is to be served.
31+
* @param prefix the "prefix" according to the Iceberg REST Catalog API specification.
32+
* @return Polaris Catalog name
33+
*/
34+
String prefixToCatalogName(RealmContext realm, String prefix);
35+
36+
/**
37+
* Produces the "prefix" according to the Iceberg REST Catalog API specification for the given
38+
* Polaris catalog name in the specified realm.
39+
*
40+
* @param realm identifies the realm owning the catalog
41+
* @param catalogName name of a Polaris catalog.
42+
* @return the "prefix" for the Iceberg REST client to be used for requests to the given catalog.
43+
*/
44+
String catalogNameToPrefix(RealmContext realm, String catalogName);
45+
}

service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
4141
import org.apache.polaris.service.admin.PolarisServiceImpl;
4242
import org.apache.polaris.service.admin.api.PolarisCatalogsApi;
43+
import org.apache.polaris.service.catalog.DefaultIcebergCatalogPrefixParser;
4344
import org.apache.polaris.service.catalog.IcebergCatalogAdapter;
4445
import org.apache.polaris.service.catalog.api.IcebergRestCatalogApi;
4546
import org.apache.polaris.service.catalog.api.IcebergRestCatalogApiService;
@@ -163,7 +164,8 @@ public TestServices build() {
163164
metaStoreSession,
164165
configurationStore,
165166
polarisDiagnostics,
166-
authorizer);
167+
authorizer,
168+
new DefaultIcebergCatalogPrefixParser());
167169

168170
IcebergRestCatalogApi restApi = new IcebergRestCatalogApi(service);
169171

0 commit comments

Comments
 (0)