gusucode.com > datatypes 工具箱matlab源码程序 > datatypes/@timetable/prejoin.m

    function [a,b,supplied,keys,leftKeys,rightKeys,leftVars,rightVars,mergeKeys] ...
        = prejoin(a,b,supplied,type,keys,leftKeys,rightKeys,leftVars,rightVars,mergeKeys)
%PERJOIN function called by join/innerjoin/outerjoin
%   Prepares the timetable to be used in the common join code
%
%   Copyright 2012-2016 The MathWorks, Inc.

import matlab.internal.datatypes.isCharString;
import matlab.internal.datatypes.isCharStrings;

try
if isa(a,'timetable') && isa(b,'timetable')
    % For joins between time tables, the key must the row times.
    a_timeLabel = a.metaDim.labels{1};
    b_timeLabel = b.metaDim.labels{1};

    % Only the time vector can be used as the key for joining two timetables.
    % If no keys are provided, just use the time vector names.
    if supplied.Keys
        if ~all(strcmp(keys,a_timeLabel)) || ~all(strcmp(keys,b_timeLabel))
            error(message('MATLAB:timetable:join:InvalidTimeKeys'));
        end
    elseif supplied.LeftKeys && supplied.RightKeys
        if ~all(strcmp(leftKeys,a_timeLabel)) || ~all(strcmp(rightKeys,b_timeLabel))
            error(message('MATLAB:timetable:join:InvalidTimeKeys'));
        end
    elseif supplied.LeftKeys || supplied.RightKeys
        error(message('MATLAB:table:join:MissingKeyVar'));
    else % No key names are provided, use the time vector labels
        supplied.LeftKeys = true;
        leftKeys = a_timeLabel;

        supplied.RightKeys = true;
        rightKeys = b_timeLabel;
    end

    if supplied.LeftVariables
        % If left variables is provided, add the time that has been moved into the
        % variables to the leftvariables so that it doesn't get dropped.
        try
            leftVars = [a.varDim.subs2inds(leftVars) a.varDim.length+1];
        catch ME
            a.subs2indsErrorHandler(leftVars,ME,'join:RowLabelsInvalidVars');
        end
    end
    if supplied.RightVariables
        % Do not need to add the row times position to right vars because
        % Keys from right variables will get dropped anyways.
        try
            rightVars = b.varDim.subs2inds(rightVars);
        catch ME
            b.subs2indsErrorHandler(rightVars,ME,'join:RowLabelsInvalidVars');
        end
    end
    
    % Temporarily add row times as the first variable to each of the timetables.
    % These are removed in postjoin.
    a = copyRowTimesAsVariable(a);
    b = copyRowTimesAsVariable(b);

    % MergeKeys cannot be false for timetable outerjoin
    if strcmp(type,'outer')
        if supplied.MergeKeys && mergeKeys == false
            error(message('MATLAB:timetable:join:MergeKeysMustBeTrue'));
        else
            mergeKeys = true;
        end
    end
    
% Only simple join will call prejoin with a timetable/table join
elseif strcmp(type,'simple') && isa(a,'timetable') && isa(b,'table') 
    % For joins between a timetable and a table, only variables (and not time) are allowed as keys.
    a_timeLabel = a.metaDim.labels{1};
    if supplied.Keys
        if strcmp(keys,a_timeLabel)
            error(message('MATLAB:timetable:join:InvalidVariableKeys'));
        end
    elseif supplied.LeftKeys
        if strcmp(leftKeys,a_timeLabel)
            error(message('MATLAB:timetable:join:InvalidVariableKeys'));
        end
    end
end
catch ME
   throwAsCaller(ME); 
end
end