/*
 * Licensed 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 com.facebook.presto.operator;

import com.facebook.presto.metadata.OutputTableHandle;
import com.facebook.presto.spi.ConnectorRecordSinkProvider;
import com.facebook.presto.spi.RecordSink;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static com.google.common.base.Preconditions.checkArgument;

public class RecordSinkManager
        implements RecordSinkProvider
{
    private final ConcurrentMap<String, ConnectorRecordSinkProvider> recordSinkProviders = new ConcurrentHashMap<>();

    public void addConnectorRecordSinkProvider(String connectorId, ConnectorRecordSinkProvider recordSinkProvider)
    {
        ConnectorRecordSinkProvider previous = recordSinkProviders.putIfAbsent(connectorId, recordSinkProvider);
        checkArgument(previous == null, "Record sink provider already registered for connector '%s'", connectorId);
    }

    @Override
    public RecordSink getRecordSink(OutputTableHandle tableHandle)
    {
        ConnectorRecordSinkProvider provider = recordSinkProviders.get(tableHandle.getConnectorId());

        checkArgument(provider != null, "No record sink for '%s'", tableHandle.getConnectorId());

        return provider.getRecordSink(tableHandle.getConnectorHandle());
    }
}

@@ -1545,32 +1545,223 @@
 )%0A    %7B%0A        
+return providerFor(tableHandle.getConnectorId()).getRecordSink(tableHandle.getConnectorHandle());%0A    %7D%0A%0A    private ConnectorRecordSinkProvider providerFor(String connectorId)%0A    %7B%0A        
 ConnectorRecordS
@@ -1806,29 +1806,14 @@
 ders
-.get(tableHandle
 .get
-C
+(c
 onne
@@ -1810,38 +1810,35 @@
 .get(connectorId
-()
 );%0A
-%0A
         checkArg
@@ -1881,35 +1881,39 @@
 ink 
-for '%25s'%22, tableHandle.getC
+provider for connector '%25s'%22, c
 onne
@@ -1922,14 +1922,11 @@
 orId
-()
 );%0A
-%0A
     
@@ -1948,56 +1948,8 @@
 ider
-.getRecordSink(tableHandle.getConnectorHandle())
 ;%0A  

Refactor provider lookup in RecordSinkManager