-
Notifications
You must be signed in to change notification settings - Fork 329
Add resource path for Generic Table Endpoints and add the endpoints as supported endpoints when generic table enabled #1286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
21096dd
add change
sfc-gh-yzou c56816e
add generic table endpoints to getConfig
sfc-gh-yzou 86b4b83
remove a function
sfc-gh-yzou 79fc51c
rebase and fix name
gh-yzou 2eacecd
address feedbacks
gh-yzou 07b0e72
spotless
gh-yzou 99af56a
move all functions to PolarisEndpoints
gh-yzou e33f97b
remove extra line
gh-yzou 2d49988
Trigger Build
gh-yzou 1a01f45
Trigger Build
gh-yzou ba292fc
remove extra
gh-yzou 0557bde
fix test
gh-yzou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
polaris-core/src/main/java/org/apache/polaris/core/rest/PolarisEndpoints.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.rest; | ||
|
|
||
| import com.google.common.collect.ImmutableSet; | ||
| import java.util.Set; | ||
| import org.apache.iceberg.rest.Endpoint; | ||
| import org.apache.polaris.core.config.FeatureConfiguration; | ||
| import org.apache.polaris.core.context.CallContext; | ||
|
|
||
| public class PolarisEndpoints { | ||
| public static final Endpoint V1_LIST_GENERIC_TABLES = | ||
| Endpoint.create("GET", PolarisResourcePaths.V1_GENERIC_TABLES); | ||
| public static final Endpoint V1_LOAD_GENERIC_TABLE = | ||
| Endpoint.create("GET", PolarisResourcePaths.V1_GENERIC_TABLE); | ||
| public static final Endpoint V1_CREATE_GENERIC_TABLE = | ||
| Endpoint.create("POST", PolarisResourcePaths.V1_GENERIC_TABLES); | ||
| public static final Endpoint V1_DELETE_GENERIC_TABLE = | ||
| Endpoint.create("DELETE", PolarisResourcePaths.V1_GENERIC_TABLE); | ||
|
|
||
| public static final Set<Endpoint> GENERIC_TABLE_ENDPOINTS = | ||
| ImmutableSet.<Endpoint>builder() | ||
| .add(V1_LIST_GENERIC_TABLES) | ||
| .add(V1_CREATE_GENERIC_TABLE) | ||
| .add(V1_DELETE_GENERIC_TABLE) | ||
| .add(V1_LOAD_GENERIC_TABLE) | ||
| .build(); | ||
|
|
||
| /** | ||
| * Get the generic table endpoints. Returns GENERIC_TABLE_ENDPOINTS if ENABLE_GENERIC_TABLES is | ||
| * set to true, otherwise, returns an empty set. | ||
| */ | ||
| public static Set<Endpoint> getSupportedGenericTableEndpoints(CallContext callContext) { | ||
| // add the generic table endpoints as supported endpoints if generic table feature is enabled. | ||
| boolean genericTableEnabled = | ||
| callContext | ||
| .getPolarisCallContext() | ||
| .getConfigurationStore() | ||
| .getConfiguration( | ||
| callContext.getPolarisCallContext(), FeatureConfiguration.ENABLE_GENERIC_TABLES); | ||
|
|
||
| return genericTableEnabled ? GENERIC_TABLE_ENDPOINTS : ImmutableSet.of(); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
polaris-core/src/main/java/org/apache/polaris/core/rest/PolarisResourcePaths.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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.rest; | ||
|
|
||
| import com.google.common.base.Joiner; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.catalog.Namespace; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.apache.iceberg.rest.RESTUtil; | ||
|
|
||
| public class PolarisResourcePaths { | ||
| private static final Joiner SLASH = Joiner.on("/").skipNulls(); | ||
| public static final String PREFIX = "prefix"; | ||
|
|
||
| // Generic Table endpoints | ||
| public static final String V1_GENERIC_TABLES = | ||
| "polaris/v1/{prefix}/namespaces/{namespace}/generic-tables"; | ||
| public static final String V1_GENERIC_TABLE = | ||
| "polaris/v1/{prefix}/namespaces/{namespace}/generic-tables/{generic-table}"; | ||
|
|
||
| private final String prefix; | ||
|
|
||
| public PolarisResourcePaths(String prefix) { | ||
| this.prefix = prefix; | ||
| } | ||
|
|
||
| public static PolarisResourcePaths forCatalogProperties(Map<String, String> properties) { | ||
| return new PolarisResourcePaths(properties.get(PREFIX)); | ||
| } | ||
|
|
||
| public String genericTables(Namespace ns) { | ||
| return SLASH.join( | ||
| "polaris", "v1", prefix, "namespaces", RESTUtil.encodeNamespace(ns), "generic-tables"); | ||
| } | ||
|
|
||
| public String genericTable(TableIdentifier ident) { | ||
| return SLASH.join( | ||
| "polaris", | ||
| "v1", | ||
| prefix, | ||
| "namespaces", | ||
| RESTUtil.encodeNamespace(ident.namespace()), | ||
| "generic-tables", | ||
| RESTUtil.encodeString(ident.name())); | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
polaris-core/src/test/java/org/apache/polaris/core/rest/PolarisResourcePathsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.rest; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.catalog.Namespace; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class PolarisResourcePathsTest { | ||
| private static final String testPrefix = "polaris-test"; | ||
|
|
||
| private PolarisResourcePaths paths; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| Map<String, String> properties = new HashMap<>(); | ||
| properties.put(PolarisResourcePaths.PREFIX, testPrefix); | ||
| paths = PolarisResourcePaths.forCatalogProperties(properties); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGenericTablesPath() { | ||
| Namespace ns = Namespace.of("ns1", "ns2"); | ||
| String genericTablesPath = paths.genericTables(ns); | ||
| String expectedPath = | ||
| String.format("polaris/v1/%s/namespaces/%s/generic-tables", testPrefix, "ns1%1Fns2"); | ||
| Assertions.assertThat(genericTablesPath).isEqualTo(expectedPath); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGenericTablePath() { | ||
| Namespace ns = Namespace.of("ns1"); | ||
| TableIdentifier ident = TableIdentifier.of(ns, "test-table"); | ||
| String genericTablePath = paths.genericTable(ident); | ||
| String expectedPath = | ||
| String.format( | ||
| "polaris/v1/%s/namespaces/%s/generic-tables/%s", testPrefix, "ns1", "test-table"); | ||
| Assertions.assertThat(genericTablePath).isEqualTo(expectedPath); | ||
| } | ||
| } |
87 changes: 87 additions & 0 deletions
87
quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/GetConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * 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.service.quarkus.catalog; | ||
|
|
||
| import static jakarta.ws.rs.core.Response.Status.CREATED; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.quarkus.test.junit.QuarkusTest; | ||
| import jakarta.ws.rs.core.Response; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import org.apache.iceberg.rest.responses.ConfigResponse; | ||
| import org.apache.polaris.core.admin.model.*; | ||
| import org.apache.polaris.core.rest.PolarisEndpoints; | ||
| import org.apache.polaris.service.TestServices; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| @QuarkusTest | ||
| public class GetConfigTest { | ||
| @ParameterizedTest | ||
| @ValueSource(booleans = {true, false}) | ||
| public void testGetConfig(boolean enableGenericTable) { | ||
| TestServices services = | ||
| TestServices.builder().config(Map.of("ENABLE_GENERIC_TABLES", enableGenericTable)).build(); | ||
|
|
||
| FileStorageConfigInfo fileStorage = | ||
| FileStorageConfigInfo.builder(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file://")) | ||
| .build(); | ||
| String catalogName = "test-catalog-" + UUID.randomUUID(); | ||
| Catalog catalog = | ||
| PolarisCatalog.builder() | ||
| .setType(Catalog.TypeEnum.INTERNAL) | ||
| .setName(catalogName) | ||
| .setProperties(new CatalogProperties("file:///tmp/path/to/data")) | ||
| .setStorageConfigInfo(fileStorage) | ||
| .build(); | ||
|
|
||
| Response response = | ||
| services | ||
| .catalogsApi() | ||
| .createCatalog( | ||
| new CreateCatalogRequest(catalog), | ||
| services.realmContext(), | ||
| services.securityContext()); | ||
| assertThat(response.getStatus()).isEqualTo(CREATED.getStatusCode()); | ||
|
|
||
| response = | ||
| services | ||
| .restConfigurationApi() | ||
| .getConfig(catalogName, services.realmContext(), services.securityContext()); | ||
| ConfigResponse configResponse = response.readEntity(ConfigResponse.class); | ||
| assertThat(configResponse.overrides()).contains(Map.entry("prefix", catalogName)); | ||
| if (enableGenericTable) { | ||
| assertThat(configResponse.endpoints()).contains(PolarisEndpoints.V1_CREATE_GENERIC_TABLE); | ||
| assertThat(configResponse.endpoints()).contains(PolarisEndpoints.V1_DELETE_GENERIC_TABLE); | ||
| assertThat(configResponse.endpoints()).contains(PolarisEndpoints.V1_LIST_GENERIC_TABLES); | ||
| assertThat(configResponse.endpoints()).contains(PolarisEndpoints.V1_LOAD_GENERIC_TABLE); | ||
| } else { | ||
| assertThat(configResponse.endpoints()) | ||
| .doesNotContain(PolarisEndpoints.V1_CREATE_GENERIC_TABLE); | ||
| assertThat(configResponse.endpoints()) | ||
| .doesNotContain(PolarisEndpoints.V1_DELETE_GENERIC_TABLE); | ||
| assertThat(configResponse.endpoints()) | ||
| .doesNotContain(PolarisEndpoints.V1_LIST_GENERIC_TABLES); | ||
| assertThat(configResponse.endpoints()).doesNotContain(PolarisEndpoints.V1_LOAD_GENERIC_TABLE); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flyrain i removed the uncessary profile class definition here, which seems start causing some test flakyness.