You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "adutra (via GitHub)" <gi...@apache.org> on 2026/04/15 17:12:45 UTC
[PR] Isolate encde/decode logic used in Polaris entities [polaris]
adutra opened a new pull request, #4214:
URL: https://github.com/apache/polaris/pull/4214
This change replaces calls to `RESTUtil` in Polaris entity code when serializing or deserializing namespaces stored in internal properties.
It replaces those calls with calls to a new utility class, `PolarisEntityUtils`. The logic used there for encoding and decoding namespaces is in fact identical to `RESTUtil` as of today, but having our own logic protects Polaris from future behavioral changes in `RESTUtil` that could potentially cause data corruption in Polaris metastores.
<!--
๐ Describe what changes you're proposing, especially breaking or user-facing changes.
๐ See https://github.com/apache/polaris/blob/main/CONTRIBUTING.md for more.
-->
## Checklist
- [ ] ๐ก๏ธ Don't disclose security issues! (contact security@apache.org)
- [ ] ๐ Clearly explained why the changes are needed, or linked related issues: Fixes #
- [ ] ๐งช Added/updated tests with good coverage, or manually tested (and explained how)
- [ ] ๐ก Added comments for complex logic
- [ ] ๐งพ Updated `CHANGELOG.md` (if needed)
- [ ] ๐ Updated documentation in `site/content/in-dev/unreleased` (if needed)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #4214:
URL: https://github.com/apache/polaris/pull/4214#discussion_r3088583521
##########
polaris-core/src/test/java/org/apache/polaris/core/entity/PolarisEntityUtilsTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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;
+
+import java.util.stream.Stream;
+import org.apache.iceberg.catalog.Namespace;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.NullSource;
+
+public class PolarisEntityUtilsTest {
+
+ static Stream<Arguments> encodeNamespaceCases() {
+ return Stream.of(
+ // empty namespace encodes to empty string
+ Arguments.of(Namespace.empty(), ""),
+ // single-level namespaces
+ Arguments.of(Namespace.of("a"), "a"),
+ Arguments.of(Namespace.of("hello world"), "hello+world"),
+ Arguments.of(Namespace.of("a/b"), "a%2Fb"),
+ // literal "%1F" in a level name is double-encoded so it can't be confused with separator
+ Arguments.of(Namespace.of("%1F"), "%251F"),
+ // multi-level namespaces: levels are joined with %1F separator
+ Arguments.of(Namespace.of("a", "b"), "a%1Fb"),
+ Arguments.of(Namespace.of("a", "b", "c"), "a%1Fb%1Fc"),
+ Arguments.of(Namespace.of("a/b", "c"), "a%2Fb%1Fc"),
+ // empty level in a multi-level namespace
+ Arguments.of(Namespace.of("a", "", "b"), "a%1F%1Fb"));
+ }
+
+ @ParameterizedTest
+ @MethodSource("encodeNamespaceCases")
+ public void testEncodeNamespace(Namespace ns, String expected) {
+ Assertions.assertThat(PolarisEntityUtils.encodeNamespace(ns)).isEqualTo(expected);
Review Comment:
Could we add an assertion that the result matches `RESTUtil.encodeNamespace`?
For now it will ensure we're not breaking existing logic. If `RESTUtil` becomes incompatible later, we will remove those assertions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #4214:
URL: https://github.com/apache/polaris/pull/4214#discussion_r3089765047
##########
polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntityUtils.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import com.google.common.base.Preconditions;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.rest.RESTUtil;
+
+public final class PolarisEntityUtils {
+
+ private static final String NAMESPACE_SEPARATOR_ENCODED = "%1F";
+
+ private PolarisEntityUtils() {}
+
+ /**
+ * Returns a String representation of a namespace that is suitable for storage in entity internal
+ * properties.
+ *
+ * <p>This method is similar to {@link RESTUtil#encodeNamespace(Namespace)}.
+ */
+ public static String encodeNamespace(Namespace ns) {
+ Preconditions.checkArgument(ns != null, "Invalid namespace: null");
+ String[] levels = ns.levels();
+ String[] encodedLevels = new String[levels.length];
+ for (int i = 0; i < levels.length; i++) {
+ encodedLevels[i] = URLEncoder.encode(levels[i], StandardCharsets.UTF_8);
+ }
+ return String.join(NAMESPACE_SEPARATOR_ENCODED, encodedLevels);
+ }
+
+ /**
+ * Returns a Namespace object from a String representation that was encoded using {@link
+ * #encodeNamespace(Namespace)}.
+ *
+ * <p>This method is similar to {@link RESTUtil#decodeNamespace(String)}.
+ */
+ public static Namespace decodeNamespace(String encodedNs) {
+ Preconditions.checkArgument(encodedNs != null, "Invalid namespace: null");
+ String[] levels = encodedNs.split(NAMESPACE_SEPARATOR_ENCODED, -1);
Review Comment:
The RESTUtil used a guava splitter`com.google.common.base.Splitter`. I think we can validate if Java String splitter behaviors a bit different. I mighty be paranoid. There could be some corner cases causing decoding behavior drift.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "nandorKollar (via GitHub)" <gi...@apache.org>.
nandorKollar commented on PR #4214:
URL: https://github.com/apache/polaris/pull/4214#issuecomment-4258013078
We use `RESTUtil.encodeNamespace` also in other places, like for example in `PolarisResourcePaths`. May I ask why do we replace that call only in the entites?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra merged PR #4214:
URL: https://github.com/apache/polaris/pull/4214
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #4214:
URL: https://github.com/apache/polaris/pull/4214#issuecomment-4259314932
> We use `RESTUtil.encodeNamespace` also in other places, like for example in `PolarisResourcePaths`. May I ask why do we replace that call only in the entites?
I will tackle this later. It will depend on https://github.com/apache/iceberg/pull/15989.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #4214:
URL: https://github.com/apache/polaris/pull/4214#discussion_r3088596467
##########
polaris-core/src/test/java/org/apache/polaris/core/entity/PolarisEntityUtilsTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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;
+
+import java.util.stream.Stream;
+import org.apache.iceberg.catalog.Namespace;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.NullSource;
+
+public class PolarisEntityUtilsTest {
+
+ static Stream<Arguments> encodeNamespaceCases() {
+ return Stream.of(
+ // empty namespace encodes to empty string
+ Arguments.of(Namespace.empty(), ""),
+ // single-level namespaces
+ Arguments.of(Namespace.of("a"), "a"),
+ Arguments.of(Namespace.of("hello world"), "hello+world"),
+ Arguments.of(Namespace.of("a/b"), "a%2Fb"),
+ // literal "%1F" in a level name is double-encoded so it can't be confused with separator
+ Arguments.of(Namespace.of("%1F"), "%251F"),
+ // multi-level namespaces: levels are joined with %1F separator
+ Arguments.of(Namespace.of("a", "b"), "a%1Fb"),
+ Arguments.of(Namespace.of("a", "b", "c"), "a%1Fb%1Fc"),
+ Arguments.of(Namespace.of("a/b", "c"), "a%2Fb%1Fc"),
+ // empty level in a multi-level namespace
+ Arguments.of(Namespace.of("a", "", "b"), "a%1F%1Fb"));
+ }
+
+ @ParameterizedTest
+ @MethodSource("encodeNamespaceCases")
+ public void testEncodeNamespace(Namespace ns, String expected) {
+ Assertions.assertThat(PolarisEntityUtils.encodeNamespace(ns)).isEqualTo(expected);
Review Comment:
Actually, what I proposes above probably makes sense for `decodeNamespace` :sweat_smile:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #4214:
URL: https://github.com/apache/polaris/pull/4214#discussion_r3092225373
##########
polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntityUtils.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import com.google.common.base.Preconditions;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.rest.RESTUtil;
+
+public final class PolarisEntityUtils {
+
+ private static final String NAMESPACE_SEPARATOR_ENCODED = "%1F";
+
+ private PolarisEntityUtils() {}
+
+ /**
+ * Returns a String representation of a namespace that is suitable for storage in entity internal
+ * properties.
+ *
+ * <p>This method is similar to {@link RESTUtil#encodeNamespace(Namespace)}.
+ */
+ public static String encodeNamespace(Namespace ns) {
+ Preconditions.checkArgument(ns != null, "Invalid namespace: null");
+ String[] levels = ns.levels();
+ String[] encodedLevels = new String[levels.length];
+ for (int i = 0; i < levels.length; i++) {
+ encodedLevels[i] = URLEncoder.encode(levels[i], StandardCharsets.UTF_8);
+ }
+ return String.join(NAMESPACE_SEPARATOR_ENCODED, encodedLevels);
+ }
+
+ /**
+ * Returns a Namespace object from a String representation that was encoded using {@link
+ * #encodeNamespace(Namespace)}.
+ *
+ * <p>This method is similar to {@link RESTUtil#decodeNamespace(String)}.
+ */
+ public static Namespace decodeNamespace(String encodedNs) {
+ Preconditions.checkArgument(encodedNs != null, "Invalid namespace: null");
+ String[] levels = encodedNs.split(NAMESPACE_SEPARATOR_ENCODED, -1);
Review Comment:
That's a good point, I will switch to using `Joiner` and `Splitter`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #4214:
URL: https://github.com/apache/polaris/pull/4214#discussion_r3089689769
##########
polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntityUtils.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import com.google.common.base.Preconditions;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.rest.RESTUtil;
+
Review Comment:
Can we add a Java doc, something like
```
/**
* Polaris-owned encoding/decoding for namespaces stored in entity internal properties.
*
* <p>This logic is isolated from iceberg.rest.RESTUtil to ensure the storage format
* remains stable even if Iceberg's REST utilities change behavior in future versions,
* preventing potential data corruption in Polaris metastores.
*/
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Isolate encode/decode logic used in Polaris entities [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #4214:
URL: https://github.com/apache/polaris/pull/4214#discussion_r3088596467
##########
polaris-core/src/test/java/org/apache/polaris/core/entity/PolarisEntityUtilsTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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;
+
+import java.util.stream.Stream;
+import org.apache.iceberg.catalog.Namespace;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.NullSource;
+
+public class PolarisEntityUtilsTest {
+
+ static Stream<Arguments> encodeNamespaceCases() {
+ return Stream.of(
+ // empty namespace encodes to empty string
+ Arguments.of(Namespace.empty(), ""),
+ // single-level namespaces
+ Arguments.of(Namespace.of("a"), "a"),
+ Arguments.of(Namespace.of("hello world"), "hello+world"),
+ Arguments.of(Namespace.of("a/b"), "a%2Fb"),
+ // literal "%1F" in a level name is double-encoded so it can't be confused with separator
+ Arguments.of(Namespace.of("%1F"), "%251F"),
+ // multi-level namespaces: levels are joined with %1F separator
+ Arguments.of(Namespace.of("a", "b"), "a%1Fb"),
+ Arguments.of(Namespace.of("a", "b", "c"), "a%1Fb%1Fc"),
+ Arguments.of(Namespace.of("a/b", "c"), "a%2Fb%1Fc"),
+ // empty level in a multi-level namespace
+ Arguments.of(Namespace.of("a", "", "b"), "a%1F%1Fb"));
+ }
+
+ @ParameterizedTest
+ @MethodSource("encodeNamespaceCases")
+ public void testEncodeNamespace(Namespace ns, String expected) {
+ Assertions.assertThat(PolarisEntityUtils.encodeNamespace(ns)).isEqualTo(expected);
Review Comment:
Actually, what I proposed above probably makes more sense for `decodeNamespace` :sweat_smile:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org