function s = calculateSummary(t)
% Calculate the summary structure for a codistributed table. The exact
% means of calculating depends on the distribution dimension. If the local
% part contains whole variables then we can calculate the info structs for
% each variable in one step. If distributed in the first dimension, we must
% do a reduction.
%
% See also: distributedutil.printSummary

%   Copyright 2016-2022 The MathWorks, Inc.


localTable = getLocalPart(t);
codistr = getCodistributor(t);
localInfo = matlab.bigdata.internal.util.calculateLocalSummary(localTable);

% Now collect together local results
if codistr.Dimension == 1
    % Variables are split across workers. Reduce to combine each part,
    % leaving the result on worker 1 (which will print them).
    s = spmdReduce(@iReduceSummary, localInfo, 1);
else
    % Local part has complete variables, just concatenate the summaries and
    % send to worker 1 (which will print them).
    s = spmdCat(localInfo, 2, 1);
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reduce phase - combine the inputs and call the shared helper.
function out = iReduceSummary(in1, in2)
out = matlab.bigdata.internal.util.reduceSummary( [in1;in2] );
end
