%% Evaluate Deferred Tall Array Calculation
% Create a datastore for the airlinesmall.csv data set. Select a subset of variables to work with, and treat 'NA' values as missing data so that tabularTextDatastore replaces them with NaN values. Convert the datastore into a tall table.

varnames = {'Year','ArrDelay','UniqueCarrier'};
ds = tabularTextDatastore('airlinesmall.csv', 'TreatAsMissing', 'NA',...
    'SelectedVariableNames',varnames);
T = tall(ds)

%
% Calculate the size of the tall table.

sz = size(T)

% MATLAB® does not immediately evaluate most operations on tall arrays. Instead, MATLAB remembers the operations you perform as you enter them and optimizes the calculations in the background.
% When you use gather on an unevaluated tall array, MATLAB executes all of the queued operations using the minimum number of passes through the data. This optimization greatly reduces the execution time of large calculations. For this reason, you should use gather only when you need to see a result.
%
% Use gather to execute the calculation and collect the result into memory.

S = gather(sz)

% Copyright 2019 The MathWorks, Inc.