rdblue commented on a change in pull request #3593: URL: https://github.com/apache/iceberg/pull/3593#discussion_r754701449
########## File path: core/src/main/java/org/apache/iceberg/io/ResolvingFileIO.java ########## @@ -0,0 +1,153 @@ +/* + * 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.io; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import org.apache.hadoop.conf.Configuration; +import org.apache.iceberg.CatalogUtil; +import org.apache.iceberg.hadoop.HadoopConfigurable; +import org.apache.iceberg.hadoop.SerializableConfiguration; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.util.SerializableSupplier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * FileIO implementation that uses location scheme to choose the correct FileIO implementation. + */ +public class ResolvingFileIO implements FileIO, HadoopConfigurable { + private static final Logger LOG = LoggerFactory.getLogger(ResolvingFileIO.class); + private static final String DEFAULT_SCHEME = "fs"; + private static final String FALLBACK_IMPL = "org.apache.iceberg.hadoop.HadoopFileIO"; + private static final Map<String, String> SCHEME_TO_FILE_IO = ImmutableMap.of( + DEFAULT_SCHEME, FALLBACK_IMPL, Review comment: Good question! That introduces two problems: * How do you find all of the `FileIO` classes? You can scan the classpath, but that's really, really, really slow. Most of the time, you use `ServiceLoader` files, but you have to remember to merge them and they are a source of problems. Plus, your available implementations are tied to the classpath and it is inflexible. * What happens when two implementations both claim to handle `s3` URIs? You'd probably throw an exception and force a user to rebuild their classpath and service loader definitions. That's one reason why we do dynamic loading through config. That way you can choose in your config what is used to handle `s3`. That should always come with an opinionated default, but we make this configurable I would want to do it through catalog config (probably). -- 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]
