function B = subsrefTabularParens(A, aidx)
% subsrefTabular performs paren indexing for distributed tables/timetables.
%
% B = A(X1,X2)
%
% X1 can be: ':', numeric, or logical; local or codistributed
% X2 can be: ':', numeric, logical, cellstr, string, or vartype; local or codistributed

% Copyright 2018-2021 The MathWorks, Inc.

if numel(aidx(1).subs) == 1
    error(message('MATLAB:table:LinearSubscript'));
elseif numel(aidx(1).subs) ~= 2
    error(message('MATLAB:table:NDSubscript'));
end

aidx.subs = tabularInterpretVartype(A, aidx.subs);

varNames = getTableVariableNames(A);
[~, aidx.subs{2}] = distributedutil.lookupTableVars(aidx.subs{2}, varNames);

% Table throws slightly different errors for bad indices.
try
    parallel.internal.indexing.validateTableIndexBounds(A, aidx);
catch ME
    throw(ME);
end

% Now that we have numeric indices we can just call standard subsrefParen
B = subsrefParens(A, aidx);
end % subsrefTabularParens
