Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * 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.tpch.testing;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
        implements ConnectorFactory
    private final NodeManager nodeManager;
    private final int defaultSplitsPerNode;
    private final int sampleWeight;
    public SampledTpchConnectorFactory(NodeManager nodeManagerint defaultSplitsPerNodeint sampleWeight)
    {
        this. = checkNotNull(nodeManager"nodeManager is null");
        this. = defaultSplitsPerNode;
        this. = sampleWeight;
    }
    @Override
    public String getName()
    {
        return "tpch_sampled";
    }
    @Override
    public Connector create(final String connectorIdMap<StringStringproperties)
    {
        checkNotNull(properties"properties is null");
        final int splitsPerNode = getSplitsPerNode(properties);
        return new Connector() {
            @Override
            public ConnectorMetadata getMetadata()
            {
                return new SampledTpchMetadata(connectorId);
            }
            @Override
            public ConnectorSplitManager getSplitManager()
            {
                return new TpchSplitManager(connectorIdsplitsPerNode);
            }
            @Override
            public ConnectorHandleResolver getHandleResolver()
            {
                return new TpchHandleResolver(connectorId);
            }
            @Override
            public ConnectorRecordSetProvider getRecordSetProvider()
            {
                return new SampledTpchRecordSetProvider(connectorId);
            }
        };
    }
    private int getSplitsPerNode(Map<StringStringproperties)
    {
        try {
            return Integer.parseInt(firstNonNull(properties.get("tpch.splits-per-node"), String.valueOf()));
        }
        catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid property tpch.splits-per-node");
        }
    }
New to GrepCode? Check out our FAQ X