kbendick commented on a change in pull request #4244: URL: https://github.com/apache/iceberg/pull/4244#discussion_r820410221
########## File path: core/src/main/java/org/apache/iceberg/rest/RESTUtil.java ########## @@ -0,0 +1,95 @@ +/* + * 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.iceberg.rest; + +import java.io.UncheckedIOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.relocated.com.google.common.base.Joiner; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.base.Splitter; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.relocated.com.google.common.collect.Streams; + +class RESTUtil { + private static final Joiner NULL_JOINER = Joiner.on('\u0000'); + private static final Splitter NULL_SPLITTER = Splitter.on('\u0000'); + + private RESTUtil() { + } + + public static String stripTrailingSlash(String path) { + if (path == null) { + return null; + } + + return path.endsWith("/") ? path.substring(0, path.length() - 1) : path; + } + + public static Map<String, String> filterByPrefix(Map<String, String> properties, String prefix) { Review comment: That's a good point. The purpose of this function is to be able to filter out configuration values that are relevant to the catalog, like we do when we configure catalog properties via the spark session configurations. For example, in the jdbc catalog, we configure the following properties. ```bash --conf spark.sql.catalog.my_catalog.jdbc.verifyServerCertificate=true \ --conf spark.sql.catalog.my_catalog.jdbc.useSSL=true \ --conf spark.sql.catalog.my_catalog.jdbc.user=admin \ --conf spark.sql.catalog.my_catalog.jdbc.password=pass ``` So we'd pass in `spark.sql.catalog.my_catalog.jdbc.` (or just `jdbc.`) to get the configuration values by name. The same thing could be done for the REST catalog. So here's an example. ``` Map<String, String> props = ImmutableMap.of(spark.sql.catalog.my_catalog.rest.readTimeoutMillis, 5000); Map<String, String> restCatalogProps = filterByPrefix(props, "spark.sql.catalog.my_catalog.rest."); ``` This function isn't nearly as important as the namespace parsing (which is what's needed more immediately), and arguably this could be achieved inline with guava Maps.filter etc, but we had a bug in the JDBC catalog a bit back because the functionality wasn't properly tested, so continuing to use a dedicated function that is tested seemed smarter. Eventually I'd like to merge them into a simpler `CatalogUtil` or something but right now I'm trying to keep changes more isolated. Ultimately, we might get rid of this function (and I'd even happily take it out of this PR). I _have_ been using this function in my development process, and it's used in the Jdbc catalog too, but if we want to hold off on merging it I'd be fine with that. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
