gusucode.com > bigdata 工具箱 matlab源码程序 > bigdata/+matlab/+bigdata/+internal/+executor/PartitionStrategy.m

    %PartitionStrategy
% The interface for classes that represent a partitioning strategy.
%
% A partitioning strategy tells the execution environment how a particular
% piece of execution or output should be partitioned. The different
% strategies modify how much control the execution environment has over the
% partitioning and with what information about the partition should be
% given to the data processor factory from ExecutionTask.
%

%   Copyright 2015-2016 The MathWorks, Inc.

classdef (Abstract) PartitionStrategy < handle
    properties (Abstract, SetAccess = private)
        % The default total number of partitions. This is allowed to be
        % empty.
        DesiredNumPartitions
        
        % A flag that indicates whether DesiredNumPartitions is the only
        % allowed value for number of partitions.
        IsNumPartitionsFixed
        
        % A flag that indicates whether the partitioning is based on an
        % underlying datastore.
        IsDatastorePartitioning
        
        % A flag that indicates whether the data will be explicitly
        % broadcasted to every partition.
        IsBroadcast;
        
        % A flag that indicates whether all data will be accessible by
        % every partition. This is true if the data is broadcasted or there
        % is only a single partition.
        IsDataReplicated;
    end
    
    methods (Abstract)
        % Create a partition object that represents the given partition
        % index.
        %
        %  partition = obj.createPartition(partitionIndex) creates a
        %  datastore based on the default desired partitioning.
        %
        %  partition = obj.createPartition(partitionIndex, numPartitions) creates a
        %  datastore based on numPartitions. If IsNumPartitionsFixed is
        %  true, then numPartitions must equal DesiredNumPartitions.
        %
        %  partition = obj.createPartition(partitionIndex, numPartitions, hadoopSplit)
        %  creates a datastore based on the provided datastore Hadoop split.
        %  The partitionIndex must match corresponding partition index of
        %  the Hadoop split. This argument is only supported if
        %  IsDatastorePartitioning is true.
        %
        partition = createPartition(obj, partitionIndex, numPartitions, varargin)
    end
    
    methods (Static)
        % Create a fixed NumPartitions or Datastore Partition Strategy.
        %
        % Syntax:
        %   strategy = PartitionStrategy.create(N) for a positive integer
        %   scalar N creates a partition strategy that has exactly N number
        %   of partitions.
        %
        %   strategy = PartitionStrategy.create(ds) creates a partition
        %   strategy that decides the partitioning based on the datastore
        %   ds.
        %
        function strategy = create(strategy)
            import matlab.bigdata.internal.executor.ArbitraryPartitionStrategy;
            import matlab.bigdata.internal.executor.DatastorePartitionStrategy;
            import matlab.bigdata.internal.executor.FixedNumPartitionStrategy;
            if isnumeric(strategy)
                strategy = FixedNumPartitionStrategy(strategy);
            elseif isa(strategy, 'matlab.io.datastore.Datastore')
                strategy = DatastorePartitionStrategy(strategy);
            elseif isempty(strategy)
                strategy = ArbitraryPartitionStrategy();
            else
                assert(false, 'Invalid input for partition strategy.');
            end
        end
    end
end