/*
 * Licensed to Crate under one or more contributor license agreements.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.  Crate 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.
 *
 * However, if you have executed another commercial license agreement
 * with Crate these terms will supersede the license and you may use the
 * software solely pursuant to the terms of the relevant commercial
 * agreement.
 */

package io.crate.operation.projectors;

import com.google.common.base.Throwables;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.crate.collections.Lists2;
import io.crate.data.Input;
import io.crate.metadata.PartitionName;
import io.crate.metadata.TableIdent;
import io.crate.operation.Inputs;
import org.apache.lucene.util.BytesRef;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

public class IndexNameResolver {

    private IndexNameResolver() {
    }

    public static Supplier<String> create(TableIdent tableIdent,
                                          @Nullable String partitionIdent,
                                          @Nullable List<Input<?>> partitionedByInputs) {
        if (partitionIdent == null && (partitionedByInputs == null || partitionedByInputs.isEmpty())) {
            return forTable(tableIdent);
        }
        if (partitionIdent == null) {
            return forPartition(tableIdent, partitionedByInputs);
        }
        return forPartition(tableIdent, partitionIdent);
    }

    public static Supplier<String> forTable(final TableIdent tableIdent) {
        return tableIdent::indexName;
    }

    private static Supplier<String> forPartition(TableIdent tableIdent, String partitionIdent) {
        return () -> PartitionName.indexName(tableIdent, partitionIdent);
    }

    private static Supplier<String> forPartition(final TableIdent tableIdent, final List<Input<?>> partitionedByInputs) {
        assert partitionedByInputs.size() > 0 : "must have at least 1 partitionedByInput";
        final LoadingCache<List<BytesRef>, String> cache = CacheBuilder.newBuilder()
            .initialCapacity(10)
            .maximumSize(20)
            .build(new CacheLoader<List<BytesRef>, String>() {
                @Override
                public String load(@Nonnull List<BytesRef> key) throws Exception {
                    return PartitionName.indexName(tableIdent, PartitionName.encodeIdent(key));
                }
            });
        return () -> {
            // copy because the values of the inputs are mutable
            List<BytesRef> partitions = Lists2.copyAndReplace(partitionedByInputs, Inputs.TO_BYTES_REF);
            try {
                return cache.get(partitions);
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
        };
    }
}

@@ -1036,50 +1036,8 @@
 s;%0A%0A
-import com.google.common.base.Throwables;%0A
 impo
@@ -1476,56 +1476,8 @@
 st;%0A
-import java.util.concurrent.ExecutionException;%0A
 impo
@@ -3316,165 +3316,46 @@
     
-try %7B%0A                return cache.get(partitions);%0A            %7D catch (ExecutionException e) %7B%0A                throw Throwables.propagate(e);%0A            %7D
+return cache.getUnchecked(partitions);
 %0A   

Remove deprecated `Throwables.propagate(` usage