function A = subsdeleteTabularParens(A, S)
% General deletion for distributed table/timetable.
%
% Support is currently limited to:
% * Removing entire variables: T(:,idx) = []
% * Removing entire rows: T(idx,:) = []

% Copyright 2019-2020 The MathWorks, Inc.

% Tables allow variable names in the second subscript. Convert to numbers.
% Also convert logical if we have them.
if numel(S(1).subs) > 1
    if couldBeVarName(S(1).subs{2})
        Atemplate = getTableTemplate(A);
        Aprops = Atemplate.Properties;
        AvarNames = Aprops.VariableNames;
        [~,S(1).subs{2}] = distributedutil.lookupTableVars(S(1).subs{2}, AvarNames);
    elseif islogical(S(1).subs{2})
        S(1).subs{2} = find(S(1).subs{2});
    elseif isnumeric(S(1).subs{2})
        % Repeated indices are ignored for deletion
        S(1).subs{2} = unique(S(1).subs{2});
    end
end

% Just use regular subsdelete
A = subsdeleteParens(A,S(1));
return;

end


function tf = couldBeVarName(arg)
% Check if an index argument could be a varname or list of varnames
tf = isstring(arg) ...
    || iscellstr(arg) ...
    || (ischar(arg) && ~parallel.internal.indexing.isColonLiteral(arg));
end
