Search in sources :

Example 1 with ConnectorNodePartitioningProvider

use of com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider in project presto by prestodb.

the class NodePartitioningManager method getSplitToBucket.

private ToIntFunction<Split> getSplitToBucket(Session session, PartitioningHandle partitioningHandle) {
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviderManager.getPartitioningProvider(partitioningHandle.getConnectorId().get());
    ToIntFunction<ConnectorSplit> splitBucketFunction = partitioningProvider.getSplitBucketFunction(partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioningHandle.getConnectorHandle());
    checkArgument(splitBucketFunction != null, "No partitioning %s", partitioningHandle);
    return split -> {
        int bucket;
        if (split.getConnectorSplit() instanceof EmptySplit) {
            bucket = split.getLifespan().isTaskWide() ? 0 : split.getLifespan().getId();
        } else {
            bucket = splitBucketFunction.applyAsInt(split.getConnectorSplit());
        }
        if (!split.getLifespan().isTaskWide()) {
            checkArgument(split.getLifespan().getId() == bucket);
        }
        return bucket;
    };
}
Also used : IntStream(java.util.stream.IntStream) ConnectorPartitionHandle(com.facebook.presto.spi.connector.ConnectorPartitionHandle) DEAD(com.facebook.presto.metadata.InternalNode.NodeStatus.DEAD) DynamicBucketNodeMap(com.facebook.presto.execution.scheduler.group.DynamicBucketNodeMap) NodeSelectionStats(com.facebook.presto.execution.scheduler.nodeSelection.NodeSelectionStats) NodeScheduler(com.facebook.presto.execution.scheduler.NodeScheduler) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) EmptySplit(com.facebook.presto.split.EmptySplit) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Node(com.facebook.presto.spi.Node) ImmutableList(com.google.common.collect.ImmutableList) BucketNodeMap(com.facebook.presto.execution.scheduler.BucketNodeMap) Objects.requireNonNull(java.util.Objects.requireNonNull) SystemSessionProperties.getMaxTasksPerStage(com.facebook.presto.SystemSessionProperties.getMaxTasksPerStage) Type(com.facebook.presto.common.type.Type) BiMap(com.google.common.collect.BiMap) BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) NODE_SELECTION_NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NODE_SELECTION_NOT_SUPPORTED) FixedBucketNodeMap(com.facebook.presto.execution.scheduler.FixedBucketNodeMap) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ToIntFunction(java.util.function.ToIntFunction) NodeSelectionStrategy(com.facebook.presto.spi.schedule.NodeSelectionStrategy) PartitionFunction(com.facebook.presto.operator.PartitionFunction) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) BucketFunction(com.facebook.presto.spi.BucketFunction) Split(com.facebook.presto.metadata.Split) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) Collections(java.util.Collections) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) EmptySplit(com.facebook.presto.split.EmptySplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 2 with ConnectorNodePartitioningProvider

use of com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider in project presto by prestodb.

the class NodePartitioningManager method getConnectorBucketNodeMap.

private ConnectorBucketNodeMap getConnectorBucketNodeMap(Session session, PartitioningHandle partitioningHandle) {
    checkArgument(!(partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle));
    ConnectorId connectorId = partitioningHandle.getConnectorId().orElseThrow(() -> new IllegalArgumentException("No connector ID for partitioning handle: " + partitioningHandle));
    List<Node> nodes = getNodes(session, connectorId);
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviderManager.getPartitioningProvider(partitioningHandle.getConnectorId().get());
    ConnectorBucketNodeMap connectorBucketNodeMap = partitioningProvider.getBucketNodeMap(partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(partitioningHandle.getConnectorId().get()), partitioningHandle.getConnectorHandle(), nodes);
    checkArgument(connectorBucketNodeMap != null, "No partition map %s", partitioningHandle);
    return connectorBucketNodeMap;
}
Also used : Node(com.facebook.presto.spi.Node) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) ConnectorBucketNodeMap(com.facebook.presto.spi.connector.ConnectorBucketNodeMap) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 3 with ConnectorNodePartitioningProvider

use of com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider in project presto by prestodb.

the class NodePartitioningManager method getPartitionFunction.

public PartitionFunction getPartitionFunction(Session session, PartitioningScheme partitioningScheme, List<Type> partitionChannelTypes) {
    Optional<int[]> bucketToPartition = partitioningScheme.getBucketToPartition();
    checkArgument(bucketToPartition.isPresent(), "Bucket to partition must be set before a partition function can be created");
    PartitioningHandle partitioningHandle = partitioningScheme.getPartitioning().getHandle();
    BucketFunction bucketFunction;
    if (partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle) {
        checkArgument(partitioningScheme.getBucketToPartition().isPresent(), "Bucket to partition must be set before a partition function can be created");
        return ((SystemPartitioningHandle) partitioningHandle.getConnectorHandle()).getPartitionFunction(partitionChannelTypes, partitioningScheme.getHashColumn().isPresent(), partitioningScheme.getBucketToPartition().get());
    } else {
        ConnectorNodePartitioningProvider partitioningProvider = partitioningProviderManager.getPartitioningProvider(partitioningHandle.getConnectorId().get());
        bucketFunction = partitioningProvider.getBucketFunction(partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioningHandle.getConnectorHandle(), partitionChannelTypes, bucketToPartition.get().length);
        checkArgument(bucketFunction != null, "No function %s", partitioningHandle);
    }
    return new BucketPartitionFunction(bucketFunction, partitioningScheme.getBucketToPartition().get());
}
Also used : BucketPartitionFunction(com.facebook.presto.operator.BucketPartitionFunction) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) BucketFunction(com.facebook.presto.spi.BucketFunction)

Example 4 with ConnectorNodePartitioningProvider

use of com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider in project presto by prestodb.

the class PartitioningProviderManager method getPartitioningProvider.

public ConnectorNodePartitioningProvider getPartitioningProvider(ConnectorId connectorId) {
    ConnectorNodePartitioningProvider partitioningProvider = partitioningProviders.get(connectorId);
    checkArgument(partitioningProvider != null, "No partitioning provider for connector %s", connectorId);
    return partitioningProvider;
}
Also used : ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider)

Example 5 with ConnectorNodePartitioningProvider

use of com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider in project presto by prestodb.

the class HiveConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new EventModule(), new MBeanModule(), new JsonModule(), new SmileModule(), new HiveClientModule(catalogName), new HiveS3Module(catalogName), new HiveGcsModule(), new HiveMetastoreModule(catalogName, metastore), new HiveSecurityModule(), new HiveAuthenticationModule(), new HiveProcedureModule(), new CachingModule(), binder -> {
            MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
            binder.bind(MBeanServer.class).toInstance(new RebindSafeMBeanServer(platformMBeanServer));
            binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
            binder.bind(PageSorter.class).toInstance(context.getPageSorter());
            binder.bind(StandardFunctionResolution.class).toInstance(context.getStandardFunctionResolution());
            binder.bind(FunctionMetadataManager.class).toInstance(context.getFunctionMetadataManager());
            binder.bind(RowExpressionService.class).toInstance(context.getRowExpressionService());
            binder.bind(FilterStatsCalculatorService.class).toInstance(context.getFilterStatsCalculatorService());
            binder.bind(BlockEncodingSerde.class).toInstance(context.getBlockEncodingSerde());
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).quiet().initialize();
        LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
        HiveMetadataFactory metadataFactory = injector.getInstance(HiveMetadataFactory.class);
        HiveTransactionManager transactionManager = injector.getInstance(HiveTransactionManager.class);
        ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
        ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
        ConnectorPageSinkProvider pageSinkProvider = injector.getInstance(ConnectorPageSinkProvider.class);
        ConnectorNodePartitioningProvider connectorDistributionProvider = injector.getInstance(ConnectorNodePartitioningProvider.class);
        HiveSessionProperties hiveSessionProperties = injector.getInstance(HiveSessionProperties.class);
        HiveTableProperties hiveTableProperties = injector.getInstance(HiveTableProperties.class);
        HiveAnalyzeProperties hiveAnalyzeProperties = injector.getInstance(HiveAnalyzeProperties.class);
        ConnectorAccessControl accessControl = new SystemTableAwareAccessControl(injector.getInstance(ConnectorAccessControl.class));
        Set<Procedure> procedures = injector.getInstance(Key.get(new TypeLiteral<Set<Procedure>>() {
        }));
        ConnectorPlanOptimizerProvider planOptimizerProvider = injector.getInstance(ConnectorPlanOptimizerProvider.class);
        ConnectorMetadataUpdaterProvider metadataUpdaterProvider = injector.getInstance(ConnectorMetadataUpdaterProvider.class);
        return new HiveConnector(lifeCycleManager, metadataFactory, transactionManager, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader), new ClassLoaderSafeConnectorPageSinkProvider(pageSinkProvider, classLoader), new ClassLoaderSafeNodePartitioningProvider(connectorDistributionProvider, classLoader), ImmutableSet.of(), procedures, hiveSessionProperties.getSessionProperties(), HiveSchemaProperties.SCHEMA_PROPERTIES, hiveTableProperties.getTableProperties(), hiveAnalyzeProperties.getAnalyzeProperties(), accessControl, planOptimizerProvider, metadataUpdaterProvider, classLoader);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : FilterStatsCalculatorService(com.facebook.presto.spi.plan.FilterStatsCalculatorService) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) Injector(com.google.inject.Injector) PageSorter(com.facebook.presto.spi.PageSorter) Procedure(com.facebook.presto.spi.procedure.Procedure) HiveMetastoreModule(com.facebook.presto.hive.metastore.HiveMetastoreModule) ClassLoaderSafeNodePartitioningProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeNodePartitioningProvider) MBeanServer(javax.management.MBeanServer) ConnectorAccessControl(com.facebook.presto.spi.connector.ConnectorAccessControl) ClassLoaderSafeConnectorPageSinkProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSinkProvider) JsonModule(com.facebook.airlift.json.JsonModule) PageIndexerFactory(com.facebook.presto.spi.PageIndexerFactory) NodeManager(com.facebook.presto.spi.NodeManager) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) SystemTableAwareAccessControl(com.facebook.presto.hive.security.SystemTableAwareAccessControl) MBeanModule(org.weakref.jmx.guice.MBeanModule) ConnectorPlanOptimizerProvider(com.facebook.presto.spi.connector.ConnectorPlanOptimizerProvider) EventModule(com.facebook.airlift.event.client.EventModule) TypeLiteral(com.google.inject.TypeLiteral) RowExpressionService(com.facebook.presto.spi.relation.RowExpressionService) HiveSecurityModule(com.facebook.presto.hive.security.HiveSecurityModule) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) ConnectorMetadataUpdaterProvider(com.facebook.presto.spi.connector.ConnectorMetadataUpdaterProvider) HiveAuthenticationModule(com.facebook.presto.hive.authentication.HiveAuthenticationModule) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) CachingModule(com.facebook.presto.cache.CachingModule) FunctionMetadataManager(com.facebook.presto.spi.function.FunctionMetadataManager) HiveS3Module(com.facebook.presto.hive.s3.HiveS3Module) ClassLoaderSafeConnectorPageSinkProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSinkProvider) ConnectorPageSinkProvider(com.facebook.presto.spi.connector.ConnectorPageSinkProvider) HiveGcsModule(com.facebook.presto.hive.gcs.HiveGcsModule) ConnectorPageSourceProvider(com.facebook.presto.spi.connector.ConnectorPageSourceProvider) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) SmileModule(com.facebook.airlift.json.smile.SmileModule) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) TypeManager(com.facebook.presto.common.type.TypeManager) StandardFunctionResolution(com.facebook.presto.spi.function.StandardFunctionResolution)

Aggregations

ConnectorNodePartitioningProvider (com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider)8 BucketFunction (com.facebook.presto.spi.BucketFunction)4 BucketPartitionFunction (com.facebook.presto.operator.BucketPartitionFunction)3 ConnectorId (com.facebook.presto.spi.ConnectorId)3 Node (com.facebook.presto.spi.Node)3 ConnectorBucketNodeMap (com.facebook.presto.spi.connector.ConnectorBucketNodeMap)3 Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)2 LifeCycleManager (com.facebook.airlift.bootstrap.LifeCycleManager)2 EventModule (com.facebook.airlift.event.client.EventModule)2 JsonModule (com.facebook.airlift.json.JsonModule)2 CachingModule (com.facebook.presto.cache.CachingModule)2 Type (com.facebook.presto.common.type.Type)2 TypeManager (com.facebook.presto.common.type.TypeManager)2 HiveAuthenticationModule (com.facebook.presto.hive.authentication.HiveAuthenticationModule)2 HiveMetastoreModule (com.facebook.presto.hive.metastore.HiveMetastoreModule)2 HiveS3Module (com.facebook.presto.hive.s3.HiveS3Module)2 InternalNode (com.facebook.presto.metadata.InternalNode)2 PartitionFunction (com.facebook.presto.operator.PartitionFunction)2 NodeManager (com.facebook.presto.spi.NodeManager)2 PageIndexerFactory (com.facebook.presto.spi.PageIndexerFactory)2