public override object Aggregate(int[] records, AggregateType kind)
{
bool hasData = false;
try
{
switch (kind)
{
case AggregateType.Min:
DateTime min = DateTime.MaxValue;
for (int i = 0; i < records.Length; i++)
{
int record = records[i];
if (HasValue(record))
{
min = (DateTime.Compare(_values[record], min) < 0) ? _values[record] : min;
hasData = true;
}
}
if (hasData)
{
return min;
}
return _nullValue;
case AggregateType.Max:
DateTime max = DateTime.MinValue;
for (int i = 0; i < records.Length; i++)
{
int record = records[i];
if (HasValue(record))
{
max = (DateTime.Compare(_values[record], max) >= 0) ? _values[record] : max;
hasData = true;
}
}
if (hasData)
{
return max;
}
return _nullValue;
case AggregateType.First:
if (records.Length > 0)
{
return _values[records[0]];
}
return null;
case AggregateType.Count:
int count = 0;
for (int i = 0; i < records.Length; i++)
{
if (HasValue(records[i]))
{
count++;
}
}
return count;
}
}
catch (OverflowException)
{
throw ExprException.Overflow(typeof(DateTime));
}
throw ExceptionBuilder.AggregateException(kind, _dataType);
}